diff --git a/README.md b/README.md index 2f11a25..426cb12 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ See the `fast-glob` [documentation][glob-docs] for glob syntax. - `allow-dot`: allow glob patterns to match entries that begin with a period (`false` by default) - `allow-removing`: allow to remove file if local copy is missing (`false` by default) +- `committer-name`: The name of the author (or committer) of the commit. (`github-actions[bot]` by default) +- `committer-email`: The email of the author (or committer) of the commit. (`github-actions[bot]@users.noreply.github.com` by default) 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`. diff --git a/action.yml b/action.yml index 006c07f..7665fc2 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,17 @@ inputs: desciption: Allow to remove file default: false required: false + + committer-name: + description: The name of the author (or committer) of the commit + default: 'github-actions[bot]' + required: false + + committer-email: + description: The email of the author (or committer) of the commit + default: 'github-actions[bot]@users.noreply.github.com' + required: false + runs: using: node12 main: dist/index.js diff --git a/dist/index.js b/dist/index.js index 27f57b2..962e0d4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -97,6 +97,8 @@ class Updater { this.octokit = octokit_1.createOctokit(options.token); this.message = options.message; this.defaultBranch = options.branch || null; + this.committerName = options.committerName; + this.committerEmail = options.committerEmail; } async updateFiles(paths) { const branch = await this.getBranch(); @@ -114,7 +116,10 @@ class Updater { async createCommit(tree, parent) { const { message } = this; const { data } = await this.octokit.git.createCommit(Object.assign(Object.assign({}, github_1.context.repo), { message, - tree, parents: [parent] })); + tree, parents: [parent], author: { + name: this.committerName, + email: this.committerEmail, + } })); return data.sha; } async createTree(branch, filePaths, base_tree) { @@ -224,7 +229,9 @@ function getActionOptions() { const token = core_1.getInput('github-token', { required: true }); const message = core_1.getInput('commit-msg', { required: true }); const branch = core_1.getInput('branch'); - return { token, message, branch }; + const committerName = core_1.getInput('committer-name'); + const committerEmail = core_1.getInput('committer-email'); + return { token, message, branch, committerName, committerEmail }; } exports.getActionOptions = getActionOptions; function isNotNull(arg) { diff --git a/src/update.ts b/src/update.ts index c51d096..869c2ab 100644 --- a/src/update.ts +++ b/src/update.ts @@ -32,12 +32,16 @@ export class Updater { private octokit: InstanceType; private message: string; private defaultBranch: string | null; + private committerName: string; + private committerEmail: string; constructor(options: UpdaterOptions) { this.octokit = createOctokit(options.token); this.message = options.message; this.defaultBranch = options.branch || null; + this.committerName = options.committerName; + this.committerEmail = options.committerEmail; } async updateFiles(paths: string[]): Promise { @@ -66,6 +70,10 @@ export class Updater { message, tree, parents: [parent], + author: { + name: this.committerName, + email: this.committerEmail, + }, }); return data.sha; diff --git a/src/util.ts b/src/util.ts index a55ac71..aa54e32 100644 --- a/src/util.ts +++ b/src/util.ts @@ -5,6 +5,8 @@ export interface UpdaterOptions { branch: string; token: string; message: string; + committerName: string; + committerEmail: string; } export function getBooleanInput(name: string, options?: InputOptions): boolean { @@ -35,8 +37,10 @@ export function getActionOptions(): UpdaterOptions { const token = getInput('github-token', { required: true }); const message = getInput('commit-msg', { required: true }); const branch = getInput('branch'); + const committerName = getInput('committer-name'); + const committerEmail = getInput('committer-email'); - return { token, message, branch }; + return { token, message, branch, committerName, committerEmail }; } export function isNotNull(arg: T): arg is Exclude {