Skip to content

Commit

Permalink
Add committer-name and committer-email inputs (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisfalconmx authored Nov 30, 2021
1 parent eb359a1 commit ada1ed5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ export class Updater {
private octokit: InstanceType<typeof GitHub>;
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<UpdateResult | null> {
Expand Down Expand Up @@ -66,6 +70,10 @@ export class Updater {
message,
tree,
parents: [parent],
author: {
name: this.committerName,
email: this.committerEmail,
},
});

return data.sha;
Expand Down
6 changes: 5 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<T>(arg: T): arg is Exclude<T, null> {
Expand Down

0 comments on commit ada1ed5

Please sign in to comment.