diff --git a/.github/workflows/assign-pr-author-on-merge.yml b/.github/workflows/assign-pr-author-on-merge.yml new file mode 100644 index 0000000..3862ff5 --- /dev/null +++ b/.github/workflows/assign-pr-author-on-merge.yml @@ -0,0 +1,33 @@ +name: Assign PR author on merge + +on: + pull_request_target: + types: [closed] + +permissions: + pull-requests: write + +jobs: + assign-author: + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true + + steps: + - name: Assign PR to its author + uses: actions/github-script@v7 + with: + script: | + const pr = context.payload.pull_request; + + // Get the PR author's username + const author = pr.user.login; + + // Assign PR to the author + await github.rest.issues.addAssignees({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + assignees: [author], + }); + + console.log(`PR #${pr.number} assigned to @${author}`);