diff --git a/.github/workflows/pr-auto-assignee.yml b/.github/workflows/pr-auto-assignee.yml index 88dd3165..c7af8571 100644 --- a/.github/workflows/pr-auto-assignee.yml +++ b/.github/workflows/pr-auto-assignee.yml @@ -12,6 +12,11 @@ on: description: 'A list of reviewers(GitHub user name) to be added to PRs' required: false type: string + assign_yourself: + description: 'Whether to assign the PR opener as an assignee' + required: false + type: boolean + default: true secrets: GITHUB: description: 'Your GitHub token for authentication.' @@ -27,4 +32,18 @@ jobs: assignees: ${{ inputs.assignees }} reviewers: ${{ inputs.reviewers }} skipKeywords: wip, draft + + - uses: actions/github-script@v7 + if: ${{ inputs.assign_yourself }} + with: + github-token: ${{ secrets.GITHUB }} + script: | + const opener = context.payload.pull_request.user.login; + + await github.rest.issues.addAssignees({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + assignees:[ opener ] + }); ... diff --git a/docs/pr-auto-assignee.md b/docs/pr-auto-assignee.md index 4092a2c7..df3a908c 100644 --- a/docs/pr-auto-assignee.md +++ b/docs/pr-auto-assignee.md @@ -3,7 +3,16 @@ This workflow automates process for assigning assignees to the PR which would opened or reopened from a users list. Workflows have been added in `.github/workflows/pr-auto-assignee.yml` #### Usage -Below workflow can be used to automatically assign the assignee to a pull request (PR) when the request is opened or reopened from the specified branch. If we provide a list of users, it will randomly select one user and assign as assignee to the PR. +This workflow can be used to automatically assign assignees to a PR when it is opened or reopened. +* If a list of users is provided, one user will be randomly selected and assigned. +* You can also enable assigning the PR opener to themselves using the `assign_yourself` flag. + +| Name | Description | Required | Type | +| ----------------- | ----------------------------------------------------- | -------- | ------- | +| `assignees` | List of GitHub usernames to randomly assign to the PR | No | String | +| `assign_yourself` | Whether to assign the PR creator as an assignee | No | Boolean | + + #### Example ```yaml @@ -20,5 +29,6 @@ jobs: secrets: GITHUB: ${{ secrets.TOKEN_GITHUB }} with: - assignees: #list of usernames of assignees + assignees: user1,user2,user3 # List of usernames + assign_yourself: true # Assign PR creator as assignee ``` \ No newline at end of file