Skip to content

Commit ada1ed5

Browse files
authored
Add committer-name and committer-email inputs (#11)
1 parent eb359a1 commit ada1ed5

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ See the `fast-glob` [documentation][glob-docs] for glob syntax.
8383
- `allow-dot`: allow glob patterns to match entries that begin with a period (`false` by default)
8484
- `allow-removing`: allow to remove file if local copy is missing
8585
(`false` by default)
86+
- `committer-name`: The name of the author (or committer) of the commit. (`github-actions[bot]` by default)
87+
- `committer-email`: The email of the author (or committer) of the commit. (`github-actions[bot]@users.noreply.github.com` by default)
8688

8789
Note that the action will produce an error if a local copy of a given file is missing, and the `allow-removing` flag is `false`.
8890

action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ inputs:
2929
desciption: Allow to remove file
3030
default: false
3131
required: false
32+
33+
committer-name:
34+
description: The name of the author (or committer) of the commit
35+
default: 'github-actions[bot]'
36+
required: false
37+
38+
committer-email:
39+
description: The email of the author (or committer) of the commit
40+
default: 'github-actions[bot]@users.noreply.github.com'
41+
required: false
42+
3243
runs:
3344
using: node12
3445
main: dist/index.js

dist/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class Updater {
9797
this.octokit = octokit_1.createOctokit(options.token);
9898
this.message = options.message;
9999
this.defaultBranch = options.branch || null;
100+
this.committerName = options.committerName;
101+
this.committerEmail = options.committerEmail;
100102
}
101103
async updateFiles(paths) {
102104
const branch = await this.getBranch();
@@ -114,7 +116,10 @@ class Updater {
114116
async createCommit(tree, parent) {
115117
const { message } = this;
116118
const { data } = await this.octokit.git.createCommit(Object.assign(Object.assign({}, github_1.context.repo), { message,
117-
tree, parents: [parent] }));
119+
tree, parents: [parent], author: {
120+
name: this.committerName,
121+
email: this.committerEmail,
122+
} }));
118123
return data.sha;
119124
}
120125
async createTree(branch, filePaths, base_tree) {
@@ -224,7 +229,9 @@ function getActionOptions() {
224229
const token = core_1.getInput('github-token', { required: true });
225230
const message = core_1.getInput('commit-msg', { required: true });
226231
const branch = core_1.getInput('branch');
227-
return { token, message, branch };
232+
const committerName = core_1.getInput('committer-name');
233+
const committerEmail = core_1.getInput('committer-email');
234+
return { token, message, branch, committerName, committerEmail };
228235
}
229236
exports.getActionOptions = getActionOptions;
230237
function isNotNull(arg) {

src/update.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ export class Updater {
3232
private octokit: InstanceType<typeof GitHub>;
3333
private message: string;
3434
private defaultBranch: string | null;
35+
private committerName: string;
36+
private committerEmail: string;
3537

3638
constructor(options: UpdaterOptions) {
3739
this.octokit = createOctokit(options.token);
3840

3941
this.message = options.message;
4042
this.defaultBranch = options.branch || null;
43+
this.committerName = options.committerName;
44+
this.committerEmail = options.committerEmail;
4145
}
4246

4347
async updateFiles(paths: string[]): Promise<UpdateResult | null> {
@@ -66,6 +70,10 @@ export class Updater {
6670
message,
6771
tree,
6872
parents: [parent],
73+
author: {
74+
name: this.committerName,
75+
email: this.committerEmail,
76+
},
6977
});
7078

7179
return data.sha;

src/util.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export interface UpdaterOptions {
55
branch: string;
66
token: string;
77
message: string;
8+
committerName: string;
9+
committerEmail: string;
810
}
911

1012
export function getBooleanInput(name: string, options?: InputOptions): boolean {
@@ -35,8 +37,10 @@ export function getActionOptions(): UpdaterOptions {
3537
const token = getInput('github-token', { required: true });
3638
const message = getInput('commit-msg', { required: true });
3739
const branch = getInput('branch');
40+
const committerName = getInput('committer-name');
41+
const committerEmail = getInput('committer-email');
3842

39-
return { token, message, branch };
43+
return { token, message, branch, committerName, committerEmail };
4044
}
4145

4246
export function isNotNull<T>(arg: T): arg is Exclude<T, null> {

0 commit comments

Comments
 (0)