-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathauto-fix-issue.yml
More file actions
141 lines (118 loc) · 5.19 KB
/
Copy pathauto-fix-issue.yml
File metadata and controls
141 lines (118 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# ======================================================================================
# Workflow: Auto Fix Issue
# ======================================================================================
# Usage:
# - Apply the label 'oz-agent' to any GitHub Issue.
# - This workflow will trigger, analyze the issue, and attempt to write code to fix it.
#
# Setup:
# - Ensure WARP_API_KEY is set in Repository Secrets.
# - Ensure the Action has write permissions for contents, issues, and pull-requests.
#
# Expected Output:
# - If a fix is found: A new Pull Request (fix/issue-NUMBER) is created and linked to the issue.
# - If no fix is found: The Agent comments on the issue explaining why.
#
# When to use:
# - Use this to delegate bug fixes, small features, or chore tasks to the Oz Agent.
# ======================================================================================
name: Auto Fix Issue
on:
issues:
types: [labeled]
jobs:
auto_fix:
# Only run if the label added is 'oz-agent'
if: github.event.label.name == 'oz-agent'
name: Auto Fix Issue
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Construct Prompt
id: prompt
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const issue = context.payload.issue;
// Fetch all previous comments on the issue to give the agent full context
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
per_page: 100,
});
const description = issue.body || 'No description provided.';
let commentsNote = 'There are no previous comments on this issue.';
let commentsInstructions = '';
if (comments.length) {
const commentsText = comments
.map(c => `- ${c.user?.login || 'unknown'} (${c.created_at}): ${c.body}`)
.join('\\n');
fs.writeFileSync('issue_comments.txt', commentsText, 'utf8');
commentsNote = 'All previous issue comments are stored in \`issue_comments.txt\` in the workspace.';
commentsInstructions = `
- Optionally, read \`issue_comments.txt\` to understand prior discussion and clarifications.`;
}
const prompt = `You are an expert software engineer and the Oz Agent.
You have been assigned to fix GitHub Issue #${issue.number}.
**Issue Details**:
- **Title**: ${issue.title}
- **Description**: ${description}
**Previous Issue Comments**:
${commentsNote}
**Instructions**:
1. **Analyze**:
- Carefully read the issue description above to understand the problem.${commentsInstructions}
2. **Fix**: Implement the changes necessary to resolve the issue.
3. **Verify**: Ensure the code is correct and follows existing patterns.
4. **Output**: Do not output the diff. Provide a brief summary of what you changed.
`;
core.setOutput('prompt', prompt);
- name: Run Oz Agent
uses: warpdotdev/oz-agent-action@v1
env:
GH_TOKEN: ${{ github.token }}
id: agent
with:
prompt: ${{ steps.prompt.outputs.prompt }}
warp_api_key: ${{ secrets.WARP_API_KEY }}
profile: ${{ vars.WARP_AGENT_PROFILE || '' }}
- name: Create PR and Comment
env:
GH_TOKEN: ${{ github.token }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
AGENT_OUTPUT: ${{ steps.agent.outputs.agent_output }}
run: |
# Remove temporary files that should not be committed
rm -f issue_comments.txt issue_description.txt
# Check for changes
if [[ -z $(git status --porcelain) ]]; then
echo "No changes made by Oz Agent."
gh issue comment "$ISSUE_NUMBER" --body "I analyzed the issue but couldn't determine a code change to make. \\n\\n**Agent Output:**\\n$AGENT_OUTPUT"
exit 0
fi
BRANCH_NAME="fix/issue-$ISSUE_NUMBER"
git config user.name "Oz Agent"
git config user.email "agent@warp.dev"
git checkout -b "$BRANCH_NAME"
git add .
git commit -m "Fix for Issue #$ISSUE_NUMBER"
git push origin "$BRANCH_NAME" --force
# Create PR
# Escape title to handle special chars
TITLE="Fix Issue #$ISSUE_NUMBER: ${{ github.event.issue.title }}"
BODY="This PR attempts to fix Issue #$ISSUE_NUMBER.
**Agent Summary**:
$AGENT_OUTPUT
Closes #$ISSUE_NUMBER"
# Create PR and capture URL
PR_URL=$(gh pr create --title "$TITLE" --body "$BODY" --base main --head "$BRANCH_NAME")
echo "Created PR: $PR_URL"
# Comment on Issue
gh issue comment "$ISSUE_NUMBER" --body "I have created a fix for this issue: $PR_URL"