generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 187
130 lines (112 loc) · 4.95 KB
/
duplicate-dispute.yml
File metadata and controls
130 lines (112 loc) · 4.95 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
name: Duplicate Dispute Handler
# Triggers when users dispute a duplicate detection by:
# 1. Commenting on an issue with 'duplicate' label
on:
issue_comment:
types: [created]
# Note: GitHub Actions doesn't have a direct trigger for reactions
# Reaction handling is done via scheduled workflow or manual trigger
permissions:
issues: write
contents: read
jobs:
handle-comment-dispute:
# Only run for issue comments (not PR comments) on issues with duplicate label
if: |
github.event_name == 'issue_comment' &&
!github.event.issue.pull_request
runs-on: ubuntu-latest
steps:
- name: Check if issue has duplicate label
id: check-label
uses: actions/github-script@v7
with:
script: |
const labels = context.payload.issue.labels.map(l => l.name);
const hasDuplicate = labels.includes('duplicate');
console.log(`Issue #${context.payload.issue.number} labels: ${labels.join(', ')}`);
console.log(`Has duplicate label: ${hasDuplicate}`);
return hasDuplicate;
result-encoding: string
- name: Check if comment is after duplicate detection
if: steps.check-label.outputs.result == 'true'
id: check-timing
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issueNumber = context.payload.issue.number;
const newCommentId = context.payload.comment.id;
const newCommentDate = new Date(context.payload.comment.created_at);
// Fetch all comments
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: issueNumber,
per_page: 100
});
// Find duplicate detection comment
const duplicateComment = comments.find(c =>
c.body && c.body.includes('Potential Duplicate Detected')
);
if (!duplicateComment) {
console.log('No duplicate detection comment found');
return false;
}
const duplicateCommentDate = new Date(duplicateComment.created_at);
const isAfter = newCommentDate > duplicateCommentDate && newCommentId !== duplicateComment.id;
console.log(`Duplicate detection comment: ${duplicateComment.id} at ${duplicateCommentDate}`);
console.log(`New comment: ${newCommentId} at ${newCommentDate}`);
console.log(`Is after duplicate detection: ${isAfter}`);
return isAfter;
result-encoding: string
- name: Relabel issue (remove duplicate, add pending-triage)
if: |
steps.check-label.outputs.result == 'true' &&
steps.check-timing.outputs.result == 'true'
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issueNumber = context.payload.issue.number;
console.log(`Relabeling issue #${issueNumber}...`);
// Remove duplicate label
try {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number: issueNumber,
name: 'duplicate'
});
console.log('✓ Removed duplicate label');
} catch (error) {
console.log(`Could not remove duplicate label: ${error.message}`);
}
// Add pending-triage label
try {
await github.rest.issues.addLabels({
owner,
repo,
issue_number: issueNumber,
labels: ['pending-triage']
});
console.log('✓ Added pending-triage label');
} catch (error) {
console.log(`Could not add pending-triage label: ${error.message}`);
}
// Post acknowledgment comment
await github.rest.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: `Thank you for your feedback! 🙏\n\nThe duplicate label has been removed and this issue has been sent back for maintainer review.\n\nA maintainer will review this issue shortly.`
});
console.log('✓ Posted acknowledgment comment');
console.log(`Issue #${issueNumber} relabeled successfully`);
- name: Create workflow summary
if: always()
run: |
echo "## Duplicate Dispute Handler" >> "$GITHUB_STEP_SUMMARY"
echo "Issue: #${{ github.event.issue.number }}" >> "$GITHUB_STEP_SUMMARY"
echo "Comment by: @${{ github.event.comment.user.login }}" >> "$GITHUB_STEP_SUMMARY"
echo "Status: ${{ job.status }}" >> "$GITHUB_STEP_SUMMARY"