Skip to content

Commit

Permalink
refactor: reduce platform defaultBranch storage (#6833)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jul 23, 2020
1 parent f37697e commit 04949af
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
9 changes: 4 additions & 5 deletions lib/platform/azure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { AzurePr } from './types';
interface Config {
repoForceRebase: boolean;
mergeMethod: GitPullRequestMergeStrategy;
defaultBranch: string;
owner: string;
repoId: string;
project: string;
Expand Down Expand Up @@ -116,8 +115,8 @@ export async function initRepo({
config.owner = '?owner?';
logger.debug(`${repository} owner = ${config.owner}`);
// Use default branch as PR target unless later overridden
config.defaultBranch = repo.defaultBranch.replace('refs/heads/', '');
logger.debug(`${repository} default branch = ${config.defaultBranch}`);
const defaultBranch = repo.defaultBranch.replace('refs/heads/', '');
logger.debug(`${repository} default branch = ${defaultBranch}`);
config.mergeMethod = await azureHelper.getMergeMethod(repo.id, names.project);
config.repoForceRebase = false;

Expand All @@ -131,7 +130,7 @@ export async function initRepo({
const json = await azureHelper.getFile(
repo.id,
'renovate.json',
config.defaultBranch
defaultBranch
);
renovateConfig = JSON.parse(json);
} catch {
Expand Down Expand Up @@ -159,7 +158,7 @@ export async function initRepo({
gitAuthorEmail: global.gitAuthor?.email,
});
const repoConfig: RepoConfig = {
defaultBranch: config.defaultBranch,
defaultBranch,
isFork: false,
};
return repoConfig;
Expand Down
4 changes: 2 additions & 2 deletions lib/platform/bitbucket-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ export async function initRepo({
).body;
config.owner = info.project.key;
logger.debug(`${repository} owner = ${config.owner}`);
config.defaultBranch = (
const defaultBranch = (
await bitbucketServerHttp.getJson<{ displayId: string }>(
`./rest/api/1.0/projects/${config.projectKey}/repos/${config.repositorySlug}/branches/default`
)
).body.displayId;
config.mergeMethod = 'merge';
const repoConfig: RepoConfig = {
defaultBranch: config.defaultBranch,
defaultBranch,
isFork: !!info.parent,
};
return repoConfig;
Expand Down
1 change: 0 additions & 1 deletion lib/platform/bitbucket-server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Pr } from '../common';

export interface BbsConfig {
bbUseDefaultReviewers: boolean;
defaultBranch: string;
fileList: any[];
mergeMethod: string;
owner: string;
Expand Down
3 changes: 1 addition & 2 deletions lib/platform/bitbucket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export async function initRepo({

Object.assign(config, {
owner: info.owner,
defaultBranch: info.mainbranch,
mergeMethod: info.mergeMethod,
has_issues: info.has_issues,
});
Expand Down Expand Up @@ -161,7 +160,7 @@ export async function initRepo({
gitAuthorEmail: global.gitAuthor?.email,
});
const repoConfig: RepoConfig = {
defaultBranch: config.defaultBranch,
defaultBranch: info.mainbranch,
isFork: info.isFork,
};
return repoConfig;
Expand Down
9 changes: 4 additions & 5 deletions lib/platform/gitea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type GiteaRenovateConfig = {
interface GiteaRepoConfig {
repository: string;
localDir: string;
defaultBranch: string;
mergeMethod: helper.PRMergeMethod;

prList: Promise<Pr[]> | null;
Expand Down Expand Up @@ -278,15 +277,15 @@ const platform: Platform = {
}

// Determine author email and branches
config.defaultBranch = repo.default_branch;
logger.debug(`${repository} default branch = ${config.defaultBranch}`);
const defaultBranch = repo.default_branch;
logger.debug(`${repository} default branch = ${defaultBranch}`);

// Optionally check if Renovate is disabled by attempting to fetch default configuration file
if (optimizeForDisabled) {
try {
renovateConfig = await retrieveDefaultConfig(
config.repository,
config.defaultBranch
defaultBranch
);
} catch (err) {
// Do nothing
Expand Down Expand Up @@ -319,7 +318,7 @@ const platform: Platform = {
config.labelList = null;

return {
defaultBranch: config.defaultBranch,
defaultBranch,
isFork: !!repo.fork,
};
},
Expand Down
8 changes: 4 additions & 4 deletions lib/platform/gitlab/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const defaultConfigFile = configFileNames[0];
let config: {
repository: string;
localDir: string;
defaultBranch: string;
email: string;
prList: any[];
issueList: any[];
Expand Down Expand Up @@ -147,6 +146,7 @@ export async function initRepo({
config.localDir = localDir;

let res: HttpResponse<RepoResponse>;
let defaultBranch: string;
try {
res = await gitlabApi.getJson<RepoResponse>(
`projects/${config.repository}`
Expand Down Expand Up @@ -198,9 +198,9 @@ export async function initRepo({
throw new Error(REPOSITORY_DISABLED);
}
}
config.defaultBranch = res.body.default_branch;
defaultBranch = res.body.default_branch;
config.mergeMethod = res.body.merge_method || 'merge';
logger.debug(`${repository} default branch = ${config.defaultBranch}`);
logger.debug(`${repository} default branch = ${defaultBranch}`);
delete config.prList;
logger.debug('Enabling Git FS');
const opts = hostRules.find({
Expand Down Expand Up @@ -253,7 +253,7 @@ export async function initRepo({
throw err;
}
const repoConfig: RepoConfig = {
defaultBranch: config.defaultBranch,
defaultBranch,
isFork: !!res.body.forked_from_project,
};
return repoConfig;
Expand Down

0 comments on commit 04949af

Please sign in to comment.