Skip to content

Commit 18e9bff

Browse files
committed
feat: use action input instead of env var to get the github token
BREAKING CHANGE: GITHUB_TOKEN env var is now ignored. In case a custom token is needed, it'll be necessary to pass it via the `token` input from now on.
1 parent a413a3f commit 18e9bff

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

.github/workflows/commitlint.yml

-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ on: [push, pull_request]
44
jobs:
55
commitlint:
66
runs-on: ubuntu-latest
7-
env:
8-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97
steps:
108
- uses: actions/checkout@v2
119
with:
@@ -19,8 +17,6 @@ jobs:
1917
run: echo ${{ toJSON(steps.run_commitlint.outputs.results) }}
2018
commitlint-with-yml-file:
2119
runs-on: ubuntu-latest
22-
env:
23-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2420
steps:
2521
- uses: actions/checkout@v2
2622
with:
@@ -32,8 +28,6 @@ jobs:
3228
configFile: './.commitlintrc.yml'
3329
commitlint-pulling-from-docker-hub:
3430
runs-on: ubuntu-latest
35-
env:
36-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3731
steps:
3832
- uses: actions/checkout@v2
3933
with:

README.md

+14-10
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ Lints Pull Request commits with commitlint
77
Create a github workflow in the `.github` folder, e.g. `.github/workflows/commitlint.yml`:
88

99
```yaml
10-
name: Commitlint
10+
name: Lint Commit Messages
1111
on: [pull_request]
1212

1313
jobs:
14-
lint:
14+
commitlint:
1515
runs-on: ubuntu-latest
16-
env:
17-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1816
steps:
1917
- uses: actions/checkout@v2
2018
with:
2119
fetch-depth: 0
22-
- uses: wagoid/commitlint-github-action@v1
20+
- uses: wagoid/commitlint-github-action@v2
2321
```
2422
2523
Alternatively, you can run on other event types such as `on: [push]`. In that case the action will lint the push event's commit(s) instead of linting commits from a pull request. You can also combine `push` and `pull_request` together in the same workflow.
@@ -54,6 +52,14 @@ Link to a page explaining your commit message convention.
5452

5553
default: `https://github.com/conventional-changelog/commitlint/#what-is-commitlint`
5654

55+
### `token`
56+
57+
Personal access token (PAT) used to interact with the GitHub API.
58+
By default, the automatic token provided by GitHub is used.
59+
You can see more info about GitHub's default token [here](https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token).
60+
61+
default: `${{ github.token }}`
62+
5763
## Outputs
5864

5965
### `results`
@@ -114,14 +120,12 @@ Apart from the shared configurations that are included by default, you can also
114120
In order to do so, you can use `NODE_PATH` env var to make the action take those dependencies into account. Below is an example workflow that does that.
115121

116122
```yaml
117-
name: Commitlint
123+
name: Lint Commit Messages
118124
on: [pull_request]
119125
120126
jobs:
121-
lint:
127+
commitlint:
122128
runs-on: ubuntu-latest
123-
env:
124-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125129
steps:
126130
- uses: actions/checkout@v2
127131
with:
@@ -134,7 +138,7 @@ jobs:
134138
# $GITHUB_WORKSPACE is the path to your repository
135139
run: echo "::set-env name=NODE_PATH::$GITHUB_WORKSPACE/node_modules"
136140
# Now the commitlint action will run considering its own dependencies and yours as well 🚀
137-
- uses: wagoid/commitlint-github-action@v1
141+
- uses: wagoid/commitlint-github-action@v2
138142
```
139143

140144
---

action.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ inputs:
77
default: './commitlint.config.js'
88
required: false
99
firstParent:
10-
description: 'When set to true, we follow only the first parent commit when seeing a merge commit. More info in git-log docs https://git-scm.com/docs/git-log#Documentation/git-log.txt---first-parent'
10+
description: >
11+
When set to true, we follow only the first parent commit when seeing a merge commit.
12+
More info in git-log docs https://git-scm.com/docs/git-log#Documentation/git-log.txt---first-parent
1113
default: 'true'
1214
required: false
1315
failOnWarnings:
@@ -18,6 +20,13 @@ inputs:
1820
description: 'Link to a page explaining your commit message convention'
1921
default: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
2022
required: false
23+
token:
24+
description: >
25+
Personal access token (PAT) used to interact with the GitHub API.
26+
By default, the automatic token provided by GitHub is used.
27+
You can see more info about GitHub's default token here: https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token
28+
default: ${{ github.token }}
29+
required: false
2130
outputs:
2231
results:
2332
description: The error and warning messages for each one of the analyzed commits

src/action.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const generateOutputs = require('./generateOutputs')
1010

1111
const pullRequestEvent = 'pull_request'
1212

13-
const { GITHUB_TOKEN, GITHUB_EVENT_NAME, GITHUB_SHA } = process.env
13+
const { GITHUB_EVENT_NAME, GITHUB_SHA } = process.env
1414

1515
const configPath = resolve(
1616
process.env.GITHUB_WORKSPACE,
@@ -47,7 +47,7 @@ const getRangeForPushEvent = () => {
4747
const getRangeForEvent = async () => {
4848
if (GITHUB_EVENT_NAME !== pullRequestEvent) return getRangeForPushEvent()
4949

50-
const octokit = new github.GitHub(GITHUB_TOKEN)
50+
const octokit = new github.GitHub(core.getInput('token'))
5151
const { owner, repo, number } = eventContext.issue
5252
const { data: commits } = await octokit.pulls.listCommits({
5353
owner,

0 commit comments

Comments
 (0)