Skip to content
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

[Feature] Create GitHub workflow to assign issues to users on comment 'take' #2507

Open
3 tasks done
JuanPabloDiaz opened this issue Oct 1, 2024 · 3 comments
Open
3 tasks done
Labels
priority: high Making completely new feature

Comments

@JuanPabloDiaz
Copy link
Contributor

Description

Description

Users should be able to comment "take" on an issue to be auto-assigned the issue.

This creates a good experience for OSS users. They can grab an issue and it will make sure nobody else is working on it.

// .github/workflows/auto-assign-issues.yml

# This workflow has been inspired by https://github.com/MrPowers/quinn/blob/main/.github/workflows/assign-on-comment.yml

name: Auto Assign Issues On Comment

on:
  issue_comment:
    types: [created]

permissions:
  issues: write

jobs:
  auto-assign:
    runs-on: ubuntu-latest
    if: (!github.event.issue.pull_request) && github.event.comment.body == 'take'
    concurrency:
      # Only run one a time per user
      group: ${{ github.actor }}-auto-assign-issue
    steps:
      - name: Check if issue can be assigned
        id: check-assignee
        run: |
          # Check if the user is already assigned to the issue
          RESPONSE=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -LI https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/assignees/${{ github.event.comment.user.login }} -o /dev/null -w '%{http_code}' -s)
          echo "HTTP_CODE=$RESPONSE" >> $GITHUB_ENV

      - name: Assign issue to commenter
        if: env.HTTP_CODE == '204'
        run: |
          # Assign the issue to the user who commented 'take'
          echo "Assigning issue #${{ github.event.issue.number }} to @${{ github.event.comment.user.login }}"
          curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -d '{"assignees": ["${{ github.event.comment.user.login }}"]}' https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/assignees
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Log failure to assign
        if: env.HTTP_CODE != '204'
        run: |
          # Log the failure to assign the issue
          echo "Issue #${{ github.event.issue.number }} cannot be assigned to @${{ github.event.comment.user.login }}. HTTP response code: ${{ env.HTTP_CODE }}"

Screenshots

Visual example:

image

Checklist

  • I have checked the existing issues
  • I have read the Contributing Guidelines
  • I am willing to work on this issue (optional)
@JuanPabloDiaz JuanPabloDiaz added the priority: high Making completely new feature label Oct 1, 2024
Copy link

github-actions bot commented Oct 1, 2024

Hello JuanPabloDiaz!
Thank you for raising this issue! 😊 Your contribution is valuable to us! 😊

Please make sure to follow our Contributing Guidelines. 💪🏻

Please only work on an issue if you're assigned; otherwise, the PR will be automatically closed.
Our review team will carefully assess the issue and reach out to you soon! 😇
We appreciate your patience!

@rupali-codes
Copy link
Owner

Hi @JuanPabloDiaz, won't this create overlapping?

@JuanPabloDiaz
Copy link
Contributor Author

Hi @JuanPabloDiaz, won't this create overlapping?

This action is use on well-known projects.

Test it and removed it if it does not work as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: high Making completely new feature
Projects
None yet
Development

No branches or pull requests

2 participants