Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refactor: remove commitFiles from platforms (#6701)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
rarkins and viceice committed Jul 8, 2020
1 parent 9d7cb7d commit 4665dbf
Show file tree
Hide file tree
Showing 29 changed files with 62 additions and 479 deletions.
2 changes: 1 addition & 1 deletion lib/manager/common.ts
@@ -1,7 +1,7 @@
import { ReleaseType } from 'semver';
import { GlobalConfig, UpdateType, ValidationMessage } from '../config/common';
import { File } from '../platform/common';
import { RangeStrategy, SkipReason } from '../types';
import { File } from '../util/git';

export type Result<T> = T | Promise<T>;

Expand Down
132 changes: 0 additions & 132 deletions lib/platform/__snapshots__/index.spec.ts.snap
Expand Up @@ -2,138 +2,6 @@

exports[`platform escapes names 1`] = `"name [what]"`;

exports[`platform has a list of supported methods for azure 1`] = `
Array [
"addAssignees",
"addReviewers",
"commitFiles",
"createPr",
"deleteBranch",
"deleteLabel",
"ensureComment",
"ensureCommentRemoval",
"ensureIssue",
"ensureIssueClosing",
"findIssue",
"findPr",
"getBranchPr",
"getBranchStatus",
"getBranchStatusCheck",
"getIssueList",
"getPr",
"getPrBody",
"getPrList",
"getRepoForceRebase",
"getRepos",
"getVulnerabilityAlerts",
"initPlatform",
"initRepo",
"mergePr",
"setBaseBranch",
"setBranchStatus",
"updatePr",
]
`;

exports[`platform has a list of supported methods for gitea 1`] = `
Array [
"addAssignees",
"addReviewers",
"commitFiles",
"createPr",
"deleteBranch",
"deleteLabel",
"ensureComment",
"ensureCommentRemoval",
"ensureIssue",
"ensureIssueClosing",
"findIssue",
"findPr",
"getBranchPr",
"getBranchStatus",
"getBranchStatusCheck",
"getIssueList",
"getPr",
"getPrBody",
"getPrList",
"getRepoForceRebase",
"getRepos",
"getVulnerabilityAlerts",
"initPlatform",
"initRepo",
"mergePr",
"setBaseBranch",
"setBranchStatus",
"updatePr",
]
`;

exports[`platform has a list of supported methods for github 1`] = `
Array [
"addAssignees",
"addReviewers",
"commitFiles",
"createPr",
"deleteBranch",
"deleteLabel",
"ensureComment",
"ensureCommentRemoval",
"ensureIssue",
"ensureIssueClosing",
"findIssue",
"findPr",
"getBranchPr",
"getBranchStatus",
"getBranchStatusCheck",
"getIssueList",
"getPr",
"getPrBody",
"getPrList",
"getRepoForceRebase",
"getRepos",
"getVulnerabilityAlerts",
"initPlatform",
"initRepo",
"mergePr",
"setBaseBranch",
"setBranchStatus",
"updatePr",
]
`;

exports[`platform has a list of supported methods for gitlab 1`] = `
Array [
"addAssignees",
"addReviewers",
"commitFiles",
"createPr",
"deleteBranch",
"deleteLabel",
"ensureComment",
"ensureCommentRemoval",
"ensureIssue",
"ensureIssueClosing",
"findIssue",
"findPr",
"getBranchPr",
"getBranchStatus",
"getBranchStatusCheck",
"getIssueList",
"getPr",
"getPrBody",
"getPrList",
"getRepoForceRebase",
"getRepos",
"getVulnerabilityAlerts",
"initPlatform",
"initRepo",
"mergePr",
"setBaseBranch",
"setBranchStatus",
"updatePr",
]
`;

exports[`platform initializes 1`] = `
Object {
"endpoint": "https://api.bitbucket.org/",
Expand Down
13 changes: 0 additions & 13 deletions lib/platform/azure/index.ts
Expand Up @@ -19,7 +19,6 @@ import { sanitize } from '../../util/sanitize';
import { ensureTrailingSlash } from '../../util/url';
import {
BranchStatusConfig,
CommitFilesConfig,
CreatePRConfig,
EnsureCommentConfig,
EnsureCommentRemovalConfig,
Expand Down Expand Up @@ -326,18 +325,6 @@ export /* istanbul ignore next */ async function deleteBranch(
}
}

export /* istanbul ignore next */ function commitFiles({
branchName,
files,
message,
}: CommitFilesConfig): Promise<string | null> {
return git.commitFiles({
branchName,
files,
message,
});
}

export async function getBranchStatusCheck(
branchName: string,
context: string
Expand Down
82 changes: 0 additions & 82 deletions lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap
Expand Up @@ -546,47 +546,6 @@ Array [
]
`;

exports[`platform/bitbucket-server endpoint with no path commitFiles() sends to gitFs 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"authorization": "Basic YWJjOjEyMw==",
"host": "stash.renovatebot.com",
"user-agent": "https://github.com/renovatebot/renovate",
"x-atlassian-token": "no-check",
},
"method": "GET",
"url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"authorization": "Basic YWJjOjEyMw==",
"host": "stash.renovatebot.com",
"user-agent": "https://github.com/renovatebot/renovate",
"x-atlassian-token": "no-check",
},
"method": "GET",
"url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo/branches/default",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"authorization": "Basic YWJjOjEyMw==",
"host": "stash.renovatebot.com",
"user-agent": "https://github.com/renovatebot/renovate",
"x-atlassian-token": "no-check",
},
"method": "GET",
"url": "https://stash.renovatebot.com/rest/api/1.0/projects/SOME/repos/repo/pull-requests?state=ALL&role.1=AUTHOR&username.1=abc&limit=100",
},
]
`;

exports[`platform/bitbucket-server endpoint with no path createPr() posts PR 1`] = `
Array [
Object {
Expand Down Expand Up @@ -4449,47 +4408,6 @@ Array [
]
`;
exports[`platform/bitbucket-server endpoint with path commitFiles() sends to gitFs 1`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"authorization": "Basic YWJjOjEyMw==",
"host": "stash.renovatebot.com",
"user-agent": "https://github.com/renovatebot/renovate",
"x-atlassian-token": "no-check",
},
"method": "GET",
"url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"authorization": "Basic YWJjOjEyMw==",
"host": "stash.renovatebot.com",
"user-agent": "https://github.com/renovatebot/renovate",
"x-atlassian-token": "no-check",
},
"method": "GET",
"url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo/branches/default",
},
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"authorization": "Basic YWJjOjEyMw==",
"host": "stash.renovatebot.com",
"user-agent": "https://github.com/renovatebot/renovate",
"x-atlassian-token": "no-check",
},
"method": "GET",
"url": "https://stash.renovatebot.com/vcs/rest/api/1.0/projects/SOME/repos/repo/pull-requests?state=ALL&role.1=AUTHOR&username.1=abc&limit=100",
},
]
`;
exports[`platform/bitbucket-server endpoint with path createPr() posts PR 1`] = `
Array [
Object {
Expand Down
21 changes: 0 additions & 21 deletions lib/platform/bitbucket-server/index.spec.ts
Expand Up @@ -408,27 +408,6 @@ describe('platform/bitbucket-server', () => {
});
});

describe('commitFiles()', () => {
it('sends to gitFs', async () => {
expect.assertions(1);
const scope = await initRepo();
scope
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests?state=ALL&role.1=AUTHOR&username.1=abc&limit=100`
)
.reply(200, {
isLastPage: true,
values: [prMock(url, 'SOME', 'repo')],
});
await bitbucket.commitFiles({
branchName: 'some-branch',
files: [{ name: 'test', contents: 'dummy' }],
message: 'message',
});
expect(httpMock.getTrace()).toMatchSnapshot();
});
});

describe('addAssignees()', () => {
it('does not throw', async () => {
expect(await bitbucket.addAssignees(3, ['some'])).toMatchSnapshot();
Expand Down
18 changes: 5 additions & 13 deletions lib/platform/bitbucket-server/index.ts
Expand Up @@ -21,7 +21,6 @@ import { sanitize } from '../../util/sanitize';
import { ensureTrailingSlash } from '../../util/url';
import {
BranchStatusConfig,
CommitFilesConfig,
CreatePRConfig,
EnsureCommentConfig,
EnsureCommentRemovalConfig,
Expand Down Expand Up @@ -385,28 +384,21 @@ export async function findPr({
}

// Returns the Pull Request for a branch. Null if not exists.
export async function getBranchPr(
branchName: string,
refreshCache?: boolean
): Promise<BbsPr | null> {
export async function getBranchPr(branchName: string): Promise<BbsPr | null> {
logger.debug(`getBranchPr(${branchName})`);
const existingPr = await findPr({
branchName,
state: PR_STATE_OPEN,
});
return existingPr ? getPr(existingPr.number, refreshCache) : null;
return existingPr ? getPr(existingPr.number) : null;
}

export async function commitFiles(
commitFilesConfig: CommitFilesConfig
): Promise<string | null> {
const commit = git.commitFiles(commitFilesConfig);

// istanbul ignore next
export async function refreshPr(number: number): Promise<void> {
// wait for pr change propagation
await delay(1000);
// refresh cache
await getBranchPr(commitFilesConfig.branchName, true);
return commit;
await getPr(number, true);
}

export async function deleteBranch(
Expand Down
18 changes: 0 additions & 18 deletions lib/platform/bitbucket/__snapshots__/index.spec.ts.snap
Expand Up @@ -64,24 +64,6 @@ Array [
]
`;

exports[`platform/bitbucket commitFiles() sends to gitFs 1`] = `undefined`;

exports[`platform/bitbucket commitFiles() sends to gitFs 2`] = `
Array [
Object {
"headers": Object {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"authorization": "Basic YWJjOjEyMw==",
"host": "api.bitbucket.org",
"user-agent": "https://github.com/renovatebot/renovate",
},
"method": "GET",
"url": "https://api.bitbucket.org/2.0/repositories/some/repo",
},
]
`;

exports[`platform/bitbucket createPr() posts PR 1`] = `
Array [
Object {
Expand Down
13 changes: 0 additions & 13 deletions lib/platform/bitbucket/index.spec.ts
Expand Up @@ -807,19 +807,6 @@ describe('platform/bitbucket', () => {
});
});

describe('commitFiles()', () => {
it('sends to gitFs', async () => {
await initRepoMock();
const res = await bitbucket.commitFiles({
branchName: 'test',
files: [],
message: 'message',
});
expect(res).toMatchSnapshot();
expect(httpMock.getTrace()).toMatchSnapshot();
});
});

describe('getVulnerabilityAlerts()', () => {
it('returns empty array', async () => {
expect(await bitbucket.getVulnerabilityAlerts()).toEqual([]);
Expand Down

0 comments on commit 4665dbf

Please sign in to comment.