Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 34 additions & 48 deletions .github/workflows/issue-automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,30 @@ jobs:
const commentBody = context.payload.comment.body.trim();
const commenter = context.payload.comment.user.login;
const issueNumber = context.issue.number;
const issueState = context.payload.issue.state;
const assignees = context.payload.issue.assignees || [];

// Fallback variables using payload data in case the real-time API call fails
let issueState = context.payload.issue.state;
let assignees = context.payload.issue.assignees || [];
let issueAuthor = context.payload.issue.user.login;
let authorAssociation = context.payload.issue.author_association;

// Fetch freshest issue state via API to eliminate race conditions
try {
const { data: freshIssue } = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
issueState = freshIssue.state;
assignees = freshIssue.assignees || [];
issueAuthor = freshIssue.user.login;
authorAssociation = freshIssue.author_association;
} catch (error) {
console.warn(`⚠️ Warning: Failed to fetch fresh issue state from API for #${issueNumber}. Falling back to payload data. Error: ${error.message}`);
}

const isAssigned = assignees.length > 0;
const issueAuthor = context.payload.issue.user.login;
const isIssueAuthor = commenter === issueAuthor;
const authorAssociation = context.payload.issue.author_association;

const isMaintainerIssue = [
"OWNER",
Expand All @@ -58,67 +76,36 @@ jobs:
const UNCLAIM_COMMAND = "/unclaim";

const BOT_MESSAGES = {
invalidClaim: (user) =>
invalidClaim: (user) =>
`👋 Thanks for your interest, @${user}!\n\n` +
`To claim this issue, please comment:\n\n` +
`\`${CLAIM_COMMAND}\`\n\n` +
`Only the first valid \`${CLAIM_COMMAND}\` comment is eligible for automatic assignment.`,

assigned: (user) =>
assigned: (user) =>
`🎉 Issue Assigned\n\n` +
`Welcome @${user}!\n\n` +
`This issue has been assigned to you following our first-come, first-served policy.\n\n` +
`Please submit a Pull Request within 24 hours.\n\n` +
`If you need more time, please update the issue before the deadline.\n\n` +
`Happy coding! 🚀`,

alreadyAssigned: (user) =>
`⚠️ This issue is currently assigned to @${user}.\n\n` +
`If the issue becomes available again, feel free to claim it.`,
alreadyAssigned: (user) =>
`❌ Issue Already Assigned\n\n` +
`This issue is currently assigned to @${user}.\n\n` +
`Please explore other available unassigned issues while waiting for this issue to become available.\n\n` +
`If the current assignee becomes inactive, the issue may be automatically reopened according to the repository's assignment policy.\n\n` +
`Thank you for your interest in contributing! 💙`,

claimRejected: (author) =>
claimRejected: (author) =>
`❌ This issue was opened by another contributor.\n\n` +
`Only the issue author (@${author}) may claim this issue automatically.\n\n` +
`Repository maintainers may still assign contributors manually if required.`,

alreadyClaimed: (user) => `⚠️ @${user}, you are already assigned to this issue!`,
closedIssue: (user) => `❌ Request denied. You cannot claim a closed issue, @${user}.`
invalidClaim: (user) => `👋 Thanks for your interest, @${user}!

To claim this issue, please comment:

\`${CLAIM_COMMAND}\`

Only the first valid \`${CLAIM_COMMAND}\` comment is eligible for automatic assignment.`,

assigned: (user) => `🎉 Issue Assigned

Welcome @${user}!

This issue has been assigned to you following our first-come, first-served policy.

Please submit a Pull Request within 24 hours.

If you need more time, please update the issue before the deadline.

Happy coding! 🚀`,

alreadyAssigned: (user) => `❌ Issue Already Assigned

This issue is currently assigned to @${user}.

Please explore other available unassigned issues while waiting for this issue to become available.

If the current assignee becomes inactive, the issue may be automatically reopened according to the repository's assignment policy.

Thank you for your interest in contributing! 💙`,

claimRejected: (author) => `❌ This issue was opened by another contributor.

Only the issue author (@${author}) may claim this issue automatically.

Repository maintainers may still assign contributors manually if required.`,
alreadyClaimed: (user) => `⚠️ @${user}, you are already assigned to this issue!`,

closedIssue: (user) => `❌ Request denied. You cannot claim a closed issue, @${user}.`,

limitReached: (user, issuesList) => {
let listStr = "";
if (issuesList && issuesList.length > 0) {
Expand Down Expand Up @@ -161,7 +148,6 @@ Repository maintainers may still assign contributors manually if required.`,
commentBody !== CLAIM_COMMAND &&
commentBody !== UNCLAIM_COMMAND &&
invalidClaimMessages.includes(commentBody.toLowerCase())
){
) {
await github.rest.issues.createComment({
owner: context.repo.owner,
Expand Down
Loading