|
| 1 | +async function handleUnclaim({ github, context }) { |
| 2 | + const { owner, repo } = context.repo; |
| 3 | + const issueNumber = context.payload.issue.number; |
| 4 | + const commenter = context.payload.comment.user.login; |
| 5 | + const issueState = context.payload.issue.state; |
| 6 | + |
| 7 | + if (issueState === 'closed') { |
| 8 | + await github.rest.issues.createComment({ |
| 9 | + owner, |
| 10 | + repo, |
| 11 | + issue_number: issueNumber, |
| 12 | + body: `❌ Commands cannot be used on closed issues.`, |
| 13 | + }); |
| 14 | + return; |
| 15 | + } |
| 16 | + |
| 17 | + const currentAssignees = context.payload.issue.assignees.map((a) => a.login.toLowerCase()); |
| 18 | + |
| 19 | + if (!currentAssignees.includes(commenter.toLowerCase())) { |
| 20 | + await github.rest.issues.createComment({ |
| 21 | + owner, |
| 22 | + repo, |
| 23 | + issue_number: issueNumber, |
| 24 | + body: `ℹ️ @${commenter}, you are not currently assigned to this issue, so there's nothing to unclaim.`, |
| 25 | + }); |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + await github.rest.issues.removeAssignees({ |
| 30 | + owner, |
| 31 | + repo, |
| 32 | + issue_number: issueNumber, |
| 33 | + assignees: [commenter], |
| 34 | + }); |
| 35 | + |
| 36 | + await github.rest.issues.createComment({ |
| 37 | + owner, |
| 38 | + repo, |
| 39 | + issue_number: issueNumber, |
| 40 | + body: `✅ Successfully unclaimed this issue for @${commenter}.\n\n> 🔓 The issue is now open for others to claim.`, |
| 41 | + }); |
| 42 | +} |
| 43 | + |
| 44 | +module.exports = { handleUnclaim }; |
0 commit comments