Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: pass git author in initRepo #6605

Merged
merged 5 commits into from Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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