Skip to content

Commit 9c05614

Browse files
authored
Use github.actor as default value for commit author (actions#128)
1 parent 1146c68 commit 9c05614

File tree

6 files changed

+9
-92
lines changed

6 files changed

+9
-92
lines changed

README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ Add a step like this to your workflow:
5858
# Arguments for the git tag command (the tag name always needs to be the first word not preceded by an hyphen)
5959
# Default: ''
6060
tag: 'v1.0.0 --force'
61-
62-
# The token to use to access the GitHub API when getting the author info (see the paragraph below for more info about the tokens used by the action)
63-
# Default: secrets.GITHUB_TOKEN
64-
token: ${{ secrets.GITHUB_TOKEN }}
6561
```
6662
6763
### Adding files:
@@ -93,8 +89,7 @@ You can use the `tag` option to enter the arguments for a `git add` command. In
9389

9490
### Tokens:
9591

96-
The token from the `token` input is only used when getting the author info from the GitHub API: usually the default GitHub token is enough but if for some reason you want to change it, you can use that input.
97-
When pushing, the action uses the token that the local git repository has been configured with: that means that if you want to change it you'll need to do it in the steps that run before this action. For example: if you set up your repo with [`actions/checkout`](https://github.com/actions/checkout/) then you have to change the token there.
92+
When pushing, the action uses the token that the local git repository has been configured with: that means that if you want to change it you'll need to do it in the steps that run before this action. For example: if you set up your repo with [`actions/checkout`](https://github.com/actions/checkout/) then you have to add the token there.
9893
Changing the token with which the repo is configured can be useful if you want to run CI checks on the commit pushed by this action; anyway, it has to be set up outside of this action.
9994

10095
### Outputs:

action.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ inputs:
99
author_name:
1010
description: The name of the user that will be displayed as the author of the commit
1111
required: false
12+
default: ${{ github.actor }}
1213
author_email:
1314
description: The email of the user that will be displayed as the author of the commit
1415
required: false
16+
default: ${{ github.actor }}@users.noreply.github.com
1517
branch:
1618
description: Name of the branch to use, if different from the one that triggered the workflow
1719
required: false
@@ -39,10 +41,6 @@ inputs:
3941
tag:
4042
description: Arguments for the git tag command (the tag name always needs to be the first word not preceded by a hyphen)
4143
required: false
42-
token:
43-
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
44-
required: false
45-
default: ${{ github.token }}
4644

4745
outputs:
4846
committed:

lib/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"homepage": "https://github.com/EndBug/add-and-commit#readme",
3636
"dependencies": {
3737
"@actions/core": "^1.2.6",
38-
"axios": "^0.21.1",
3938
"js-yaml": "^3.14.1",
4039
"simple-git": "^2.27.0"
4140
},

src/main.ts

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
startGroup,
77
endGroup
88
} from '@actions/core'
9-
import axios from 'axios'
109
import path from 'path'
1110
import simpleGit, { Response } from 'simple-git'
1211
import YAML from 'js-yaml'
@@ -179,25 +178,10 @@ async function checkInputs() {
179178
const eventPath = process.env.GITHUB_EVENT_PATH,
180179
event = eventPath && require(eventPath),
181180
isPR = process.env.GITHUB_EVENT_NAME?.includes('pull_request'),
182-
sha = (event?.pull_request?.head?.sha || process.env.GITHUB_SHA) as string,
183181
defaultBranch = isPR
184182
? (event?.pull_request?.head?.ref as string)
185183
: process.env.GITHUB_REF?.substring(11)
186184

187-
// #region GITHUB_TOKEN
188-
let token = process.env.GITHUB_TOKEN
189-
if (token) {
190-
debug('Using token from GITHUB_TOKEN env variable.')
191-
warning(
192-
"The GITHUB_TOKEN env variable is deprecated and will not be supported in the next major release. Use the 'token' input, " +
193-
"which defaults to 'secrets.GITHUB_TOKEN'."
194-
)
195-
} else {
196-
debug('Using token from token input.')
197-
token = getInput('token')
198-
}
199-
// #endregion
200-
201185
// #region add, remove
202186
if (!getInput('add') && !getInput('remove'))
203187
throw new Error(
@@ -227,57 +211,11 @@ async function checkInputs() {
227211
// #endregion
228212

229213
// #region author_name, author_email
230-
if (getInput('author_name') && getInput('author_email')) {
231-
info('> Using author info from inputs...')
232-
} else {
233-
info('> Some author info is missing, filling from workflow event...')
234-
let author = event?.head_commit?.author
235-
236-
if (sha && !author) {
237-
info(
238-
'> Unable to get commit from workflow event: trying with the GitHub API...'
239-
)
240-
241-
// https://docs.github.com/en/rest/reference/repos#get-a-commit--code-samples
242-
const url = `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}`,
243-
headers = token
244-
? {
245-
Authorization: `Bearer ${token}`
246-
}
247-
: undefined,
248-
commit = (
249-
await axios.get(url, { headers }).catch((err) => {
250-
startGroup('Request error:')
251-
info(`> Request URL: ${url}\b${err}`)
252-
endGroup()
253-
return undefined
254-
})
255-
)?.data
256-
257-
author = commit?.commit?.author
258-
}
259-
260-
if (typeof author == 'object') {
261-
setDefault('author_name', author.name)
262-
setDefault('author_email', author.email)
263-
}
264-
265-
if (!getInput('author_name') || !getInput('author_email')) {
266-
const reason = !eventPath
267-
? 'event path'
268-
: isPR
269-
? sha
270-
? 'fetch commit'
271-
: 'find commit sha'
272-
: !event?.head_commit
273-
? 'find commit'
274-
: 'find commit author'
275-
warning(`Unable to fetch author info: couldn't ${reason}.`)
276-
setDefault('author_name', 'Add & Commit Action')
277-
setDefault('author_email', 'actions@github.com')
278-
}
279-
}
280-
214+
setDefault('author_name', `${process.env.GITHUB_ACTOR}`)
215+
setDefault(
216+
'author_email',
217+
`${process.env.GITHUB_ACTOR}@users.noreply.github.com`
218+
)
281219
info(
282220
`> Using '${getInput('author_name')} <${getInput(
283221
'author_email'

0 commit comments

Comments
 (0)