Skip to content

Commit b751d26

Browse files
committed
chore(actions): harden YAML and scripts for contributor workflows
1 parent eea2ac0 commit b751d26

5 files changed

Lines changed: 201 additions & 169 deletions

File tree

.github/workflows/assign.yml

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,23 @@ jobs:
5757
return;
5858
}
5959
60-
const body = `${marker}
61-
👋 Hi @${assignee.login}, you have been assigned to this issue by @${assigner?.login || "a maintainer"}.
62-
63-
Welcome to LearnHub. Please make sure you:
64-
- Star the repository
65-
- Fork the repository
66-
- Read \`CONTRIBUTING.md\`
67-
- Read \`CODE_OF_CONDUCT.md\`
68-
- Understand the issue clearly before starting
69-
70-
Please share meaningful progress within 3 days, or the issue may be reassigned.
71-
72-
If you need help or may be delayed, please ping @udaycodespace or join Discord and message there with your GitHub username.
73-
74-
Note: PRs with fewer than 20 lines are not accepted.`;
60+
const intro =
61+
`👋 Hi @${assignee.login}, you have been assigned to this issue by @${assigner?.login || "a maintainer"}.\n\n`;
62+
const checklist =
63+
`Welcome to LearnHub. Please make sure you:\n` +
64+
`- Star the repository\n` +
65+
`- Fork the repository\n` +
66+
`- Read \`CONTRIBUTING.md\`\n` +
67+
`- Read \`CODE_OF_CONDUCT.md\`\n` +
68+
`- Understand the issue clearly before starting\n\n`;
69+
const timing =
70+
`Please share meaningful progress within 3 days, or the issue may be reassigned.\n\n`;
71+
const support =
72+
`If you need help or may be delayed, please ping @udaycodespace or join Discord and message there with your GitHub username.\n\n`;
73+
const note =
74+
`Note: PRs with fewer than 20 lines are not accepted.\n`;
75+
76+
const body = `${marker}\n${intro}${checklist}${timing}${support}${note}`;
7577
7678
await github.rest.issues.createComment({
7779
owner,
@@ -124,7 +126,6 @@ Note: PRs with fewer than 20 lines are not accepted.`;
124126
return;
125127
}
126128
127-
// Helper: check if commenter is maintainer
128129
async function isMaintainer(username) {
129130
try {
130131
const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({
@@ -141,13 +142,11 @@ Note: PRs with fewer than 20 lines are not accepted.`;
141142
}
142143
}
143144
144-
// Helper: current assignees
145145
const currentAssignees = (issue.assignees || []).map(a => a.login);
146146
const lowerCurrentAssignees = currentAssignees.map(login => login.toLowerCase());
147147
const commenterLower = commenter.toLowerCase();
148148
const issueAuthorLower = issueAuthor.toLowerCase();
149149
150-
// Helper: 2-open-issue limit
151150
async function hasTooManyOpenAssignments(username) {
152151
const { data: assignedItems } = await github.rest.issues.listForRepo({
153152
owner,
@@ -160,16 +159,18 @@ Note: PRs with fewer than 20 lines are not accepted.`;
160159
return assignedOpenIssuesOnly.length >= 2;
161160
}
162161
162+
const limitBody =
163+
`Easy there, legend — @${commenter} already has 2 open issues. Finish one first and let others cook too.\n`;
164+
163165
async function replyLimit(username) {
164166
await github.rest.issues.createComment({
165167
owner,
166168
repo,
167169
issue_number: issueNumber,
168-
body: `Easy there, legend — @${username} already has 2 open issues. Finish one first and let others cook too.`
170+
body: limitBody.replace(commenter, username)
169171
});
170172
}
171173
172-
// Sticky queue state comment helpers
173174
const QUEUE_MARKER = "<!-- learnhub-queue-state";
174175
175176
async function getQueueComment() {
@@ -243,7 +244,7 @@ last_progress_at: ${state.last_progress_at || ""}
243244
const commenterIsMaintainer = await isMaintainer(commenter);
244245
const isSelfIssue = commenterLower === issueAuthorLower;
245246

246-
// COMMAND: /assign (self or @someone)
247+
// /assign (self or @someone)
247248
if (isAssignCommand) {
248249
const rawArg = (assignMatch[1] || "").trim();
249250
const isForceAssign = /^@([a-zA-Z0-9-]+)$/i.test(rawArg);
@@ -279,7 +280,6 @@ last_progress_at: ${state.last_progress_at || ""}
279280

280281
const isAlreadyPrimary = queueState.primary.toLowerCase() === targetUser.toLowerCase();
281282

282-
// Remove existing assignees if primary changing
283283
if (!isAlreadyPrimary && currentAssignees.length > 0) {
284284
await github.rest.issues.removeAssignees({
285285
owner,
@@ -333,11 +333,14 @@ last_progress_at: ${state.last_progress_at || ""}
333333
});
334334
} catch (e) {}
335335

336+
const forceBody =
337+
`🎯 @${targetUser} has been assigned to this issue by a maintainer. Please share meaningful progress within 3 days, or it may be opened to others.\n`;
338+
336339
await github.rest.issues.createComment({
337340
owner,
338341
repo,
339342
issue_number: issueNumber,
340-
body: `🎯 @${targetUser} has been assigned to this issue by a maintainer. Please share meaningful progress within 3 days, or it may be opened to others.`
343+
body: forceBody
341344
});
342345

343346
return;
@@ -352,7 +355,6 @@ last_progress_at: ${state.last_progress_at || ""}
352355
const hasPrimaryAssignee = currentAssignees.length > 0;
353356

354357
if (!hasPrimaryAssignee) {
355-
// Assign commenter as primary
356358
if (!lowerCurrentAssignees.includes(commenterLower)) {
357359
await github.rest.issues.addAssignees({
358360
owner,
@@ -397,31 +399,29 @@ last_progress_at: ${state.last_progress_at || ""}
397399
});
398400
} catch (e) {}
399401

400-
const isAuthor = isSelfIssue;
401-
const welcomeBody = isAuthor
402-
? `🎉 @${commenter} has been assigned to this issue. Welcome to LearnHub.
403-
404-
Hope you do well on this issue. Please make sure you:
405-
- Star the repository
406-
- Fork the repository
407-
- Read \`CONTRIBUTING.md\`
408-
- Read \`CODE_OF_CONDUCT.md\`
409-
- Understand the issue clearly before starting
410-
- Share meaningful progress within 3 days
411-
412-
If you need help or may be delayed, please ping @udaycodespace.
413-
414-
Note: PRs with fewer than 20 lines are not accepted.`
415-
: `🎉 @${commenter} has been assigned to this issue. Welcome to LearnHub.
416-
417-
Please make sure you:
418-
- Star the repository
419-
- Fork the repository
420-
- Read \`CONTRIBUTING.md\`
421-
- Read \`CODE_OF_CONDUCT.md\`
422-
- Understand the issue clearly before starting
423-
424-
Please share meaningful progress within 3 days, or it may be made available to others.`;
402+
const authorWelcome =
403+
`🎉 @${commenter} has been assigned to this issue. Welcome to LearnHub.\n\n` +
404+
`Hope you do well on this issue. Please make sure you:\n` +
405+
`- Star the repository\n` +
406+
`- Fork the repository\n` +
407+
`- Read \`CONTRIBUTING.md\`\n` +
408+
`- Read \`CODE_OF_CONDUCT.md\`\n` +
409+
`- Understand the issue clearly before starting\n` +
410+
`- Share meaningful progress within 3 days\n\n` +
411+
`If you need help or may be delayed, please ping @udaycodespace.\n\n` +
412+
`Note: PRs with fewer than 20 lines are not accepted.\n`;
413+
414+
const nonAuthorWelcome =
415+
`🎉 @${commenter} has been assigned to this issue. Welcome to LearnHub.\n\n` +
416+
`Please make sure you:\n` +
417+
`- Star the repository\n` +
418+
`- Fork the repository\n` +
419+
`- Read \`CONTRIBUTING.md\`\n` +
420+
`- Read \`CODE_OF_CONDUCT.md\`\n` +
421+
`- Understand the issue clearly before starting\n\n` +
422+
`Please share meaningful progress within 3 days, or it may be made available to others.\n`;
423+
424+
const welcomeBody = isSelfIssue ? authorWelcome : nonAuthorWelcome;
425425

426426
await github.rest.issues.createComment({
427427
owner,
@@ -431,7 +431,6 @@ Please share meaningful progress within 3 days, or it may be made available to o
431431
});
432432

433433
} else {
434-
// Already assigned
435434
if (lowerCurrentAssignees.includes(commenterLower)) {
436435
await github.rest.issues.createComment({
437436
owner,
@@ -441,21 +440,24 @@ Please share meaningful progress within 3 days, or it may be made available to o
441440
});
442441
} else {
443442
const primary = currentAssignees[0];
443+
const alreadyBody =
444+
`@${commenter}, first priority for this issue is with @${primary}.\n\n` +
445+
`If you’d like to be next in queue, please use \`/work <approach>\` and describe how you plan to solve it. ` +
446+
`After the 3-day window, you may be auto-promoted if there is no meaningful progress from the primary assignee.\n`;
447+
444448
await github.rest.issues.createComment({
445449
owner,
446450
repo,
447451
issue_number: issueNumber,
448-
body: `@${commenter}, first priority for this issue is with @${primary}.
449-
450-
If you’d like to be next in queue, please use \`/work <approach>\` and describe how you plan to solve it. After the 3-day window, you may be auto-promoted if there is no meaningful progress from the primary assignee.`
452+
body: alreadyBody
451453
});
452454
}
453455
}
454456

455457
return;
456458
}
457459

458-
// COMMAND: /work <approach> (backup claim)
460+
// /work <approach>
459461
if (isWorkCommand) {
460462
if (issue.pull_request) {
461463
await github.rest.issues.createComment({
@@ -505,20 +507,20 @@ If you’d like to be next in queue, please use \`/work <approach>\` and describ
505507
body: buildQueueBody(queueState)
506508
});
507509

510+
const workBody =
511+
`@${commenter}, first priority is with @${primary}. You are now next in the queue for this issue with the following approach:\n\n` +
512+
`\`${approach}\`\n\n` +
513+
`Please make sure you:\n` +
514+
`- Star the repository\n` +
515+
`- Fork the repository\n` +
516+
`- Understand the issue clearly\n\n` +
517+
`If @${primary} doesn’t show meaningful progress within 3 days, you may be auto-promoted to primary assignee.\n`;
518+
508519
await github.rest.issues.createComment({
509520
owner,
510521
repo,
511522
issue_number: issueNumber,
512-
body: `@${commenter}, first priority is with @${primary}. You are now next in the queue for this issue with the following approach:
513-
514-
\`${approach}\`
515-
516-
Please make sure you:
517-
- Star the repository
518-
- Fork the repository
519-
- Understand the issue clearly
520-
521-
If @${primary} doesn’t show meaningful progress within 3 days, you may be auto-promoted to primary assignee.`
523+
body: workBody
522524
});
523525
} else if (queueState.backup.toLowerCase() === commenterLower) {
524526
await github.rest.issues.createComment({
@@ -539,7 +541,7 @@ If @${primary} doesn’t show meaningful progress within 3 days, you may be auto
539541
return;
540542
}
541543

542-
// COMMAND: /unassign
544+
// /unassign
543545
if (isUnassignCommand) {
544546
const isPrimary = lowerCurrentAssignees.includes(commenterLower);
545547

@@ -572,7 +574,6 @@ If @${primary} doesn’t show meaningful progress within 3 days, you may be auto
572574
assignees: usersToRemove
573575
});
574576

575-
// Reset queue completely on unassign
576577
queueState.primary = "";
577578
queueState.primary_assigned_at = "";
578579
queueState.backup = "";
@@ -715,7 +716,6 @@ last_progress_at: ${state.last_progress_at || ""}
715716
continue;
716717
}
717718

718-
// Promote backup
719719
const currentAssignees = (issue.assignees || []).map(a => a.login);
720720
if (currentAssignees.length > 0) {
721721
await github.rest.issues.removeAssignees({
@@ -756,16 +756,18 @@ last_progress_at: ${state.last_progress_at || ""}
756756
});
757757
} catch (e) {}
758758

759+
const promotionBody =
760+
`⏳ The primary claimant did not show enough progress in 3 days. @${backup} is now the new priority assignee for this issue.\n\n` +
761+
`Please:\n` +
762+
`- Star the repository\n` +
763+
`- Fork the repository\n` +
764+
`- Understand the issue clearly\n` +
765+
`- Share meaningful progress as soon as you can.\n`;
766+
759767
await github.rest.issues.createComment({
760768
owner,
761769
repo,
762770
issue_number: issueNumber,
763-
body: `⏳ The primary claimant did not show enough progress in 3 days. @${backup} is now the new priority assignee for this issue.
764-
765-
Please:
766-
- Star the repository
767-
- Fork the repository
768-
- Understand the issue clearly
769-
- Share meaningful progress as soon as you can.`
771+
body: promotionBody
770772
});
771773
}

0 commit comments

Comments
 (0)