-
Notifications
You must be signed in to change notification settings - Fork 70
feat: Add /unassign command to allow contributors to unassign themselves #1246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rwalworth
merged 1 commit into
hiero-ledger:main
from
darshit2308:feature/unassign-command
Mar 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| // commands/unassign-comments.js | ||
| // | ||
| // Comment builders for the /unassign command. Pure formatting functions | ||
| // separated from unassignment logic for readability. | ||
|
|
||
| const { MAINTAINER_TEAM, LABELS } = require('../helpers'); | ||
|
|
||
| /** | ||
| * Builds the comment posted after a successful unassignment. | ||
| * | ||
| * @param {string} username - The GitHub username being unassigned. | ||
| * @returns {string} The formatted Markdown comment body. | ||
| */ | ||
| function buildSuccessfulUnassignComment(username) { | ||
| return [ | ||
| `👋 Hi @${username}! You have been successfully unassigned from this issue.`, | ||
| '', | ||
| `The \`${LABELS.IN_PROGRESS}\` label has been removed, and it is now back to \`${LABELS.READY_FOR_DEV}\` for others to claim. Thanks for letting us know!`, | ||
| ].join('\n'); | ||
| } | ||
|
|
||
| /** | ||
| * Builds the comment posted when a user tries to unassign an issue they don't own. | ||
| * | ||
| * @param {string} requesterUsername - The GitHub username who commented /unassign. | ||
| * @param {string} currentAssignee - The GitHub username of the actual assignee. | ||
| * @returns {string} The formatted Markdown comment body. | ||
| */ | ||
| function buildNotAssignedToUserComment(requesterUsername, currentAssignee) { | ||
| const assigneeText = currentAssignee ? `@${currentAssignee}` : 'someone else'; | ||
| return [ | ||
| `⚠️ Hi @${requesterUsername}! You cannot unassign this issue because it is currently assigned to ${assigneeText}.`, | ||
| '', | ||
| 'Only the current assignee can unassign themselves.', | ||
| ].join('\n'); | ||
| } | ||
|
|
||
| /** | ||
| * Builds the comment posted when the issue has no assignees. | ||
| * | ||
| * @param {string} requesterUsername - The GitHub username who commented /unassign. | ||
| * @returns {string} The formatted Markdown comment body. | ||
| */ | ||
| function buildNoAssigneeComment(requesterUsername) { | ||
| return [ | ||
| `👋 Hi @${requesterUsername}! This issue doesn't currently have any assignees.`, | ||
| ].join('\n'); | ||
| } | ||
|
|
||
| /** | ||
| * Builds the comment posted when the issue is already closed. | ||
| * | ||
| * @param {string} requesterUsername - The GitHub username who commented /unassign. | ||
| * @returns {string} The formatted Markdown comment body. | ||
| */ | ||
| function buildIssueClosedComment(requesterUsername) { | ||
| return [ | ||
| `👋 Hi @${requesterUsername}! This issue is already closed, so the \`/unassign\` command cannot be used here.`, | ||
| ].join('\n'); | ||
| } | ||
|
|
||
| /** | ||
| * Builds the comment posted when the unassign API call fails. | ||
| * | ||
| * @param {string} requesterUsername - The GitHub username who commented /unassign. | ||
| * @returns {string} The formatted Markdown comment body. | ||
| */ | ||
| function buildUnassignFailureComment(requesterUsername) { | ||
| return [ | ||
| `⚠️ Hi @${requesterUsername}! I tried to unassign you, but encountered an unexpected error.`, | ||
| '', | ||
| `${MAINTAINER_TEAM} — could you please manually unassign @${requesterUsername}?`, | ||
| ].join('\n'); | ||
| } | ||
|
|
||
| module.exports = { | ||
| buildSuccessfulUnassignComment, | ||
| buildNotAssignedToUserComment, | ||
| buildNoAssigneeComment, | ||
| buildIssueClosedComment, | ||
| buildUnassignFailureComment, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| // commands/unassign.js | ||
| // | ||
| // /unassign command: allows a currently assigned contributor to unassign themselves. | ||
| // Enforces authorization (only assignees can unassign themselves) and reverts | ||
| // status labels back to the community pool. | ||
|
|
||
| const { | ||
| LABELS, | ||
| ISSUE_STATE, | ||
| getLogger, | ||
| hasLabel, | ||
| addLabels, | ||
| removeLabel, | ||
| removeAssignees, | ||
| postComment, | ||
| } = require('../helpers'); | ||
|
|
||
| const { | ||
| buildSuccessfulUnassignComment, | ||
| buildNotAssignedToUserComment, | ||
| buildNoAssigneeComment, | ||
| buildIssueClosedComment, | ||
| buildUnassignFailureComment, | ||
| } = require('./unassign-comments'); | ||
|
|
||
| // Delegate to the active logger set by the dispatcher. | ||
| const logger = { | ||
| log: (...args) => getLogger().log(...args), | ||
| error: (...args) => getLogger().error(...args), | ||
| }; | ||
|
|
||
| /** | ||
| * Main handler for the /unassign command. Runs the following gates in order: | ||
| * | ||
| * 1. Is the issue already closed? -> issue-closed comment. | ||
| * 2. Does the issue have no assignees? -> no-assignee comment. | ||
| * 3. Is the commenter not the current assignee? -> unauthorized comment. | ||
| * | ||
| * On success: removes the user as an assignee, reverts the "in progress" | ||
| * label to "ready for dev", and posts an acknowledgment comment. | ||
| * | ||
| * @param {{ github: object, owner: string, repo: string, number: number, | ||
| * issue: object, comment: { user: { login: string } } }} botContext | ||
| * @returns {Promise<void>} | ||
| */ | ||
| async function handleUnassign(botContext) { | ||
rwalworth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const requesterUsername = botContext.comment.user.login; | ||
| const issue = botContext.issue; | ||
|
|
||
| // GATE 1: Issue is closed | ||
| if (issue.state === ISSUE_STATE.CLOSED) { | ||
| logger.log('Exit: issue is closed'); | ||
| await postComment(botContext, buildIssueClosedComment(requesterUsername)); | ||
| return; | ||
| } | ||
|
|
||
| const assignees = issue.assignees || []; | ||
|
|
||
| // GATE 2: No one is assigned at all | ||
| if (assignees.length === 0) { | ||
| logger.log('Exit: issue has no assignees'); | ||
| await postComment(botContext, buildNoAssigneeComment(requesterUsername)); | ||
| return; | ||
| } | ||
|
|
||
| // GATE 3: Authorization check (case-insensitive) | ||
| const isAssigned = assignees.some( | ||
| (a) => (a?.login || '').toLowerCase() === requesterUsername.toLowerCase() | ||
| ); | ||
| if (!isAssigned) { | ||
| logger.log(`Exit: @${requesterUsername} is not assigned to this issue`); | ||
| const currentAssignee = assignees[0]?.login; // Grab the actual assignee for the message | ||
| await postComment(botContext, buildNotAssignedToUserComment(requesterUsername, currentAssignee)); | ||
| return; | ||
| } | ||
|
|
||
| // ACTION 1: Remove the assignee | ||
| logger.log(`Unassigning @${requesterUsername}`); | ||
| const removeResult = await removeAssignees(botContext, [requesterUsername]); | ||
| if (!removeResult.success) { | ||
| await postComment(botContext, buildUnassignFailureComment(requesterUsername)); | ||
| return; | ||
| } | ||
|
|
||
| // ACTION 2: Label Swapping (Mirroring assign.js style - no stale checks) | ||
| logger.log(`Swapping labels: removing ${LABELS.IN_PROGRESS}, adding ${LABELS.READY_FOR_DEV}`); | ||
|
|
||
| const removeLabelResult = await removeLabel(botContext, LABELS.IN_PROGRESS); | ||
| if (!removeLabelResult.success) { | ||
| logger.error(`Failed to remove ${LABELS.IN_PROGRESS}: ${removeLabelResult.error}`); | ||
| } | ||
|
|
||
| const addLabelResult = await addLabels(botContext, [LABELS.READY_FOR_DEV]); | ||
| if (!addLabelResult.success) { | ||
| logger.error(`Failed to add ${LABELS.READY_FOR_DEV}: ${addLabelResult.error}`); | ||
| } | ||
rwalworth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // ACTION 3: Post success acknowledgment | ||
| await postComment(botContext, buildSuccessfulUnassignComment(requesterUsername)); | ||
| logger.log(`Successfully unassigned @${requesterUsername} and reverted labels`); | ||
| } | ||
|
|
||
| module.exports = { handleUnassign }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.