Add better error handling & rertries

This commit is contained in:
Ake
2025-01-10 08:54:18 +07:00
parent 15ca1a6692
commit 9ac0c2738d
+14 -6
View File
@@ -15,6 +15,7 @@ jobs:
with: with:
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
script: | script: |
try {
const comment = context.payload.comment; const comment = context.payload.comment;
const body = comment.body.toLowerCase(); const body = comment.body.toLowerCase();
const author = comment.user.login; const author = comment.user.login;
@@ -68,20 +69,19 @@ jobs:
); );
if (foundPatterns.length > 0 || suspiciousLinks) { if (foundPatterns.length > 0 || suspiciousLinks) {
try {
// Create a warning comment // Create a warning comment
const warningMessage = `⚠️ Potential scam detected in comment by ${author}:
- Suspicious patterns found: ${foundPatterns.join(', ')}
${suspiciousLinks ? '- Contains external links' : ''}
@${context.repo.owner} Please review this comment.`;
await github.rest.issues.createComment({ await github.rest.issues.createComment({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: context.payload.issue ? context.payload.issue.number : context.payload.pull_request.number, issue_number: context.payload.issue ? context.payload.issue.number : context.payload.pull_request.number,
body: warningMessage body: warningMessage
}); });
} catch (e) {
console.log('Failed to create comment:', e);
}
try {
// Add 'potential-scam' label // Add 'potential-scam' label
await github.rest.issues.addLabels({ await github.rest.issues.addLabels({
owner: context.repo.owner, owner: context.repo.owner,
@@ -89,4 +89,12 @@ jobs:
issue_number: context.payload.issue ? context.payload.issue.number : context.payload.pull_request.number, issue_number: context.payload.issue ? context.payload.issue.number : context.payload.pull_request.number,
labels: ['potential-scam'] labels: ['potential-scam']
}); });
} catch (e) {
console.log('Failed to add label:', e);
}
}
} catch (e) {
console.log('Workflow error:', e);
// Still mark as failure but with more context
core.setFailed(`Workflow failed: ${e.message}`);
} }