Skip to content

Commit 83f4976

Browse files
authored
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
1 parent d5067cc commit 83f4976

File tree

6 files changed

+78
-16
lines changed

6 files changed

+78
-16
lines changed

README.md

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,33 @@ This action lets you choose the path that you want to use when adding & committi
1313
Add a step like this to your workflow:
1414

1515
```yaml
16-
- uses: EndBug/add-and-commit@v7 # You can change this to use a specific version
16+
- uses: EndBug/add-and-commit@v7 # You can change this to use a specific version.
1717
with:
1818
# The arguments for the `git add` command (see the paragraph below for more info)
1919
# Default: '.'
2020
add: 'src'
2121

22-
# The name of the user that will be displayed as the author of the commit
22+
# The name of the user that will be displayed as the author of the commit.
2323
# Default: depends on the default_author input
24-
author_name: Your Name
24+
author_name: Author Name
2525

26-
# The email of the user that will be displayed as the author of the commit
26+
# The email of the user that will be displayed as the author of the commit.
2727
# Default: depends on the default_author input
2828
author_email: [email protected]
2929

30-
# Name of the branch to use, if different from the one that triggered the workflow
30+
# The name of the branch to use, if different from the one that triggered the workflow.
3131
# Default: the branch that triggered the run
3232
branch: some-branch
3333

34-
# The local path to the directory where your repository is located. You should use actions/checkout first to set it up
34+
# The name of the custom committer you want to use, if different from the author of the commit.
35+
# Default: the name of the author (set with either author_name or default_author)
36+
committer_name: Committer Name
37+
38+
# The email of the custom committer you want to use, if different from the author of the commit.
39+
# Default: the email of the author (set with either author_email or default_author)
40+
committer_email: [email protected]
41+
42+
# The local path to the directory where your repository is located. You should use actions/checkout first to set it up.
3543
# Default: '.'
3644
cwd: './path/to/the/repo'
3745

@@ -42,7 +50,7 @@ Add a step like this to your workflow:
4250
# Default: github_actor
4351
default_author: github_actor
4452

45-
# The message for the commit
53+
# The message for the commit.
4654
# Default: 'Commit from GitHub Actions (name of the workflow)'
4755
message: 'Your commit message'
4856

@@ -144,6 +152,30 @@ jobs:
144152
default_author: github_actions
145153
```
146154

155+
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:
156+
157+
<img src="https://user-images.githubusercontent.com/26386270/130594168-1d910710-e2d0-4b06-9324-cbe5dde59154.png" height=70/>
158+
159+
```yaml
160+
- uses: EndBug/add-and-commit@v7
161+
with:
162+
message: Show GitHub Actions logo
163+
committer_name: GitHub Actions
164+
committer_email: [email protected]
165+
```
166+
167+
168+
<img src="https://user-images.githubusercontent.com/26386270/130594443-b881fae7-3064-4020-a4cc-6db37ef0df65.png" height=70/>
169+
170+
```yaml
171+
- uses: EndBug/add-and-commit@v7
172+
with:
173+
message: Show GitHub logo
174+
committer_name: GitHub Actions
175+
committer_email: 41898282+github-actions[bot]@users.noreply.github.com
176+
```
177+
178+
147179
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:
148180

149181
```yaml
@@ -206,6 +238,8 @@ jobs:
206238
cwd: './pathToRepo/'
207239
```
208240

241+
242+
209243
## Contributors ✨
210244

211245
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ inputs:
1515
branch:
1616
description: Name of the branch to use, if different from the one that triggered the workflow
1717
required: false
18+
committer_name:
19+
description: The name of the custom committer you want to use
20+
required: false
21+
committer_email:
22+
description: The email of the custom committer you want to use
23+
required: false
1824
cwd:
1925
description: The directory where your repository is located. You should use actions/checkout first to set it up
2026
required: false

lib/index.js

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

package-lock.json

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

src/main.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ core.info(`Running in ${baseDir}`)
4040
await git
4141
.addConfig('user.email', getInput('author_email'), undefined, log)
4242
.addConfig('user.name', getInput('author_name'), undefined, log)
43+
.addConfig('author.email', getInput('author_email'), undefined, log)
44+
.addConfig('author.name', getInput('author_name'), undefined, log)
45+
.addConfig('committer.email', getInput('committer_email'), undefined, log)
46+
.addConfig('committer.name', getInput('committer_name'), undefined, log)
4347
core.debug(
4448
'> Current git config\n' +
4549
JSON.stringify((await git.listConfig()).all, null, 2)
@@ -75,9 +79,6 @@ core.info(`Running in ${baseDir}`)
7579
getInput('message'),
7680
undefined,
7781
{
78-
'--author': `"${getInput('author_name')} <${getInput(
79-
'author_email'
80-
)}>"`,
8182
...(getInput('signoff')
8283
? {
8384
'--signoff': null
@@ -238,6 +239,7 @@ async function checkInputs() {
238239
', '
239240
)}`
240241
)
242+
// #endregion
241243

242244
// #region author_name, author_email
243245
let name, email
@@ -289,6 +291,25 @@ async function checkInputs() {
289291
)
290292
// #endregion
291293

294+
// #region committer_name, committer_email
295+
if (getInput('committer_name') || getInput('committer_email'))
296+
core.info(
297+
`> Using custom committer info: ${
298+
getInput('committer_name') ||
299+
getInput('author_name') + ' [from author info]'
300+
} <${
301+
getInput('committer_email') ||
302+
getInput('author_email') + ' [from author info]'
303+
}>`
304+
)
305+
306+
setDefault('committer_name', getInput('author_name'))
307+
setDefault('committer_email', getInput('author_email'))
308+
core.debug(
309+
`Committer: ${getInput('committer_name')} <${getInput('committer_email')}>`
310+
)
311+
// #endregion
312+
292313
// #region message
293314
setDefault(
294315
'message',
@@ -349,6 +370,7 @@ async function checkInputs() {
349370
core.warning(
350371
'No github_token has been detected, the action may fail if it needs to use the API'
351372
)
373+
// #endregion
352374
}
353375

354376
async function add({ logWarning = true, ignoreErrors = false } = {}): Promise<

src/util.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export type Input =
88
| 'author_name'
99
| 'author_email'
1010
| 'branch'
11+
| 'committer_name'
12+
| 'committer_email'
1113
| 'cwd'
1214
| 'default_author'
1315
| 'message'

0 commit comments

Comments
 (0)