Skip to content

Commit

Permalink
Use author name and email in the commit instead of user's
Browse files Browse the repository at this point in the history
Signed-off-by: Vacha Shah <vachshah@amazon.com>
  • Loading branch information
VachaShah committed Mar 23, 2023
1 parent a82e65e commit 48f71fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
33 changes: 28 additions & 5 deletions src/backport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Buffer } from 'node:buffer';
import { group, info, error as logError, warning } from "@actions/core";
import { exec } from "@actions/exec";
import { getOctokit } from "@actions/github";
Expand Down Expand Up @@ -108,9 +109,14 @@ const backportOnce = async ({
try {
await git("cherry-pick", "-x", "-n", commitSha);
} catch (error: unknown) {
logError(
"Possibly a conflict error. Trying to skip possible conflict files. ",
);
if (error instanceof Error) {
logError(
"Possibly a conflict error. Trying to skip possible conflict files. ",
);
console.log(error.message);
} else {
console.log('Unexpected error', error);
}
}

/* eslint-disable no-await-in-loop */
Expand Down Expand Up @@ -273,14 +279,31 @@ const backport = async ({
cloneUrl.username = "x-access-token";
cloneUrl.password = token;

let authorName = "";
let authorEmail = "";

const options = {
listeners: {
stdout (data: Buffer) {
authorName += data.toString();
authorEmail += data.toString();
},
},
};

info(`Getting author name ${authorName} and email ${authorEmail}...`);

await exec("git", ["show", "-s", "--format='%an'", mergeCommitSha], options);
await exec("git", ["show", "-s", "--format='%ae'", mergeCommitSha], options);

await exec("git", ["clone", cloneUrl.toString()]);
await exec("git", [
"config",
"--global",
"user.email",
authorEmail,
"github-actions[bot]@users.noreply.github.com",
]);
await exec("git", ["config", "--global", "user.name", "github-actions[bot]"]);
await exec("git", ["config", "--global", authorName, "github-actions[bot]"]);

const createdPullRequestBaseBranchToNumber: { [base: string]: number } = {};

Expand Down
1 change: 0 additions & 1 deletion xo.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ module.exports = {
"newlines-between": "never",
},
],
"no-console": "error",
"object-shorthand": [
"error",
"always",
Expand Down

0 comments on commit 48f71fb

Please sign in to comment.