From 48f71fb98aee3caafb3d3e6b2f8c194dd05a55e6 Mon Sep 17 00:00:00 2001 From: Vacha Shah Date: Tue, 21 Mar 2023 07:29:37 +0000 Subject: [PATCH] Use author name and email in the commit instead of user's Signed-off-by: Vacha Shah --- src/backport.ts | 33 ++++++++++++++++++++++++++++----- xo.config.cjs | 1 - 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/backport.ts b/src/backport.ts index 6283d5a..cc15c05 100644 --- a/src/backport.ts +++ b/src/backport.ts @@ -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"; @@ -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 */ @@ -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 } = {}; diff --git a/xo.config.cjs b/xo.config.cjs index 0995500..c1d60d4 100644 --- a/xo.config.cjs +++ b/xo.config.cjs @@ -48,7 +48,6 @@ module.exports = { "newlines-between": "never", }, ], - "no-console": "error", "object-shorthand": [ "error", "always",