Skip to content

feat: add GitHub Action to handle /assign and /unassign commands via issue comments#56

Open
Pranjal6955 wants to merge 1 commit into
Dev-Card:mainfrom
Pranjal6955:Github-Workflow
Open

feat: add GitHub Action to handle /assign and /unassign commands via issue comments#56
Pranjal6955 wants to merge 1 commit into
Dev-Card:mainfrom
Pranjal6955:Github-Workflow

Conversation

@Pranjal6955
Copy link
Copy Markdown

@Pranjal6955 Pranjal6955 commented Apr 5, 2026

Summary

This PR implements a GitHub Action that allows users to self-assign or unassign issues by commenting /assign or /unassign in 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

  • Bug fix
  • New feature
  • Refactor (no functional change)
  • UI / Design change
  • Tests only
  • Documentation
  • Infrastructure / DevOps
  • Security

What Changed

  • Created .github/workflows/assign.yml: Added a new GitHub Action workflow using actions/github-script.
  • Integrated slash commands: Implemented /assign and /unassign logic.
  • Added feedback comments: The bot now replies with a confirmation message upon successful assignment or unassignment.
  • Handled edge cases: Included checks for duplicate assignments and basic error handling for permission issues.

How to Test

  1. Create a dummy issue in the repository.
  2. Comment /assign and verify you receive an assignment and a bot reply.
  3. Comment /unassign and verify the assignment is removed and the bot confirms it.
  4. Try commenting /assign again while already assigned to see the duplicate warning message.

Checklist

  • My code follows the project's coding style.
  • TypeScript compiles without errors.
  • I have added or updated tests for the changes I made.
  • All tests pass locally.
  • I have updated documentation wherever necessary.
  • No new console.log or debug statements left in the code.
  • Breaking changes are documented in this PR description.

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.

Copilot AI review requested due to automatic review settings April 5, 2026 18:16
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 /assign and /unassign.
  • Implements assignment/unassignment via actions/github-script and 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:
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
issue_commands:
issue_commands:
permissions:
issues: write

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +21
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 {
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

console.log(`Successfully unassigned ${commenter} from issue #${issueNumber}`);
} catch (error) {
console.error(`Failed to unassign ${commenter}: ${error.message}`);
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/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.

Suggested change
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.`
});

Copilot uses AI. Check for mistakes.
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
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
uses: actions/github-script@v6
uses: actions/github-script@v6.4.1

Copilot uses AI. Check for mistakes.
@ShantKhatri
Copy link
Copy Markdown
Contributor

@Pranjal6955 could you please look into the review comments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement /assign Command via GitHub Actions

3 participants