feat: add GitHub Action to handle /assign and /unassign commands via issue comments#56
feat: add GitHub Action to handle /assign and /unassign commands via issue comments#56Pranjal6955 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a GitHub Actions workflow that listens to issue comments and implements /assign and /unassign commands to self-manage issue assignees (excluding PR comments), improving contributor workflow without maintainer intervention.
Changes:
- Introduces a new
issue_comment-triggered workflow to process/assignand/unassign. - Implements assignment/unassignment via
actions/github-scriptand posts confirmation comments. - Adds a PR-exclusion guard so commands only run on issues (not pull requests).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| types: [created] | ||
|
|
||
| jobs: | ||
| issue_commands: |
There was a problem hiding this comment.
The workflow doesn't declare explicit permissions. On many repos the default GITHUB_TOKEN permissions are read-only, which will cause addAssignees/removeAssignees/createComment to fail. Please add least-privilege permissions (e.g., permissions: issues: write and contents: read if needed) at the workflow or job level so this feature reliably works and limits token scope.
| issue_commands: | |
| issue_commands: | |
| permissions: | |
| issues: write |
| if: github.event.issue.pull_request == null && (startsWith(github.event.comment.body, '/assign') || startsWith(github.event.comment.body, '/unassign')) | ||
| steps: | ||
| - name: Handle Issue Commands | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| script: | | ||
| const commenter = context.payload.comment.user.login; | ||
| const issueNumber = context.payload.issue.number; | ||
| const body = context.payload.comment.body.trim(); | ||
|
|
||
| if (body === '/assign') { | ||
| try { |
There was a problem hiding this comment.
The job-level if: runs when the comment starts with /assign or /unassign, but the script only handles exact matches (body === '/assign' / '/unassign'). Comments like /assign please or /assign\n... will trigger the workflow but then do nothing (no feedback). Consider parsing the first token/line in the script (or tightening the job condition) so the trigger condition and command handling are consistent.
|
|
||
| console.log(`Successfully unassigned ${commenter} from issue #${issueNumber}`); | ||
| } catch (error) { | ||
| console.error(`Failed to unassign ${commenter}: ${error.message}`); |
There was a problem hiding this comment.
/unassign error handling only logs to the Actions output. If removeAssignees fails (e.g., commenter isn't assigned, lacks permission, or assignment is disabled for outside collaborators), the user gets no feedback. Consider posting an explanatory comment in the catch (similar to the /assign path) so the command isn't silently ignored.
| console.error(`Failed to unassign ${commenter}: ${error.message}`); | |
| console.error(`Failed to unassign ${commenter}: ${error.message}`); | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issueNumber, | |
| body: `Oops, @${commenter}! I couldn't unassign you from this issue. You might not currently be assigned, or you may not have the necessary permissions.` | |
| }); |
| if: github.event.issue.pull_request == null && (startsWith(github.event.comment.body, '/assign') || startsWith(github.event.comment.body, '/unassign')) | ||
| steps: | ||
| - name: Handle Issue Commands | ||
| uses: actions/github-script@v6 |
There was a problem hiding this comment.
For supply-chain safety, consider pinning actions/github-script to a full-length commit SHA (or at least a major+minor) rather than @v6. This reduces the risk of unexpected behavior changes from upstream updates.
| uses: actions/github-script@v6 | |
| uses: actions/github-script@v6.4.1 |
|
@Pranjal6955 could you please look into the review comments? |
Summary
This PR implements a GitHub Action that allows users to self-assign or unassign issues by commenting
/assignor/unassignin the issue comments. This improves the developer experience by letting contributors signal their intent to work on a task without requiring manual intervention from maintainers.Closes #52
Type of Change
What Changed
.github/workflows/assign.yml: Added a new GitHub Action workflow usingactions/github-script./assignand/unassignlogic.How to Test
/assignand verify you receive an assignment and a bot reply./unassignand verify the assignment is removed and the bot confirms it./assignagain while already assigned to see the duplicate warning message.Checklist
console.logor debug statements left in the code.Additional Context
The action specifically excludes Pull Request comments to avoid cluttering code reviews. Users may need to have basic collaboration rights (or the repository must be configured to allow outside contributors to be assigned) for this to function as expected.