-
Notifications
You must be signed in to change notification settings - Fork 280
247 lines (196 loc) Β· 8.86 KB
/
helpful-error-reporter.yml
File metadata and controls
247 lines (196 loc) Β· 8.86 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
name: π€ Helpful Error Reporter
on:
workflow_run:
workflows: ["π PR Validation", "π§ͺ Multi-Language Testing", "π PR Automation"]
types: [completed]
permissions:
contents: read
pull-requests: write
issues: write
actions: read
jobs:
report-errors:
name: π’ Explain Errors
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
steps:
- name: π₯ Get PR number
id: get-pr
uses: actions/github-script@v7
with:
script: |
// Get the head repository owner (handles forks correctly)
const headOwner = context.payload.workflow_run.head_repository?.owner?.login || context.repo.owner;
const headBranch = context.payload.workflow_run.head_branch;
const pulls = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${headOwner}:${headBranch}`
});
if (pulls.data.length > 0) {
return pulls.data[0].number;
}
return null;
- name: π₯ Download workflow logs
if: steps.get-pr.outputs.result != 'null'
uses: actions/github-script@v7
id: get-logs
with:
script: |
const run_id = context.payload.workflow_run.id;
try {
const jobs = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: run_id
});
let failureReasons = [];
for (const job of jobs.data.jobs) {
if (job.conclusion === 'failure') {
failureReasons.push({
name: job.name,
steps: job.steps.filter(s => s.conclusion === 'failure').map(s => s.name)
});
}
}
return JSON.stringify(failureReasons);
} catch (error) {
console.log('Error fetching logs:', error);
return '[]';
}
- name: π¬ Post helpful error explanation
if: steps.get-pr.outputs.result != 'null'
uses: actions/github-script@v7
env:
PR_NUMBER: ${{ steps.get-pr.outputs.result }}
FAILURES_JSON: ${{ steps.get-logs.outputs.result }}
with:
script: |
const prNumber = parseInt(process.env.PR_NUMBER);
const workflowName = context.payload.workflow_run.name;
const failures = JSON.parse(process.env.FAILURES_JSON || '[]');
let errorExplanation = '';
// Generate helpful messages based on workflow type
if (workflowName.includes('PR Validation')) {
errorExplanation = `## β PR Validation Failed
Your PR didn't pass our validation checks. Here's what went wrong and how to fix it:
### π Common Issues:
**1οΈβ£ File Naming Convention**
- **Problem:** File names don't follow our standards
- **Fix:** Use descriptive names like \`binary_search.cpp\`, \`merge_sort.py\`
- **Avoid:** Generic names like \`test.cpp\`, \`program.py\`
**2οΈβ£ Wrong Directory Structure**
- **Problem:** Files are not in the correct folder
- **Fix:** Place files in \`Language/Category/file\`
- **Examples:**
- β
\`Python/algorithms/sorting/quick_sort.py\`
- β
\`CPP/data_structures/trees/binary_tree.cpp\`
- β \`Python/quick_sort.py\` (missing category)
**3οΈβ£ Missing Documentation**
- **Problem:** Code lacks comments or complexity analysis
- **Fix:** Add algorithm description, time/space complexity, and inline comments
### π§ How to Fix:
1. Check the workflow logs above to see specific errors
2. Fix the issues in your code
3. Commit and push the changes
4. The checks will run automatically again
### π Need Help?
- Check our [Contributing Guidelines](https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/CONTRIBUTING.md)
- Review similar merged PRs for examples
- Ask questions in the PR comments - we're here to help!`;
} else if (workflowName.includes('Multi-Language Testing')) {
errorExplanation = `## β Code Testing Failed
Your code didn't compile or run successfully. Don't worry - this is fixable!
### π Common Issues:
**1οΈβ£ Compilation Errors**
- **C/C++:** Missing headers, syntax errors, undefined variables
- **Java:** Class name doesn't match filename, missing semicolons
- **Python:** Indentation errors, syntax mistakes
**2οΈβ£ Runtime Errors**
- **Problem:** Code compiles but crashes when running
- **Common causes:** Array out of bounds, null pointers, infinite loops
- **Fix:** Add error handling and validate inputs
**3οΈβ£ Code Requires User Input**
- **Problem:** Code waits for user input (cin, scanf, input())
- **Fix:** Use test cases that don't require user input, or include sample data
### π§ How to Fix:
1. **Test Locally First:**
\`\`\`bash
# For C++
g++ your_file.cpp -o program && ./program
# For Python
python3 your_file.py
# For Java
javac YourClass.java && java YourClass
\`\`\`
2. **Check the error logs** in the workflow run details
3. **Fix the errors** and test locally again
4. **Push your changes** - tests will re-run automatically
### π‘ Pro Tips:
- Always test your code locally before pushing
- Include test cases in your code to verify it works
- Add error handling for edge cases
- Avoid code that requires user input`;
} else {
errorExplanation = `## β Workflow Check Failed
One of our automated checks didn't pass. Here's what you need to know:
### π What Failed:
Workflow: **${workflowName}**
### π§ General Fix Steps:
1. Click on "Details" next to the failed check to see specific errors
2. Read the error messages carefully - they usually explain what's wrong
3. Fix the issues mentioned in the errors
4. Push your changes - checks will re-run automatically
### π Resources:
- [Contributing Guidelines](https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/CONTRIBUTING.md)
- [Code Examples](https://github.com/${context.repo.owner}/${context.repo.repo}/tree/main)
- Ask questions in this PR - maintainers will help!
### πͺ You Can Do This!
Every developer faces failed checks - it's part of the learning process. Fix the issues and you'll be one step closer to a successful contribution!`;
}
// Add specific failed steps if available
if (failures.length > 0) {
errorExplanation += '\n\n### π Specific Failed Steps:\n\n';
for (const failure of failures) {
errorExplanation += `**${failure.name}:**\n`;
for (const step of failure.steps) {
errorExplanation += `- ${step}\n`;
}
errorExplanation += '\n';
}
}
errorExplanation += `\n---\n*Need help? Tag @Karanjot786 or @Pradeepsingh61 and we'll assist you! π€*`;
// Check if we already posted an error explanation
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const errorComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
(comment.body.includes('PR Validation Failed') ||
comment.body.includes('Code Testing Failed') ||
comment.body.includes('Workflow Check Failed'))
);
// Only post if we haven't already commented, otherwise update
if (!errorComment) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: errorExplanation
});
} else {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: errorComment.id,
body: errorExplanation
});
}
- name: β
Summary
run: |
echo "Posted helpful error explanation to PR"
echo "Workflow: ${{ github.event.workflow_run.name }}"
echo "Conclusion: ${{ github.event.workflow_run.conclusion }}"