Skip to content

Commit

Permalink
feat: set token default (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-evans authored Dec 8, 2022
1 parent b3d5f7f commit 60812ab
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ A GitHub action to [enable auto-merge](https://docs.github.com/en/github/collabo
| Name | Description | Default |
| --- | --- | --- |
| `token` | (**required**) A `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token). Note: `GITHUB_TOKEN` *does not* work here. | |
| `token` | `GITHUB_TOKEN` (permissions `pull_requests: write`, `contents: write`) or a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token). | `GITHUB_TOKEN` |
| `repository` | The target GitHub repository containing the pull request. | `github.repository` (Current repository) |
| `pull-request-number` | (**required**) The number of the target pull request | |
| `merge-method` | The merge method to use. `merge`, `rebase` or `squash`. | `merge` |
Expand All @@ -32,7 +32,32 @@ This action uses a GitHub API that only works under specific conditions. All of
2. The pull request `base` must have a branch protection rule with at least one requirement enabled.
3. The pull request must be in a state where requirements have not yet been satisfied. If the pull request can already be merged, attempting to enable auto-merge will fail.

### Example
### Dependabot example

The following example will automerge dependabot pull requests.
Note that if you use the default `GITHUB_TOKEN`, as in the example, the merge will not trigger further workflow runs.
If you want to trigger further workflow runs, you will need to use a `repo` scoped [Personal Access Token (PAT)](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token).

```yml
name: Auto-merge Dependabot
on: pull_request
permissions:
pull-requests: write
contents: write
jobs:
automerge:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- uses: peter-evans/enable-pull-request-automerge@v2
with:
pull-request-number: ${{ github.event.pull_request.number }}
merge-method: squash
```

### Create pull request example

In the following example [create-pull-request](https://github.com/peter-evans/create-pull-request) action is used to create a pull request containing some changes that we want to merge automatically once requirements have been satisfied.

Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: 'Enable Pull Request Automerge'
description: 'A GitHub action to enable auto-merge on a pull request'
inputs:
token:
description: 'A repo scoped GitHub Personal Access Token (PAT).'
required: true
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
default: ${{ github.token }}
repository:
description: 'The target GitHub repository containing the pull request'
default: ${{ github.repository }}
Expand Down

0 comments on commit 60812ab

Please sign in to comment.