Skip to content

Commit

Permalink
refactor: writeGitAuthor
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Sep 2, 2021
1 parent 9c3fd34 commit 8933fe9
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions lib/util/git/index.ts
Expand Up @@ -234,6 +234,27 @@ async function setBranchPrefix(branchPrefix: string): Promise<void> {
}
}

export async function writeGitAuthor(): Promise<void> {
const { gitAuthorName, gitAuthorEmail } = config;
try {
if (gitAuthorName) {
logger.debug({ gitAuthorName }, 'Setting git author name');
await git.addConfig('user.name', gitAuthorName);
}
if (gitAuthorEmail) {
logger.debug({ gitAuthorEmail }, 'Setting git author email');
await git.addConfig('user.email', gitAuthorEmail);
}
} catch (err) /* istanbul ignore next */ {
checkForPlatformFailure(err);
logger.debug(
{ err, gitAuthorName, gitAuthorEmail },
'Error setting git author config'
);
throw new Error(TEMPORARY_ERROR);
}
}

export async function setUserRepoConfig({
branchPrefix,
gitIgnoredAuthors,
Expand Down Expand Up @@ -344,21 +365,7 @@ export async function syncGit(): Promise<void> {
}
logger.warn({ err }, 'Cannot retrieve latest commit');
}
try {
const { gitAuthorName, gitAuthorEmail } = config;
if (gitAuthorName) {
logger.debug({ gitAuthorName }, 'Setting git author name');
await git.addConfig('user.name', gitAuthorName);
}
if (gitAuthorEmail) {
logger.debug({ gitAuthorEmail }, 'Setting git author email');
await git.addConfig('user.email', gitAuthorEmail);
}
} catch (err) /* istanbul ignore next */ {
checkForPlatformFailure(err);
logger.debug({ err }, 'Error setting git author config');
throw new Error(TEMPORARY_ERROR);
}
await writeGitAuthor();
config.currentBranch = config.currentBranch || (await getDefaultBranch(git));
if (config.branchPrefix) {
await setBranchPrefix(config.branchPrefix);
Expand Down Expand Up @@ -710,6 +717,7 @@ export async function commitFiles({
}
const { localDir } = getGlobalConfig();
await configSigningKey(localDir);
await writeGitAuthor();
try {
await git.reset(ResetMode.HARD);
await git.raw(['clean', '-fd']);
Expand Down

0 comments on commit 8933fe9

Please sign in to comment.