Skip to content

Commit

Permalink
fix: only set git config if does not exist (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Nov 22, 2021
1 parent 24193ae commit 0a0ed83
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/commands/cli/latestrc/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ export default class build extends SfdxCommand {

this.exec('yarn snapshot-generate');

const user = await octokit.request('GET /user');

// required for committing in Circle
this.exec(`git config user.email "${user.data.email}"`);
this.exec(`git config user.name "${user.data.name}"`);
await this.maybeSetGitConfig(octokit);

// commit package.json/yarn.lock and potentially command-snapshot changes
this.exec('git add .');
Expand All @@ -91,4 +87,14 @@ export default class build extends SfdxCommand {
this.log(bold(cmd));
exec(cmd, options);
}

private async maybeSetGitConfig(octokit: Octokit): Promise<void> {
const username = exec('git config user.name', { silent: true }).stdout.trim();
const email = exec('git config user.email', { silent: true }).stdout.trim();
if (!username || !email) {
const user = await octokit.request('GET /user');
if (!username) this.exec(`git config user.name "${user.data.name}"`);
if (!email) this.exec(`git config user.email "${user.data.email}"`);
}
}
}

0 comments on commit 0a0ed83

Please sign in to comment.