From e51628308ddabc04cde0bb4970b5343a7d5b4323 Mon Sep 17 00:00:00 2001 From: Revati Kadam Date: Mon, 6 Jul 2026 15:06:59 +0530 Subject: [PATCH 1/3] style --- .github/workflows/issue-automation.yml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/issue-automation.yml b/.github/workflows/issue-automation.yml index 62388af..cc65f9e 100644 --- a/.github/workflows/issue-automation.yml +++ b/.github/workflows/issue-automation.yml @@ -38,16 +38,24 @@ jobs: // ======================================================== // 2. HANDLE ISSUE COMMANDS (Features 2, 3, 4) // ======================================================== - if (context.eventName === 'issue_comment' && !context.payload.issue.pull_request) { + if (context.eventName === 'issue_comment' && !context.payload.issue.pull_request) { 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 || []; + + // Fetch the absolute freshest issue state to prevent race conditions + const { data: freshIssue } = await github.rest.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber + }); + + const issueState = freshIssue.state; + const assignees = freshIssue.assignees || []; const isAssigned = assignees.length > 0; - const issueAuthor = context.payload.issue.user.login; + const issueAuthor = freshIssue.user.login; const isIssueAuthor = commenter === issueAuthor; - const authorAssociation = context.payload.issue.author_association; + const authorAssociation = freshIssue.author_association; const isMaintainerIssue = [ "OWNER", @@ -161,7 +169,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, From 3d94f4ad0db1c9f2cfe518820c44a5ea1e416b15 Mon Sep 17 00:00:00 2001 From: Revati Kadam Date: Tue, 7 Jul 2026 18:32:34 +0530 Subject: [PATCH 2/3] Update issue-automation.yml --- .github/workflows/issue-automation.yml | 56 ++++++++++---------------- 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/.github/workflows/issue-automation.yml b/.github/workflows/issue-automation.yml index cc65f9e..ceff98f 100644 --- a/.github/workflows/issue-automation.yml +++ b/.github/workflows/issue-automation.yml @@ -38,24 +38,34 @@ jobs: // ======================================================== // 2. HANDLE ISSUE COMMANDS (Features 2, 3, 4) // ======================================================== - if (context.eventName === 'issue_comment' && !context.payload.issue.pull_request) { + if (context.eventName === 'issue_comment' && !context.payload.issue.pull_request) { const commentBody = context.payload.comment.body.trim(); const commenter = context.payload.comment.user.login; const issueNumber = context.issue.number; - // Fetch the absolute freshest issue state to prevent race conditions - const { data: freshIssue } = await github.rest.issues.get({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issueNumber - }); + // 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 issueState = freshIssue.state; - const assignees = freshIssue.assignees || []; const isAssigned = assignees.length > 0; - const issueAuthor = freshIssue.user.login; const isIssueAuthor = commenter === issueAuthor; - const authorAssociation = freshIssue.author_association; const isMaintainerIssue = [ "OWNER", @@ -66,30 +76,6 @@ jobs: const UNCLAIM_COMMAND = "/unclaim"; const BOT_MESSAGES = { - 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) => - `🎉 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.`, - - 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: From 8dd14279bc65c42e2d4a01a113d21052ca6a4d1f Mon Sep 17 00:00:00 2001 From: Revati Kadam Date: Tue, 7 Jul 2026 18:36:42 +0530 Subject: [PATCH 3/3] Update issue-automation.yml --- .github/workflows/issue-automation.yml | 63 ++++++++++++-------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/.github/workflows/issue-automation.yml b/.github/workflows/issue-automation.yml index ceff98f..a54f77d 100644 --- a/.github/workflows/issue-automation.yml +++ b/.github/workflows/issue-automation.yml @@ -76,43 +76,36 @@ jobs: const UNCLAIM_COMMAND = "/unclaim"; const BOT_MESSAGES = { - 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.`, + 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) => + `🎉 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) => + `❌ 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) => + `❌ 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}.`, + limitReached: (user, issuesList) => { let listStr = ""; if (issuesList && issuesList.length > 0) {