Skip to content

Commit

Permalink
refactor: pass git author in initRepo (#6605)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jun 27, 2020
1 parent 41c7c61 commit dd636ed
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 13 deletions.
2 changes: 2 additions & 0 deletions lib/platform/azure/index.ts
Expand Up @@ -169,6 +169,8 @@ export async function initRepo({
localDir,
url,
extraCloneOpts: azureHelper.getStorageExtraCloneOpts(opts),
gitAuthorName: global.gitAuthor?.name,
gitAuthorEmail: global.gitAuthor?.email,
});
const repoConfig: RepoConfig = {
baseBranch: config.baseBranch,
Expand Down
2 changes: 2 additions & 0 deletions lib/platform/bitbucket-server/index.ts
Expand Up @@ -191,6 +191,8 @@ export async function initRepo({
...config,
localDir,
url: gitUrl,
gitAuthorName: global.gitAuthor?.name,
gitAuthorEmail: global.gitAuthor?.email,
});

try {
Expand Down
2 changes: 2 additions & 0 deletions lib/platform/bitbucket/index.ts
Expand Up @@ -160,6 +160,8 @@ export async function initRepo({
...config,
localDir,
url,
gitAuthorName: global.gitAuthor?.name,
gitAuthorEmail: global.gitAuthor?.email,
});
const repoConfig: RepoConfig = {
baseBranch: config.baseBranch,
Expand Down
6 changes: 2 additions & 4 deletions lib/platform/git/storage.spec.ts
Expand Up @@ -47,16 +47,14 @@ describe('platform/git/storage', () => {
const repo = Git(origin.path);
await repo.clone(base.path, '.', ['--bare']);
tmpDir = await tmp.dir({ unsafeCleanup: true });
global.gitAuthor = {
name: 'test',
email: 'test@example.com',
};
await git.initRepo({
localDir: tmpDir.path,
url: origin.path,
extraCloneOpts: {
'--config': 'extra.clone.config=test-extra-config-value',
},
gitAuthorName: 'test',
gitAuthorEmail: 'test@example.com',
});
});

Expand Down
24 changes: 15 additions & 9 deletions lib/platform/git/storage.ts
Expand Up @@ -28,6 +28,8 @@ interface StorageConfig {
baseBranch?: string;
url: string;
extraCloneOpts?: Git.Options;
gitAuthorName?: string;
gitAuthorEmail?: string;
}

interface LocalConfig extends StorageConfig {
Expand Down Expand Up @@ -200,16 +202,20 @@ export class Storage {
}
logger.warn({ err }, 'Cannot retrieve latest commit date');
}
if (global.gitAuthor) {
logger.debug({ gitAuthor: global.gitAuthor }, 'Setting git author');
try {
await this._git.raw(['config', 'user.name', global.gitAuthor.name]);
await this._git.raw(['config', 'user.email', global.gitAuthor.email]);
} catch (err) /* istanbul ignore next */ {
checkForPlatformFailure(err);
logger.debug({ err }, 'Error setting git config');
throw new Error(REPOSITORY_TEMPORARY_ERROR);
try {
const { gitAuthorName, gitAuthorEmail } = args;
if (gitAuthorName) {
logger.debug({ gitAuthorName }, 'Setting git author name');
await this._git.raw(['config', 'user.name', gitAuthorName]);
}
if (gitAuthorEmail) {
logger.debug({ gitAuthorEmail }, 'Setting git author email');
await this._git.raw(['config', 'user.email', gitAuthorEmail]);
}
} catch (err) /* istanbul ignore next */ {
checkForPlatformFailure(err);
logger.debug({ err }, 'Error setting git author config');
throw new Error(REPOSITORY_TEMPORARY_ERROR);
}

await setBaseBranchToDefault(this._git);
Expand Down
2 changes: 2 additions & 0 deletions lib/platform/gitea/index.ts
Expand Up @@ -338,6 +338,8 @@ const platform: Platform = {
await config.storage.initRepo({
...config,
url: URL.format(gitEndpoint),
gitAuthorName: global.gitAuthor?.name,
gitAuthorEmail: global.gitAuthor?.email,
});

// Reset cached resources
Expand Down
2 changes: 2 additions & 0 deletions lib/platform/github/index.ts
Expand Up @@ -436,6 +436,8 @@ export async function initRepo({
await config.storage.initRepo({
...config,
url,
gitAuthorName: global.gitAuthor?.name,
gitAuthorEmail: global.gitAuthor?.email,
});
const repoConfig: RepoConfig = {
baseBranch: config.baseBranch,
Expand Down
2 changes: 2 additions & 0 deletions lib/platform/gitlab/index.ts
Expand Up @@ -249,6 +249,8 @@ export async function initRepo({
await config.storage.initRepo({
...config,
url,
gitAuthorName: global.gitAuthor?.name,
gitAuthorEmail: global.gitAuthor?.email,
});
} catch (err) /* istanbul ignore next */ {
logger.debug({ err }, 'Caught initRepo error');
Expand Down

0 comments on commit dd636ed

Please sign in to comment.