Skip to content

Commit 15c4352

Browse files
Fix/issue bot final (#171)
1 parent 7893986 commit 15c4352

1 file changed

Lines changed: 57 additions & 29 deletions

File tree

.github/workflows/issue-assignment.yml

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ permissions:
99
contents: read
1010

1111
jobs:
12-
assign-issue:
13-
# Only run on issue comments (not PR comments) and when comment contains @bot assign
12+
claim-issue:
13+
# Only run on issue comments (not PR comments) and when comment contains @bot claim
1414
if: |
1515
!github.event.issue.pull_request &&
16-
contains(github.event.comment.body, '@bot assign')
16+
contains(github.event.comment.body, '@bot claim')
1717
runs-on: ubuntu-latest
1818
# Prevent race conditions - only one job per issue at a time
1919
concurrency:
@@ -30,12 +30,12 @@ jobs:
3030
const issue = context.payload.issue;
3131
const repo = context.repo;
3232
33-
console.log(`Processing @bot assign from ${commenter} on issue #${issue.number}`);
33+
console.log(`Processing @bot claim from ${commenter} on issue #${issue.number}`);
3434
3535
// Validate exact command match
3636
const commentBody = context.payload.comment.body.trim();
37-
if (commentBody !== '@bot assign') {
38-
console.log(`Comment "${commentBody}" is not an exact match for "@bot assign", skipping`);
37+
if (commentBody !== '@bot claim') {
38+
console.log(`Comment "${commentBody}" is not an exact match for "@bot claim", skipping`);
3939
return;
4040
}
4141
@@ -47,10 +47,9 @@ jobs:
4747
4848
// Check if issue is already assigned
4949
if (currentIssue.assignees && currentIssue.assignees.length > 0) {
50-
const currentAssignee = currentIssue.assignees[0].login;
50+
const isAlreadyAssignedToCommenter = currentIssue.assignees.some(a => a.login === commenter);
5151
52-
// Check if already assigned to the same commenter
53-
if (currentAssignee === commenter) {
52+
if (isAlreadyAssignedToCommenter) {
5453
console.log(`Issue already assigned to commenter ${commenter}`);
5554
await github.rest.issues.createComment({
5655
...repo,
@@ -60,28 +59,57 @@ jobs:
6059
return;
6160
}
6261
63-
console.log(`Issue already assigned to ${currentAssignee}`);
62+
// Assigned to someone else
63+
const assigneesList = currentIssue.assignees.map(a => `@${a.login}`).join(', ');
64+
console.log(`Issue already assigned to ${assigneesList}`);
6465
await github.rest.issues.createComment({
6566
...repo,
6667
issue_number: issue.number,
67-
body: `@${commenter} This issue cannot be claimed, as someone else is already working on it.`
68+
body: `@${commenter} This issue cannot be claimed, as it is already assigned to ${assigneesList}.`
6869
});
6970
return;
7071
}
7172
72-
// Check if commenter has any other open assigned issues using Search API
73-
const { data: searchResult } = await github.rest.search.issuesAndPullRequests({
74-
q: `repo:${repo.owner}/${repo.repo} is:issue is:open assignee:${commenter}`
75-
});
73+
// Check if commenter has any other open assigned issues
74+
// Using ONLY repo-scoped API (listForRepo) - no Search API dependency
75+
// This approach works for all users including first-time contributors
76+
let otherAssignedIssues = [];
77+
let page = 1;
78+
let hasMorePages = true;
7679
77-
// Filter out the current issue and PRs
78-
const otherAssignedIssues = searchResult.items.filter(i =>
79-
i.number !== issue.number && !i.pull_request
80-
);
80+
console.log(`Checking for other assigned issues for ${commenter}...`);
8181
82-
if (otherAssignedIssues.length > 0) {
83-
console.log(`User ${commenter} already has ${otherAssignedIssues.length} assigned issues`);
82+
while (hasMorePages) {
83+
const { data: issues } = await github.rest.issues.listForRepo({
84+
...repo,
85+
state: 'open',
86+
per_page: 100,
87+
page: page
88+
});
8489
90+
if (issues.length === 0) {
91+
hasMorePages = false;
92+
} else {
93+
// Filter: exclude current issue, exclude PRs, find issues assigned to commenter
94+
const assignedToUser = issues.filter(i =>
95+
i.number !== issue.number &&
96+
!i.pull_request &&
97+
i.assignees &&
98+
i.assignees.some(a => a.login === commenter)
99+
);
100+
otherAssignedIssues = otherAssignedIssues.concat(assignedToUser);
101+
page++;
102+
103+
// Stop early if we found assigned issues or reached end of results
104+
if (otherAssignedIssues.length > 0 || issues.length < 100) {
105+
hasMorePages = false;
106+
}
107+
}
108+
}
109+
110+
console.log(`Found ${otherAssignedIssues.length} other assigned issues for ${commenter}`);
111+
112+
if (otherAssignedIssues.length > 0) {
85113
await github.rest.issues.createComment({
86114
...repo,
87115
issue_number: issue.number,
@@ -129,19 +157,19 @@ jobs:
129157
130158
console.log(`Successfully assigned issue #${issue.number} to ${commenter}`);
131159
132-
unclaim-issue:
133-
# Only run on issue comments (not PR comments) and when comment contains @bot unclaim
160+
drop-issue:
161+
# Only run on issue comments (not PR comments) and when comment contains @bot drop
134162
if: |
135163
!github.event.issue.pull_request &&
136-
contains(github.event.comment.body, '@bot unclaim')
164+
contains(github.event.comment.body, '@bot drop')
137165
runs-on: ubuntu-latest
138166
# Prevent race conditions - only one job per issue at a time
139167
concurrency:
140168
group: issue-assign-${{ github.event.issue.number }}
141169
cancel-in-progress: false
142170

143171
steps:
144-
- name: Unclaim Issue
172+
- name: Drop Issue
145173
uses: actions/github-script@v8
146174
with:
147175
github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -150,12 +178,12 @@ jobs:
150178
const issue = context.payload.issue;
151179
const repo = context.repo;
152180
153-
console.log(`Processing @bot unclaim from ${commenter} on issue #${issue.number}`);
181+
console.log(`Processing @bot drop from ${commenter} on issue #${issue.number}`);
154182
155183
// Validate exact command match
156184
const commentBody = context.payload.comment.body.trim();
157-
if (commentBody !== '@bot unclaim') {
158-
console.log(`Comment "${commentBody}" is not an exact match for "@bot unclaim", skipping`);
185+
if (commentBody !== '@bot drop') {
186+
console.log(`Comment "${commentBody}" is not an exact match for "@bot drop", skipping`);
159187
return;
160188
}
161189
@@ -221,7 +249,7 @@ jobs:
221249
await github.rest.issues.createComment({
222250
...repo,
223251
issue_number: issue.number,
224-
body: `@${commenter} You have been unassigned from this issue. It's now available for others to claim.`
252+
body: `@${commenter} You have dropped this issue. It's now available for others to claim.`
225253
});
226254
227255
console.log(`Successfully unassigned ${commenter} from issue #${issue.number}`);

0 commit comments

Comments
 (0)