Skip to content

Commit cc8a21e

Browse files
authored
Merge pull request #2 from fastify/feat/exclude
feat: allow excluding packages
2 parents 5a171a7 + 773c8c3 commit cc8a21e

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ This action automatically merges dependabot PRs.
88

99
**Required** A github token.
1010

11+
### `exclude`
12+
13+
*Optional* An array of packages that you don't want to auto-merge and would like to manually review to decide whether to upgrade or not.
14+
1115
## Example usage
1216

1317
```yml
@@ -30,4 +34,20 @@ jobs:
3034
github-token: ${{secrets.github_token}}
3135
```
3236
33-
Note: The `github_token` is automatically provided by Github Actions, which we access using `secrets.github_token` and supply to the action as an input `github-token`
37+
**Note**
38+
39+
- The `github_token` is automatically provided by Github Actions, which we access using `secrets.github_token` and supply to the action as an input `github-token`.
40+
- Make sure to use `needs: <jobs>` to delay the auto-merging until CI checks (test/build) are passed.
41+
42+
## With `exclude`
43+
44+
```yml
45+
...
46+
steps:
47+
- uses: fastify/github-action-merge-dependabot@v1
48+
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
49+
with:
50+
github-token: ${{secrets.github_token}}
51+
exclude: ['material-ui']
52+
...
53+
```

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ inputs:
44
github-token:
55
description: "A GitHub token."
66
required: true
7+
exclude:
8+
description: "Packages that you want to manually review before upgrading"
9+
required: false
10+
default: []
711
runs:
812
using: "node12"
913
main: "index.js"

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const core = require('@actions/core')
22
const github = require('@actions/github')
33

44
const GITHUB_TOKEN = core.getInput('github-token', { required: true })
5+
const EXCLUDE_PKGS = core.getInput('exclude') || []
56

67
const getMergeMethod = (repo) => {
78
if (repo.allow_merge_commit) return 'merge'
@@ -21,7 +22,14 @@ async function run () {
2122
const isDependabotPR = pr.user.login === 'dependabot[bot]'
2223

2324
if (!isDependabotPR) {
24-
return console.log('Unable to merge')
25+
return core.info('Not dependabot PR, skip merging.')
26+
}
27+
28+
// dependabot branch names are in format "dependabot/npm_and_yarn/pkg-0.0.1"
29+
const pkgName = pr.head.ref.split('/').pop().split('-').shift()
30+
31+
if (EXCLUDE_PKGS.includes(pkgName)) {
32+
return core.info(`${pkgName} is excluded, skip merging.`)
2533
}
2634

2735
await octokit.pulls.createReview({

0 commit comments

Comments
 (0)