Skip to content

Commit

Permalink
refactor(platform): remove unnecessary pr.canMerge cases (#13914)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jan 31, 2022
1 parent 493fd75 commit 3a34d11
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 880 deletions.
614 changes: 2 additions & 612 deletions lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap

Large diffs are not rendered by default.

101 changes: 5 additions & 96 deletions lib/platform/bitbucket-server/index.spec.ts
Expand Up @@ -486,11 +486,6 @@ describe('platform/bitbucket-server/index', () => {
it('does not throw', async () => {
const scope = await initRepo();
scope
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.twice()
.reply(200, { conflicted: false })
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand All @@ -509,11 +504,6 @@ describe('platform/bitbucket-server/index', () => {
expect.assertions(1);
const scope = await initRepo();
scope
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.twice()
.reply(200, { conflicted: false })
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand Down Expand Up @@ -559,10 +549,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.put(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand All @@ -582,10 +568,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.put(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand All @@ -603,10 +585,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.put(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand Down Expand Up @@ -643,10 +621,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.put(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand Down Expand Up @@ -1136,11 +1110,7 @@ describe('platform/bitbucket-server/index', () => {
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false });
.reply(200, prMock(url, 'SOME', 'repo'));

expect(
await bitbucket.getBranchPr('userName1/pullRequest5')
Expand Down Expand Up @@ -1279,11 +1249,7 @@ describe('platform/bitbucket-server/index', () => {
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false });
.reply(200, prMock(url, 'SOME', 'repo'));

expect(await bitbucket.getPr(5)).toMatchSnapshot();
expect(httpMock.getTrace()).toMatchSnapshot();
Expand All @@ -1296,20 +1262,11 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/3`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/3/merge`
)
.reply(200, { conflicted: false })
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.twice()
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.twice()
.reply(200, { conflicted: false });
.reply(200, prMock(url, 'SOME', 'repo'));

expect(await bitbucket.getPr(3)).toMatchSnapshot();

Expand Down Expand Up @@ -1348,10 +1305,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.put(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand All @@ -1372,10 +1325,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.put(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand All @@ -1401,10 +1350,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.put(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand Down Expand Up @@ -1457,10 +1402,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.put(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand All @@ -1480,10 +1421,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.put(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand All @@ -1510,10 +1447,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.put(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`,
(body) => body.reviewers.length === 0
Expand All @@ -1537,10 +1470,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.put(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand All @@ -1559,10 +1488,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.put(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
Expand All @@ -1583,10 +1508,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.post(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge?version=1`
)
Expand Down Expand Up @@ -1635,10 +1556,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.post(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge?version=1`
)
Expand All @@ -1660,10 +1577,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.post(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge?version=1`
)
Expand All @@ -1685,10 +1598,6 @@ describe('platform/bitbucket-server/index', () => {
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5`
)
.reply(200, prMock(url, 'SOME', 'repo'))
.get(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge`
)
.reply(200, { conflicted: false })
.post(
`${urlPath}/rest/api/1.0/projects/SOME/repos/repo/pull-requests/5/merge?version=1`
)
Expand Down Expand Up @@ -2112,9 +2021,9 @@ Followed by some information.

it('returns file content in json5 format', async () => {
const json5Data = `
{
{
// json5 comment
foo: 'bar'
foo: 'bar'
}
`;
const scope = await initRepo();
Expand Down
11 changes: 0 additions & 11 deletions lib/platform/bitbucket-server/index.ts
Expand Up @@ -289,17 +289,6 @@ export async function getPr(
pr.hasReviewers = is.nonEmptyArray(pr.reviewers);
pr.version = updatePrVersion(pr.number, pr.version);

if (pr.state === PrState.Open) {
const mergeRes = await bitbucketServerHttp.getJson<{
conflicted: string;
canMerge: string;
}>(
`./rest/api/1.0/projects/${config.projectKey}/repos/${config.repositorySlug}/pull-requests/${prNo}/merge`,
{ useCache: !refreshCache }
);
pr.canMerge = !!mergeRes.body.canMerge;
}

return pr;
}

Expand Down
16 changes: 8 additions & 8 deletions lib/platform/gitea/__snapshots__/index.spec.ts.snap
Expand Up @@ -3,7 +3,7 @@
exports[`platform/gitea/index createPr should use base branch by default 1`] = `
Object {
"body": "pr-body",
"canMerge": true,
"cannotMergeReason": undefined,
"createdAt": "2014-04-01T05:14:20Z",
"displayNumber": "Pull Request #42",
"hasAssignees": false,
Expand All @@ -20,7 +20,7 @@ Object {
exports[`platform/gitea/index createPr should use default branch if requested 1`] = `
Object {
"body": "pr-body",
"canMerge": true,
"cannotMergeReason": undefined,
"createdAt": "2014-04-01T05:14:20Z",
"displayNumber": "Pull Request #42",
"hasAssignees": false,
Expand All @@ -37,7 +37,7 @@ Object {
exports[`platform/gitea/index getPr should fallback to direct fetching if cache fails 1`] = `
Object {
"body": "some random pull request",
"canMerge": true,
"cannotMergeReason": "pr.mergeable=\\"false\\"",
"createdAt": "2015-03-22T20:36:16Z",
"displayNumber": "Pull Request #1",
"hasAssignees": false,
Expand All @@ -54,7 +54,7 @@ Object {
exports[`platform/gitea/index getPr should return enriched pull request which exists if open 1`] = `
Object {
"body": "some random pull request",
"canMerge": true,
"cannotMergeReason": undefined,
"createdAt": "2015-03-22T20:36:16Z",
"displayNumber": "Pull Request #1",
"hasAssignees": false,
Expand All @@ -79,7 +79,7 @@ exports[`platform/gitea/index getPrList should filter list by creator 2`] = `
Array [
Object {
"body": "some random pull request",
"canMerge": true,
"cannotMergeReason": undefined,
"createdAt": "2015-03-22T20:36:16Z",
"displayNumber": "Pull Request #1",
"hasAssignees": false,
Expand All @@ -93,7 +93,7 @@ Array [
},
Object {
"body": "other random pull request",
"canMerge": true,
"cannotMergeReason": undefined,
"createdAt": "2011-08-18T22:30:38Z",
"displayNumber": "Pull Request #2",
"hasAssignees": false,
Expand All @@ -112,7 +112,7 @@ exports[`platform/gitea/index getPrList should return list of pull requests 1`]
Array [
Object {
"body": "some random pull request",
"canMerge": true,
"cannotMergeReason": undefined,
"createdAt": "2015-03-22T20:36:16Z",
"displayNumber": "Pull Request #1",
"hasAssignees": false,
Expand All @@ -126,7 +126,7 @@ Array [
},
Object {
"body": "other random pull request",
"canMerge": true,
"cannotMergeReason": undefined,
"createdAt": "2011-08-18T22:30:38Z",
"displayNumber": "Pull Request #2",
"hasAssignees": false,
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/gitea/index.spec.ts
Expand Up @@ -576,7 +576,7 @@ describe('platform/gitea/index', () => {
it('should fallback to direct fetching if cache fails', async () => {
const mockPR = mockPRs[0];
helper.searchPRs.mockResolvedValueOnce([]);
helper.getPR.mockResolvedValueOnce(mockPR);
helper.getPR.mockResolvedValueOnce({ ...mockPR, mergeable: false });
await initFakeRepo();

const res = await gitea.getPr(mockPR.number);
Expand Down
4 changes: 3 additions & 1 deletion lib/platform/gitea/index.ts
Expand Up @@ -102,7 +102,9 @@ function toRenovatePR(data: helper.PR): Pr | null {
targetBranch: data.base.ref,
sourceRepo: data.head.repo.full_name,
createdAt: data.created_at,
canMerge: data.mergeable,
cannotMergeReason: data.mergeable
? undefined
: `pr.mergeable="${data.mergeable}"`,
hasAssignees: !!(data.assignee?.login || is.nonEmptyArray(data.assignees)),
};
}
Expand Down
6 changes: 1 addition & 5 deletions lib/platform/github/__fixtures__/graphql/pullrequest-1.json
Expand Up @@ -9,7 +9,6 @@
"baseRefName": "master",
"headRefName": "renovate/major-got-packages",
"title": "build(deps): update got packages (major)",
"mergeable": "MERGEABLE",
"mergeStateStatus": "CLEAN",
"labels": {
"nodes": [
Expand All @@ -24,20 +23,17 @@
"baseRefName": "master",
"headRefName": "renovate/jest-monorepo",
"title": "chore(deps): update dependency jest to v23.6.0",
"mergeable": "UNKNOWN",
"mergeStateStatus": "DIRTY"
},
{
"number": 2079,
"headRefName": "feat/nodever",
"title": "feat: node versioning (WIP)",
"mergeable": "MERGEABLE"
"title": "feat: node versioning (WIP)"
},
{
"number": 2086,
"headRefName": "fix/deletePRafterDeleteBranch",
"title": "feat(azure): abandon pr after delete branch",
"mergeable": "MERGEABLE",
"mergeStateStatus": "BEHIND",
"reviews": { "nodes": [ ] }
}
Expand Down

0 comments on commit 3a34d11

Please sign in to comment.