Claim bot: let an unassigned claimant /unclaim (#6718) (#6719)

* claim: #6718

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Claim bot: let an unassigned claimant /unclaim (#6718)

GitHub doesn't assign people who aren't collaborators, so many claims
have the `in progress` label and the bot's "Claimed by @user" reply but
no assignee, and `/unclaim` refused the claimant. When nobody is
assigned, `unclaim()` now also accepts the user named in the bot's
latest "Claimed by" reply on the timeline, unless the label was removed
after it. Maintainers and the owner rule are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yhamil04
2026-10-26 23:28:46 +00:00
committed by GitHub
parent 367aa249bc
commit ef1d02f274
2 changed files with 51 additions and 1 deletions
+18 -1
View File
@@ -8,6 +8,7 @@ const LABEL_DESCRIPTION = 'Someone is working on this';
const CLAIM_HOURS = 72;
const PR_IDLE_DAYS = 14;
const HOUR = 3600 * 1000;
const BOT = 'github-actions[bot]';
function parseCommand(body) {
const text = String(body || '').trimStart();
@@ -96,6 +97,19 @@ function linkedPulls(timeline, context, number) {
return [...seen.values()].sort((a, b) => a.number - b.number);
}
// Who the bot's latest "Claimed by @user" reply names, unless the label came off after it.
// GitHub doesn't assign people who aren't collaborators, so for them this reply is the only record.
function recordedClaimant(timeline) {
let who = null;
for (const ev of timeline) {
if (ev.event === 'unlabeled' && ev.label && ev.label.name === LABEL) who = null;
const mine = ev.event === 'commented' && ev.user && ev.user.login === BOT;
const m = mine && /^Claimed by @([A-Za-z0-9-]+)/.exec(ev.body || '');
if (m) who = m[1];
}
return who;
}
async function lastPush(github, context, pr) {
const { data } = await github.rest.pulls.get({ ...repoArgs(context), pull_number: pr.number });
const { data: commit } = await github.rest.repos.getCommit({
@@ -234,7 +248,10 @@ async function unclaim(github, context) {
await react(github, context, 'eyes'); // only the owner releases their own issues
return;
}
const allowed = assignees.includes(user) || (await isMaintainer(github, context, user));
let allowed = assignees.includes(user) || (await isMaintainer(github, context, user));
if (!allowed && assignees.length === 0) {
allowed = recordedClaimant(await getTimeline(github, context, issue.number)) === user;
}
if (!allowed) {
await react(github, context, 'eyes');
await reply(github, context, `Only the person who claimed this, or a maintainer, can release it, @${user}.`);
+33
View File
@@ -54,6 +54,7 @@ function fake(world = {}) {
const names = (calls) => calls.map((c) => c[0]);
const find = (calls, n) => calls.find((c) => c[0] === n);
const labeled = (at) => ({ event: 'labeled', label: { name: 'in progress' }, created_at: at });
const said = (body, login = 'github-actions[bot]') => ({ event: 'commented', body, user: { login } });
const pr = (number, login = 'other', state = 'open', extra = {}) => ({
event: 'cross-referenced',
source: { issue: {
@@ -188,6 +189,38 @@ test('unclaim by a maintainer releases, by a stranger does not', async () => {
assert.equal(find(w.calls, 'react')[1].content, 'eyes');
});
test('unclaim by a claimant the bot could not assign releases, by a stranger does not', async () => {
const timeline = [labeled(ago(5 * H)), said('Claimed by @alice through #50. The claim lapses after 14 days without pushes.')];
let w = fake({ timeline });
await claim.handleComment({ github: w.github, context: ctx('/unclaim', { labels: ['in progress'] }), now: NOW });
assert.equal(find(w.calls, 'removeLabel')[1].name, 'in progress');
assert.equal(find(w.calls, 'removeAssignees'), undefined);
assert.equal(find(w.calls, 'react')[1].content, '+1');
w = fake({ timeline });
await claim.handleComment({ github: w.github, context: ctx('/unclaim', { user: 'mallory', labels: ['in progress'] }), now: NOW });
assert.equal(find(w.calls, 'removeLabel'), undefined);
assert.match(find(w.calls, 'comment')[1].body, /Only the person who claimed this/);
w = fake({ timeline, perms: { carol: 'write' } });
await claim.handleComment({ github: w.github, context: ctx('/unclaim', { user: 'carol', labels: ['in progress'] }), now: NOW });
assert.ok(find(w.calls, 'removeLabel'));
});
test('only the bot\'s latest claim reply, before any release or assignment, names the claimant', async () => {
const cases = [
[said('Claimed by @mallory.', 'mallory')], // not the bot
[said('Claimed by @mallory.'), { event: 'unlabeled', label: { name: 'in progress' } }, labeled(ago(H))], // released since
[said('Claimed by @mallory.'), said('Claimed by @bob.')], // taken over
];
for (const timeline of cases) {
const w = fake({ timeline });
await claim.handleComment({ github: w.github, context: ctx('/unclaim', { user: 'mallory', labels: ['in progress'] }), now: NOW });
assert.equal(find(w.calls, 'removeLabel'), undefined);
}
const w = fake({ timeline: [said('Claimed by @mallory.')] }); // someone is assigned since
await claim.handleComment({ github: w.github, context: ctx('/unclaim', { user: 'mallory', assignees: ['bob'], labels: ['in progress'] }), now: NOW });
assert.equal(find(w.calls, 'removeLabel'), undefined);
});
test('unclaim on an owner-assigned issue works only for the owner', async () => {
let w = fake();
await claim.handleComment({ github: w.github, context: ctx('/unclaim', { user: 'carol', assignees: ['bherbruck'], labels: ['in progress'] }), now: NOW });