Custom committer support (#264)
* feat: add support for a custom committer * chore: update build * chore: remove redundant code The author is correctly set by the git config (line 40) * docs: add new feature docs * docs(README): add example use of committer info Closes #265
This commit is contained in:
48
README.md
48
README.md
@@ -13,25 +13,33 @@ This action lets you choose the path that you want to use when adding & committi
|
||||
Add a step like this to your workflow:
|
||||
|
||||
```yaml
|
||||
- uses: EndBug/add-and-commit@v7 # You can change this to use a specific version
|
||||
- uses: EndBug/add-and-commit@v7 # You can change this to use a specific version.
|
||||
with:
|
||||
# The arguments for the `git add` command (see the paragraph below for more info)
|
||||
# Default: '.'
|
||||
add: 'src'
|
||||
|
||||
# The name of the user that will be displayed as the author of the commit
|
||||
# The name of the user that will be displayed as the author of the commit.
|
||||
# Default: depends on the default_author input
|
||||
author_name: Your Name
|
||||
author_name: Author Name
|
||||
|
||||
# The email of the user that will be displayed as the author of the commit
|
||||
# The email of the user that will be displayed as the author of the commit.
|
||||
# Default: depends on the default_author input
|
||||
author_email: mail@example.com
|
||||
|
||||
# Name of the branch to use, if different from the one that triggered the workflow
|
||||
# The name of the branch to use, if different from the one that triggered the workflow.
|
||||
# Default: the branch that triggered the run
|
||||
branch: some-branch
|
||||
|
||||
# The local path to the directory where your repository is located. You should use actions/checkout first to set it up
|
||||
# The name of the custom committer you want to use, if different from the author of the commit.
|
||||
# Default: the name of the author (set with either author_name or default_author)
|
||||
committer_name: Committer Name
|
||||
|
||||
# The email of the custom committer you want to use, if different from the author of the commit.
|
||||
# Default: the email of the author (set with either author_email or default_author)
|
||||
committer_email: mail@example.com
|
||||
|
||||
# The local path to the directory where your repository is located. You should use actions/checkout first to set it up.
|
||||
# Default: '.'
|
||||
cwd: './path/to/the/repo'
|
||||
|
||||
@@ -42,7 +50,7 @@ Add a step like this to your workflow:
|
||||
# Default: github_actor
|
||||
default_author: github_actor
|
||||
|
||||
# The message for the commit
|
||||
# The message for the commit.
|
||||
# Default: 'Commit from GitHub Actions (name of the workflow)'
|
||||
message: 'Your commit message'
|
||||
|
||||
@@ -144,6 +152,30 @@ jobs:
|
||||
default_author: github_actions
|
||||
```
|
||||
|
||||
You can also use the `committer_name` and `committer_email` inputs to make it appear as if GitHub Actions is the committer, here are a couple of example steps:
|
||||
|
||||
<img src="https://user-images.githubusercontent.com/26386270/130594168-1d910710-e2d0-4b06-9324-cbe5dde59154.png" height=70/>
|
||||
|
||||
```yaml
|
||||
- uses: EndBug/add-and-commit@v7
|
||||
with:
|
||||
message: Show GitHub Actions logo
|
||||
committer_name: GitHub Actions
|
||||
committer_email: actions@github.com
|
||||
```
|
||||
|
||||
|
||||
<img src="https://user-images.githubusercontent.com/26386270/130594443-b881fae7-3064-4020-a4cc-6db37ef0df65.png" height=70/>
|
||||
|
||||
```yaml
|
||||
- uses: EndBug/add-and-commit@v7
|
||||
with:
|
||||
message: Show GitHub logo
|
||||
committer_name: GitHub Actions
|
||||
committer_email: 41898282+github-actions[bot]@users.noreply.github.com
|
||||
```
|
||||
|
||||
|
||||
Do you want to lint your JavaScript files, located in the `src` folder, with ESLint, so that fixable changes are done without your intervention? You can use a workflow like this:
|
||||
|
||||
```yaml
|
||||
@@ -206,6 +238,8 @@ jobs:
|
||||
cwd: './pathToRepo/'
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Contributors ✨
|
||||
|
||||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
||||
|
||||
@@ -15,6 +15,12 @@ inputs:
|
||||
branch:
|
||||
description: Name of the branch to use, if different from the one that triggered the workflow
|
||||
required: false
|
||||
committer_name:
|
||||
description: The name of the custom committer you want to use
|
||||
required: false
|
||||
committer_email:
|
||||
description: The email of the custom committer you want to use
|
||||
required: false
|
||||
cwd:
|
||||
description: The directory where your repository is located. You should use actions/checkout first to set it up
|
||||
required: false
|
||||
|
||||
6
lib/index.js
generated
6
lib/index.js
generated
File diff suppressed because one or more lines are too long
4
package-lock.json
generated
4
package-lock.json
generated
@@ -748,7 +748,6 @@
|
||||
"node_modules/actions-toolkit": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "git+ssh://git@github.com/EndBug/actions-toolkit.git#50bcf238178fb66d1448ae29b741641406e5a1a0",
|
||||
"integrity": "sha512-551oLndgEeSLzp15qjwjKBUS5gPhggPhI6kMQKDEHju7Bgp1NL8l8S7I9gQtYXe8frgp75kYZPWM+NA79E/s5g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
@@ -3944,8 +3943,7 @@
|
||||
},
|
||||
"actions-toolkit": {
|
||||
"version": "git+ssh://git@github.com/EndBug/actions-toolkit.git#50bcf238178fb66d1448ae29b741641406e5a1a0",
|
||||
"integrity": "sha512-551oLndgEeSLzp15qjwjKBUS5gPhggPhI6kMQKDEHju7Bgp1NL8l8S7I9gQtYXe8frgp75kYZPWM+NA79E/s5g==",
|
||||
"from": "actions-toolkit@github:EndBug/actions-toolkit#50bcf238178fb66d1448ae29b741641406e5a1a0",
|
||||
"from": "actions-toolkit@github:EndBug/actions-toolkit#core-actions",
|
||||
"requires": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "^1.0.4",
|
||||
|
||||
28
src/main.ts
28
src/main.ts
@@ -40,6 +40,10 @@ core.info(`Running in ${baseDir}`)
|
||||
await git
|
||||
.addConfig('user.email', getInput('author_email'), undefined, log)
|
||||
.addConfig('user.name', getInput('author_name'), undefined, log)
|
||||
.addConfig('author.email', getInput('author_email'), undefined, log)
|
||||
.addConfig('author.name', getInput('author_name'), undefined, log)
|
||||
.addConfig('committer.email', getInput('committer_email'), undefined, log)
|
||||
.addConfig('committer.name', getInput('committer_name'), undefined, log)
|
||||
core.debug(
|
||||
'> Current git config\n' +
|
||||
JSON.stringify((await git.listConfig()).all, null, 2)
|
||||
@@ -75,9 +79,6 @@ core.info(`Running in ${baseDir}`)
|
||||
getInput('message'),
|
||||
undefined,
|
||||
{
|
||||
'--author': `"${getInput('author_name')} <${getInput(
|
||||
'author_email'
|
||||
)}>"`,
|
||||
...(getInput('signoff')
|
||||
? {
|
||||
'--signoff': null
|
||||
@@ -238,6 +239,7 @@ async function checkInputs() {
|
||||
', '
|
||||
)}`
|
||||
)
|
||||
// #endregion
|
||||
|
||||
// #region author_name, author_email
|
||||
let name, email
|
||||
@@ -289,6 +291,25 @@ async function checkInputs() {
|
||||
)
|
||||
// #endregion
|
||||
|
||||
// #region committer_name, committer_email
|
||||
if (getInput('committer_name') || getInput('committer_email'))
|
||||
core.info(
|
||||
`> Using custom committer info: ${
|
||||
getInput('committer_name') ||
|
||||
getInput('author_name') + ' [from author info]'
|
||||
} <${
|
||||
getInput('committer_email') ||
|
||||
getInput('author_email') + ' [from author info]'
|
||||
}>`
|
||||
)
|
||||
|
||||
setDefault('committer_name', getInput('author_name'))
|
||||
setDefault('committer_email', getInput('author_email'))
|
||||
core.debug(
|
||||
`Committer: ${getInput('committer_name')} <${getInput('committer_email')}>`
|
||||
)
|
||||
// #endregion
|
||||
|
||||
// #region message
|
||||
setDefault(
|
||||
'message',
|
||||
@@ -349,6 +370,7 @@ async function checkInputs() {
|
||||
core.warning(
|
||||
'No github_token has been detected, the action may fail if it needs to use the API'
|
||||
)
|
||||
// #endregion
|
||||
}
|
||||
|
||||
async function add({ logWarning = true, ignoreErrors = false } = {}): Promise<
|
||||
|
||||
@@ -8,6 +8,8 @@ export type Input =
|
||||
| 'author_name'
|
||||
| 'author_email'
|
||||
| 'branch'
|
||||
| 'committer_name'
|
||||
| 'committer_email'
|
||||
| 'cwd'
|
||||
| 'default_author'
|
||||
| 'message'
|
||||
|
||||
Reference in New Issue
Block a user