Use github.actor as default value for commit author (#128)
This commit is contained in:
committed by
GitHub
parent
1146c681e3
commit
9c056146c1
@@ -58,10 +58,6 @@ Add a step like this to your workflow:
|
||||
# Arguments for the git tag command (the tag name always needs to be the first word not preceded by an hyphen)
|
||||
# Default: ''
|
||||
tag: 'v1.0.0 --force'
|
||||
|
||||
# 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)
|
||||
# Default: secrets.GITHUB_TOKEN
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
### Adding files:
|
||||
@@ -93,8 +89,7 @@ You can use the `tag` option to enter the arguments for a `git add` command. In
|
||||
|
||||
### Tokens:
|
||||
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
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.
|
||||
|
||||
### Outputs:
|
||||
|
||||
@@ -9,9 +9,11 @@ inputs:
|
||||
author_name:
|
||||
description: The name of the user that will be displayed as the author of the commit
|
||||
required: false
|
||||
default: ${{ github.actor }}
|
||||
author_email:
|
||||
description: The email of the user that will be displayed as the author of the commit
|
||||
required: false
|
||||
default: ${{ github.actor }}@users.noreply.github.com
|
||||
branch:
|
||||
description: Name of the branch to use, if different from the one that triggered the workflow
|
||||
required: false
|
||||
@@ -39,10 +41,6 @@ inputs:
|
||||
tag:
|
||||
description: Arguments for the git tag command (the tag name always needs to be the first word not preceded by a hyphen)
|
||||
required: false
|
||||
token:
|
||||
description: 'GITHUB_TOKEN or a `repo` scoped Personal Access Token (PAT)'
|
||||
required: false
|
||||
default: ${{ github.token }}
|
||||
|
||||
outputs:
|
||||
committed:
|
||||
|
||||
2
lib/index.js
generated
2
lib/index.js
generated
File diff suppressed because one or more lines are too long
13
package-lock.json
generated
13
package-lock.json
generated
@@ -314,14 +314,6 @@
|
||||
"integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==",
|
||||
"dev": true
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.21.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
|
||||
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
|
||||
"requires": {
|
||||
"follow-redirects": "^1.10.0"
|
||||
}
|
||||
},
|
||||
"balanced-match": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||
@@ -785,11 +777,6 @@
|
||||
"integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==",
|
||||
"dev": true
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.13.1",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.1.tgz",
|
||||
"integrity": "sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg=="
|
||||
},
|
||||
"fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
"homepage": "https://github.com/EndBug/add-and-commit#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"axios": "^0.21.1",
|
||||
"js-yaml": "^3.14.1",
|
||||
"simple-git": "^2.27.0"
|
||||
},
|
||||
|
||||
72
src/main.ts
72
src/main.ts
@@ -6,7 +6,6 @@ import {
|
||||
startGroup,
|
||||
endGroup
|
||||
} from '@actions/core'
|
||||
import axios from 'axios'
|
||||
import path from 'path'
|
||||
import simpleGit, { Response } from 'simple-git'
|
||||
import YAML from 'js-yaml'
|
||||
@@ -179,25 +178,10 @@ async function checkInputs() {
|
||||
const eventPath = process.env.GITHUB_EVENT_PATH,
|
||||
event = eventPath && require(eventPath),
|
||||
isPR = process.env.GITHUB_EVENT_NAME?.includes('pull_request'),
|
||||
sha = (event?.pull_request?.head?.sha || process.env.GITHUB_SHA) as string,
|
||||
defaultBranch = isPR
|
||||
? (event?.pull_request?.head?.ref as string)
|
||||
: process.env.GITHUB_REF?.substring(11)
|
||||
|
||||
// #region GITHUB_TOKEN
|
||||
let token = process.env.GITHUB_TOKEN
|
||||
if (token) {
|
||||
debug('Using token from GITHUB_TOKEN env variable.')
|
||||
warning(
|
||||
"The GITHUB_TOKEN env variable is deprecated and will not be supported in the next major release. Use the 'token' input, " +
|
||||
"which defaults to 'secrets.GITHUB_TOKEN'."
|
||||
)
|
||||
} else {
|
||||
debug('Using token from token input.')
|
||||
token = getInput('token')
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region add, remove
|
||||
if (!getInput('add') && !getInput('remove'))
|
||||
throw new Error(
|
||||
@@ -227,57 +211,11 @@ async function checkInputs() {
|
||||
// #endregion
|
||||
|
||||
// #region author_name, author_email
|
||||
if (getInput('author_name') && getInput('author_email')) {
|
||||
info('> Using author info from inputs...')
|
||||
} else {
|
||||
info('> Some author info is missing, filling from workflow event...')
|
||||
let author = event?.head_commit?.author
|
||||
|
||||
if (sha && !author) {
|
||||
info(
|
||||
'> Unable to get commit from workflow event: trying with the GitHub API...'
|
||||
)
|
||||
|
||||
// https://docs.github.com/en/rest/reference/repos#get-a-commit--code-samples
|
||||
const url = `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}`,
|
||||
headers = token
|
||||
? {
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
: undefined,
|
||||
commit = (
|
||||
await axios.get(url, { headers }).catch((err) => {
|
||||
startGroup('Request error:')
|
||||
info(`> Request URL: ${url}\b${err}`)
|
||||
endGroup()
|
||||
return undefined
|
||||
})
|
||||
)?.data
|
||||
|
||||
author = commit?.commit?.author
|
||||
}
|
||||
|
||||
if (typeof author == 'object') {
|
||||
setDefault('author_name', author.name)
|
||||
setDefault('author_email', author.email)
|
||||
}
|
||||
|
||||
if (!getInput('author_name') || !getInput('author_email')) {
|
||||
const reason = !eventPath
|
||||
? 'event path'
|
||||
: isPR
|
||||
? sha
|
||||
? 'fetch commit'
|
||||
: 'find commit sha'
|
||||
: !event?.head_commit
|
||||
? 'find commit'
|
||||
: 'find commit author'
|
||||
warning(`Unable to fetch author info: couldn't ${reason}.`)
|
||||
setDefault('author_name', 'Add & Commit Action')
|
||||
setDefault('author_email', 'actions@github.com')
|
||||
}
|
||||
}
|
||||
|
||||
setDefault('author_name', `${process.env.GITHUB_ACTOR}`)
|
||||
setDefault(
|
||||
'author_email',
|
||||
`${process.env.GITHUB_ACTOR}@users.noreply.github.com`
|
||||
)
|
||||
info(
|
||||
`> Using '${getInput('author_name')} <${getInput(
|
||||
'author_email'
|
||||
|
||||
Reference in New Issue
Block a user