Skip to content

Commit b3c116d

Browse files
Jagadeeshftwclaude
andcommitted
ci: stop auto-assign from failing on a bad maintainer token
Every contributor comment that reached the API calls turned into a red run on main with `401 Bad credentials` — the MAINTAINER_GH_TOKEN secret has expired. Fall back to the built-in GITHUB_TOKEN (the job already declares `issues: write`, which covers search, timeline reads, assign and comment), and treat assignment failures as warnings rather than job failures, since auto-assignment is a convenience and not a gate. Also bump actions/github-script v7 -> v9 to clear the Node 20 deprecation warning and match stellopay-core. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent f2e6c7d commit b3c116d

1 file changed

Lines changed: 53 additions & 42 deletions

File tree

.github/workflows/auto-assign.yml

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Assign commenter if they asked to work on this issue
16-
uses: actions/github-script@v7
16+
uses: actions/github-script@v9
1717
with:
18-
github-token: ${{ secrets.MAINTAINER_GH_TOKEN }}
18+
# Falls back to the built-in GITHUB_TOKEN when no maintainer PAT is
19+
# configured. `permissions.issues: write` above covers everything this
20+
# script needs (search, timeline reads, assign, comment).
21+
github-token: ${{ secrets.MAINTAINER_GH_TOKEN || github.token }}
1922
script: |
2023
const MAX_ASSIGNED_PER_REPO = 6;
2124
const body = (context.payload.comment.body || "").toLowerCase();
@@ -32,54 +35,62 @@ jobs:
3235
return;
3336
}
3437
35-
const { data: assignedOpen } = await github.rest.search.issuesAndPullRequests({
36-
q: `repo:${context.repo.owner}/${context.repo.repo} type:issue state:open assignee:${commenter}`,
37-
});
38+
// Assignment is a convenience, not a gate. A credential problem (an
39+
// expired MAINTAINER_GH_TOKEN, say) or a transient API error must not
40+
// turn every contributor comment into a red run on the default branch,
41+
// so failures are reported as warnings and the job still succeeds.
42+
try {
43+
const { data: assignedOpen } = await github.rest.search.issuesAndPullRequests({
44+
q: `repo:${context.repo.owner}/${context.repo.repo} type:issue state:open assignee:${commenter}`,
45+
});
46+
47+
// Only issues with NO open-or-merged pull request count against the cap —
48+
// a PR that's still open (in review) or already merged means the assignee
49+
// is clearly active/delivering, so it shouldn't count. A PR that was closed
50+
// WITHOUT merging represents abandoned work and still counts toward the cap.
51+
let uncoveredCount = 0;
52+
for (const item of assignedOpen.items) {
53+
const timeline = await github.rest.issues.listEventsForTimeline({
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
issue_number: item.number,
57+
per_page: 100,
58+
});
59+
const hasActivePr = timeline.data.some((ev) => {
60+
if (ev.event !== "cross-referenced" || !ev.source || !ev.source.issue || !ev.source.issue.pull_request) {
61+
return false;
62+
}
63+
const pr = ev.source.issue.pull_request;
64+
const isMerged = !!pr.merged_at;
65+
const isOpen = ev.source.issue.state === "open";
66+
return isOpen || isMerged;
67+
});
68+
if (!hasActivePr) uncoveredCount++;
69+
}
70+
71+
if (uncoveredCount >= MAX_ASSIGNED_PER_REPO) {
72+
await github.rest.issues.createComment({
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
issue_number: issue.number,
76+
body: `Thanks for the interest, @${commenter}! You currently have ${uncoveredCount} assigned issues in this repo with no PR up yet, which is the cap (${MAX_ASSIGNED_PER_REPO}) for this project. Please open a PR for one of them (or release it) before taking on another — issues you've already submitted a PR for don't count against this.`,
77+
});
78+
return;
79+
}
3880
39-
// Only issues with NO open-or-merged pull request count against the cap —
40-
// a PR that's still open (in review) or already merged means the assignee
41-
// is clearly active/delivering, so it shouldn't count. A PR that was closed
42-
// WITHOUT merging represents abandoned work and still counts toward the cap.
43-
let uncoveredCount = 0;
44-
for (const item of assignedOpen.items) {
45-
const timeline = await github.rest.issues.listEventsForTimeline({
81+
await github.rest.issues.addAssignees({
4682
owner: context.repo.owner,
4783
repo: context.repo.repo,
48-
issue_number: item.number,
49-
per_page: 100,
50-
});
51-
const hasActivePr = timeline.data.some((ev) => {
52-
if (ev.event !== "cross-referenced" || !ev.source || !ev.source.issue || !ev.source.issue.pull_request) {
53-
return false;
54-
}
55-
const pr = ev.source.issue.pull_request;
56-
const isMerged = !!pr.merged_at;
57-
const isOpen = ev.source.issue.state === "open";
58-
return isOpen || isMerged;
84+
issue_number: issue.number,
85+
assignees: [commenter],
5986
});
60-
if (!hasActivePr) uncoveredCount++;
61-
}
6287
63-
if (uncoveredCount >= MAX_ASSIGNED_PER_REPO) {
6488
await github.rest.issues.createComment({
6589
owner: context.repo.owner,
6690
repo: context.repo.repo,
6791
issue_number: issue.number,
68-
body: `Thanks for the interest, @${commenter}! You currently have ${uncoveredCount} assigned issues in this repo with no PR up yet, which is the cap (${MAX_ASSIGNED_PER_REPO}) for this project. Please open a PR for one of them (or release it) before taking on another — issues you've already submitted a PR for don't count against this.`,
92+
body: `Assigned @${commenter} to this issue. Please open a PR referencing this issue (e.g. \`Closes #${issue.number}\`) when you're ready. If you have questions along the way, feel free to join our contributor chat: https://t.me/+vTbe0hOUKrFhNTJl`,
6993
});
70-
return;
94+
} catch (err) {
95+
core.warning(`Auto-assign for @${commenter} on #${issue.number} did not complete (${err.status || "no status"}): ${err.message}`);
7196
}
72-
73-
await github.rest.issues.addAssignees({
74-
owner: context.repo.owner,
75-
repo: context.repo.repo,
76-
issue_number: issue.number,
77-
assignees: [commenter],
78-
});
79-
80-
await github.rest.issues.createComment({
81-
owner: context.repo.owner,
82-
repo: context.repo.repo,
83-
issue_number: issue.number,
84-
body: `Assigned @${commenter} to this issue. Please open a PR referencing this issue (e.g. \`Closes #${issue.number}\`) when you're ready. If you have questions along the way, feel free to join our contributor chat: https://t.me/+vTbe0hOUKrFhNTJl`,
85-
});

0 commit comments

Comments
 (0)