Auto Assign and Unassign Issues #1
This file contains 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
name: Auto Assign and Unassign Issues | |
permissions: | |
issues: write # Ensure the workflow has permission to write to issues | |
on: | |
issues: | |
types: [opened] | |
schedule: | |
- cron: '0 0 * * 0' # Unassign workflow runs weekly | |
jobs: | |
auto-assign: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Check if the issue has specific labels | |
- name: Check if issue uses specific labels | |
id: label-check | |
run: | | |
if [[ "${{ github.event.issue.labels[*] }}" == *"bug"* || "${{ github.event.issue.labels[*] }}" == *"test"* || "${{ github.event.issue.labels[*] }}" == *"enhancement"* ]]; then | |
echo "template_matched=true" >> $GITHUB_ENV | |
else | |
echo "template_matched=false" >> $GITHUB_ENV | |
# Step 2: Check if issue creator is a collaborator | |
- name: Check if issue creator is a collaborator | |
id: collaborator-check | |
if: env.template_matched == 'true' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const { data: collaborators } = await github.repos.listCollaborators({ | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
const creator = context.payload.issue.user.login; | |
const isCollaborator = collaborators.some(collaborator => collaborator.login === creator); | |
return isCollaborator; | |
# Step 3: Assign issue to creator if not a collaborator | |
- name: Assign issue to creator if not a collaborator | |
if: steps.collaborator-check.outputs.result == 'false' && env.template_matched == 'true' | |
uses: actions-ecosystem/action-add-issue-assigner@v1 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
assignees: ${{ github.event.issue.user.login }} | |
auto-unassign: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 4: Unassign issues with no activity for a week | |
- name: Unassign issues with no activity for a week | |
uses: ahmadnassri/action-unassign-issues@v1 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
inactivity_days: 7 |