diff --git a/lib/platform/azure/__snapshots__/index.spec.ts.snap b/lib/platform/azure/__snapshots__/index.spec.ts.snap index 98bbf1fa1bcb8feccab6c7b814241c7bbaae84e6..1ed2c883db95266978d6df8e612cc72d8c0831d2 100644 --- a/lib/platform/azure/__snapshots__/index.spec.ts.snap +++ b/lib/platform/azure/__snapshots__/index.spec.ts.snap @@ -133,6 +133,7 @@ exports[`platform/azure getBranchPr(branchName) should return the pr 1`] = `null exports[`platform/azure getPr(prNo) should return a pr in the right format 1`] = ` Object { + "hasReviewers": false, "isModified": false, "labels": Array [ "renovate", @@ -143,6 +144,7 @@ Object { exports[`platform/azure getPr(prNo) should return a pr thats been modified 1`] = ` Object { + "hasReviewers": false, "isModified": true, "labels": Array [], "number": 1234, diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts index 6f24dba0b317350e60a53f07f5533b53d1701870..98363e171039e7aa1a1880e9c6bf738d8daa9c8c 100644 --- a/lib/platform/azure/index.ts +++ b/lib/platform/azure/index.ts @@ -1,3 +1,4 @@ +import is from '@sindresorhus/is'; import { GitPullRequest, GitPullRequestCommentThread, @@ -262,7 +263,7 @@ export async function getPr(pullRequestId: number): Promise<Pr | null> { azurePr.isModified = commits.length > 0 && commits[0].author.name !== commits[commits.length - 1].author.name; - + azurePr.hasReviewers = is.nonEmptyArray(azurePr.reviewers); return azurePr; } diff --git a/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap b/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap index 075b9c5abe1258d77df62f0c8f4038d9a8767974..da572a96b8ddac59d14de8484684d1323d6ad1c4 100644 --- a/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap +++ b/lib/platform/bitbucket-server/__snapshots__/index.spec.ts.snap @@ -1506,6 +1506,7 @@ Object { "canMerge": false, "createdAt": 1547853840016, "displayNumber": "Pull Request #5", + "hasReviewers": true, "isConflicted": false, "isModified": false, "isStale": false, @@ -1957,6 +1958,7 @@ Object { "canMerge": false, "createdAt": 1547853840016, "displayNumber": "Pull Request #5", + "hasReviewers": true, "isConflicted": false, "isModified": true, "isStale": false, @@ -1979,6 +1981,7 @@ Object { "canMerge": false, "createdAt": 1547853840016, "displayNumber": "Pull Request #5", + "hasReviewers": true, "isConflicted": false, "isModified": false, "isStale": false, @@ -2001,6 +2004,7 @@ Object { "canMerge": false, "createdAt": 1547853840016, "displayNumber": "Pull Request #5", + "hasReviewers": true, "isConflicted": false, "isModified": true, "isStale": false, @@ -2160,6 +2164,7 @@ Object { "canMerge": false, "createdAt": 1547853840016, "displayNumber": "Pull Request #5", + "hasReviewers": true, "isConflicted": false, "isModified": false, "isStale": false, @@ -2245,6 +2250,7 @@ Object { "branchName": undefined, "createdAt": undefined, "displayNumber": "Pull Request #undefined", + "hasReviewers": false, "isModified": false, "isStale": false, "number": undefined, @@ -5372,6 +5378,7 @@ Object { "canMerge": false, "createdAt": 1547853840016, "displayNumber": "Pull Request #5", + "hasReviewers": true, "isConflicted": false, "isModified": false, "isStale": false, @@ -5823,6 +5830,7 @@ Object { "canMerge": false, "createdAt": 1547853840016, "displayNumber": "Pull Request #5", + "hasReviewers": true, "isConflicted": false, "isModified": true, "isStale": false, @@ -5845,6 +5853,7 @@ Object { "canMerge": false, "createdAt": 1547853840016, "displayNumber": "Pull Request #5", + "hasReviewers": true, "isConflicted": false, "isModified": false, "isStale": false, @@ -5867,6 +5876,7 @@ Object { "canMerge": false, "createdAt": 1547853840016, "displayNumber": "Pull Request #5", + "hasReviewers": true, "isConflicted": false, "isModified": true, "isStale": false, @@ -6026,6 +6036,7 @@ Object { "canMerge": false, "createdAt": 1547853840016, "displayNumber": "Pull Request #5", + "hasReviewers": true, "isConflicted": false, "isModified": false, "isStale": false, @@ -6111,6 +6122,7 @@ Object { "branchName": undefined, "createdAt": undefined, "displayNumber": "Pull Request #undefined", + "hasReviewers": false, "isModified": false, "isStale": false, "number": undefined, diff --git a/lib/platform/bitbucket-server/index.ts b/lib/platform/bitbucket-server/index.ts index 44cb2afb0160eb92213060c5cf6e3557a93de753..75c2e1bb98d22fe40ab413ec8a12bed8645eefcd 100644 --- a/lib/platform/bitbucket-server/index.ts +++ b/lib/platform/bitbucket-server/index.ts @@ -1,4 +1,5 @@ import url, { URLSearchParams } from 'url'; +import is from '@sindresorhus/is'; import delay from 'delay'; import { RenovateConfig } from '../../config/common'; import { @@ -267,7 +268,7 @@ export async function getPr( reviewers: res.body.reviewers.map((r) => r.user.name), isModified: false, }; - + pr.hasReviewers = is.nonEmptyArray(pr.reviewers); pr.version = updatePrVersion(pr.number, pr.version); if (pr.state === PR_STATE_OPEN) { diff --git a/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap b/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap index 3c0b2ec7cf2d3e315fd21903c0a61946629cf720..994caf139a5934479fdd162514a5f93e4b1a76de 100644 --- a/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap +++ b/lib/platform/bitbucket/__snapshots__/index.spec.ts.snap @@ -518,6 +518,7 @@ Object { "canMerge": true, "createdAt": "2018-07-02T07:02:25.275030+00:00", "displayNumber": "Pull Request #5", + "hasReviewers": false, "isConflicted": false, "isModified": false, "isStale": false, @@ -919,6 +920,7 @@ Object { "canMerge": true, "createdAt": "2018-07-02T07:02:25.275030+00:00", "displayNumber": "Pull Request #3", + "hasReviewers": false, "isConflicted": false, "isModified": true, "isStale": false, @@ -936,6 +938,7 @@ Object { "canMerge": true, "createdAt": "2018-07-02T07:02:25.275030+00:00", "displayNumber": "Pull Request #5", + "hasReviewers": false, "isConflicted": false, "isModified": false, "isStale": false, @@ -953,6 +956,7 @@ Object { "canMerge": true, "createdAt": "2018-07-02T07:02:25.275030+00:00", "displayNumber": "Pull Request #5", + "hasReviewers": false, "isConflicted": false, "isModified": true, "isStale": false, @@ -1082,6 +1086,7 @@ Object { "canMerge": true, "createdAt": "2018-07-02T07:02:25.275030+00:00", "displayNumber": "Pull Request #5", + "hasReviewers": false, "isConflicted": false, "isModified": false, "isStale": false, diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index bb16658f8ba4e997a70a362745ac43cfe15bca55..511efd04cd1a3d408be32379bd0d08d8932be0ee 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -1,4 +1,5 @@ import URL from 'url'; +import is from '@sindresorhus/is'; import addrs from 'email-addresses'; import parseDiff from 'parse-diff'; import { RenovateConfig } from '../../config/common'; @@ -327,6 +328,8 @@ export async function getPr(prNo: number): Promise<Pr | null> { res.isStale = await git.isBranchStale(pr.source.branch.name); } + res.hasReviewers = is.nonEmptyArray(pr.reviewers); + return res; } diff --git a/lib/platform/common.ts b/lib/platform/common.ts index 97a2de0ed116544aafd0810ffe36568001027c2b..550e093cc4d2b9d93c36dd04c8b25a5fd41057b0 100644 --- a/lib/platform/common.ts +++ b/lib/platform/common.ts @@ -43,6 +43,8 @@ export interface Pr { canMergeReason?: string; createdAt?: string; displayNumber?: string; + hasAssignees?: boolean; + hasReviewers?: boolean; isConflicted?: boolean; isModified?: boolean; isStale?: boolean; diff --git a/lib/platform/gitea/__snapshots__/index.spec.ts.snap b/lib/platform/gitea/__snapshots__/index.spec.ts.snap index f165adbbd31e134aef424309e0fc1bea963f6cbf..0f6d04a8330d99f5d0b097995093dc90f4cedf46 100644 --- a/lib/platform/gitea/__snapshots__/index.spec.ts.snap +++ b/lib/platform/gitea/__snapshots__/index.spec.ts.snap @@ -7,6 +7,7 @@ Object { "canMerge": true, "createdAt": "2014-04-01T05:14:20Z", "displayNumber": "Pull Request #42", + "hasAssignees": false, "isConflicted": false, "isModified": undefined, "isStale": undefined, @@ -26,6 +27,7 @@ Object { "canMerge": true, "createdAt": "2014-04-01T05:14:20Z", "displayNumber": "Pull Request #42", + "hasAssignees": false, "isConflicted": false, "isModified": undefined, "isStale": undefined, @@ -45,6 +47,7 @@ Object { "canMerge": true, "createdAt": "2015-03-22T20:36:16Z", "displayNumber": "Pull Request #1", + "hasAssignees": false, "isConflicted": false, "isModified": true, "isStale": false, @@ -64,6 +67,7 @@ Object { "canMerge": true, "createdAt": "2015-03-22T20:36:16Z", "displayNumber": "Pull Request #1", + "hasAssignees": false, "isConflicted": false, "isModified": false, "isStale": false, @@ -84,6 +88,7 @@ Array [ "canMerge": true, "createdAt": "2015-03-22T20:36:16Z", "displayNumber": "Pull Request #1", + "hasAssignees": false, "isConflicted": false, "isModified": undefined, "isStale": undefined, @@ -100,6 +105,7 @@ Array [ "canMerge": true, "createdAt": "2011-08-18T22:30:38Z", "displayNumber": "Pull Request #2", + "hasAssignees": false, "isConflicted": false, "isModified": undefined, "isStale": undefined, diff --git a/lib/platform/gitea/gitea-helper.ts b/lib/platform/gitea/gitea-helper.ts index 120220940d5306b650714892a8bfd8070a4eb891..756f7535aedff770dea22c441e87368bb5033711 100644 --- a/lib/platform/gitea/gitea-helper.ts +++ b/lib/platform/gitea/gitea-helper.ts @@ -33,6 +33,10 @@ export interface PR { sha: string; repo?: Repo; }; + assignee?: { + login?: string; + }; + assignees?: any[]; } export interface Issue { diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index 7cccb5419b624dd6a1c669948a72ccc02e9a12c1..6211369c311a881947fa10c92f154a42e045d833 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -1,4 +1,5 @@ import URL from 'url'; +import is from '@sindresorhus/is'; import { configFileNames } from '../../config/app-strings'; import { RenovateConfig } from '../../config/common'; import { @@ -104,6 +105,7 @@ function toRenovatePR(data: helper.PR): Pr | null { isConflicted: !data.mergeable, isStale: undefined, isModified: undefined, + hasAssignees: !!(data.assignee?.login || is.nonEmptyArray(data.assignees)), }; } diff --git a/lib/platform/github/__snapshots__/index.spec.ts.snap b/lib/platform/github/__snapshots__/index.spec.ts.snap index 5a5c9415330c809726bdb19576bad464039efd68..28be1610335a76f0e567a990c1008a20def1fec6 100644 --- a/lib/platform/github/__snapshots__/index.spec.ts.snap +++ b/lib/platform/github/__snapshots__/index.spec.ts.snap @@ -1935,6 +1935,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -1975,6 +1978,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -1993,7 +1999,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", @@ -2200,6 +2206,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -2240,6 +2249,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -2258,7 +2270,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", @@ -2928,6 +2940,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -2968,6 +2983,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -2986,7 +3004,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", @@ -3057,6 +3075,8 @@ Object { "canMerge": false, "canMergeReason": "mergeStateStatus = DIRTY", "displayNumber": "Pull Request #2500", + "hasAssignees": false, + "hasReviewers": false, "isConflicted": true, "isModified": false, "isStale": true, @@ -3114,6 +3134,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -3154,6 +3177,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -3172,7 +3198,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", @@ -3254,6 +3280,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -3294,6 +3323,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -3312,7 +3344,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", @@ -3443,6 +3475,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -3483,6 +3518,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -3501,7 +3539,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", @@ -3642,6 +3680,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -3682,6 +3723,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -3700,7 +3744,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", @@ -3842,6 +3886,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -3882,6 +3929,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -3900,7 +3950,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", @@ -4053,6 +4103,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -4093,6 +4146,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -4111,7 +4167,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", @@ -4264,6 +4320,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -4304,6 +4363,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -4322,7 +4384,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", @@ -4475,6 +4537,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -4515,6 +4580,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -4533,7 +4601,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", @@ -4686,6 +4754,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -4726,6 +4797,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -4744,7 +4818,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", @@ -4878,6 +4952,9 @@ Array [ "first": "100", }, "nodes": Object { + "assignees": Object { + "totalCount": null, + }, "baseRefName": null, "body": null, "commits": Object { @@ -4918,6 +4995,9 @@ Array [ "mergeStateStatus": null, "mergeable": null, "number": null, + "reviewRequests": Object { + "totalCount": null, + }, "reviews": Object { "__args": Object { "first": "1", @@ -4936,7 +5016,7 @@ Array [ "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.v3+json", "accept-encoding": "gzip, deflate", "authorization": "token abc123", - "content-length": 1264, + "content-length": 1413, "content-type": "application/json", "host": "api.github.com", "user-agent": "https://github.com/renovatebot/renovate", diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index abd2a86dcb73aa4c18be282988ddeda48f347f58..12ceb01f4271cdae988dceafc5f81f7606a96581 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -600,6 +600,12 @@ async function getOpenPrs(): Promise<PrList> { name } } + assignees { + totalCount + } + reviewRequests { + totalCount + } commits(first: 2) { nodes { commit { @@ -723,6 +729,10 @@ async function getOpenPrs(): Promise<PrList> { (label: { name: string }) => label.name ); } + pr.hasAssignees = !!(pr.assignees?.totalCount > 0); + delete pr.assignees; + pr.hasReviewers = !!(pr.reviewRequests?.totalCount > 0); + delete pr.reviewRequests; delete pr.mergeable; delete pr.mergeStateStatus; delete pr.commits; diff --git a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap index a9050579770071360702465cd379c5d1eadb2248..2ece084bd0707369c646f00454f97300bc05af7e 100644 --- a/lib/platform/gitlab/__snapshots__/index.spec.ts.snap +++ b/lib/platform/gitlab/__snapshots__/index.spec.ts.snap @@ -832,6 +832,8 @@ Object { "commits": 1, "deletions": 1, "displayNumber": "Merge Request #91", + "hasAssignees": false, + "hasReviewers": false, "iid": 91, "isConflicted": true, "isModified": true, @@ -1171,6 +1173,8 @@ Object { "description": "a merge request", "displayNumber": "Merge Request #12345", "diverged_commits_count": 5, + "hasAssignees": false, + "hasReviewers": false, "id": 1, "iid": 12345, "isConflicted": true, @@ -1220,6 +1224,8 @@ Object { "description": "a merge request", "displayNumber": "Merge Request #12345", "diverged_commits_count": 2, + "hasAssignees": true, + "hasReviewers": false, "id": 1, "iid": 12345, "isConflicted": true, @@ -1269,6 +1275,8 @@ Object { "description": "a merge request", "displayNumber": "Merge Request #12345", "diverged_commits_count": 5, + "hasAssignees": true, + "hasReviewers": false, "id": 1, "iid": 12345, "isModified": true, diff --git a/lib/platform/gitlab/index.spec.ts b/lib/platform/gitlab/index.spec.ts index ad2e79ea10b7afff1c398a14af59a0c84d4bd067..a83433a44eacd87c04fb5c59d3d57c232a5f16bb 100644 --- a/lib/platform/gitlab/index.spec.ts +++ b/lib/platform/gitlab/index.spec.ts @@ -1079,11 +1079,13 @@ describe('platform/gitlab', () => { diverged_commits_count: 5, source_branch: 'some-branch', target_branch: 'master', + assignees: [], }) .get('/api/v4/projects/undefined/repository/branches/some-branch') .reply(200, { commit: { author_email: global.gitAuthor.email } }); const pr = await gitlab.getPr(12345); expect(pr).toMatchSnapshot(); + expect(pr.hasAssignees).toBe(false); expect(httpMock.getTrace()).toMatchSnapshot(); }); it('returns the mergeable PR', async () => { @@ -1100,6 +1102,9 @@ describe('platform/gitlab', () => { diverged_commits_count: 5, source_branch: 'some-branch', target_branch: 'master', + assignee: { + id: 1, + }, }) .get( '/api/v4/projects/some%2Frepo/repository/commits/0d9c7726c3d628b7e28af234595cfd20febdbf8e/statuses' @@ -1109,6 +1114,7 @@ describe('platform/gitlab', () => { .reply(200, { commit: null }); const pr = await gitlab.getPr(12345); expect(pr).toMatchSnapshot(); + expect(pr.hasAssignees).toBe(true); expect(httpMock.getTrace()).toMatchSnapshot(); }); it('returns the PR with nonexisting branch', async () => { @@ -1126,11 +1132,17 @@ describe('platform/gitlab', () => { diverged_commits_count: 2, source_branch: 'some-branch', target_branch: 'master', + assignees: [ + { + id: 1, + }, + ], }) .get('/api/v4/projects/undefined/repository/branches/some-branch') .reply(404); const pr = await gitlab.getPr(12345); expect(pr).toMatchSnapshot(); + expect(pr.hasAssignees).toBe(true); expect(httpMock.getTrace()).toMatchSnapshot(); }); }); diff --git a/lib/platform/gitlab/index.ts b/lib/platform/gitlab/index.ts index 98f52c113e8c84305e5e3581d97f1520469c325c..9fc8ecc077f80e4ab435715208b0e0b68e1e45d1 100644 --- a/lib/platform/gitlab/index.ts +++ b/lib/platform/gitlab/index.ts @@ -442,6 +442,8 @@ export async function getPr(iid: number): Promise<Pr> { description: string; diverged_commits_count: number; merge_status: string; + assignee?: { id?: number }; + assignees?: { id?: number }[]; } >(url) ).body; @@ -454,6 +456,10 @@ export async function getPr(iid: number): Promise<Pr> { pr.isStale = pr.diverged_commits_count > 0; pr.state = pr.state === 'opened' ? PR_STATE_OPEN : pr.state; pr.isModified = true; + pr.hasAssignees = !!(pr.assignee?.id || pr.assignees?.[0]?.id); + delete pr.assignee; + delete pr.assignees; + pr.hasReviewers = false; if (pr.merge_status === 'cannot_be_merged') { logger.debug('pr cannot be merged'); pr.canMerge = false; diff --git a/lib/workers/pr/index.ts b/lib/workers/pr/index.ts index c50b153aa39f631f54116d248bb6f4b10024cb48..79f1e153b172386d286b1e139dd8f661c87a1b2e 100644 --- a/lib/workers/pr/index.ts +++ b/lib/workers/pr/index.ts @@ -282,7 +282,12 @@ export async function ensurePr( if (existingPr) { logger.debug('Processing existing PR'); // istanbul ignore if - if (config.automerge && (await getBranchStatus()) === BranchStatus.red) { + if ( + !existingPr.hasAssignees && + !existingPr.hasReviewers && + config.automerge && + (await getBranchStatus()) === BranchStatus.red + ) { logger.debug(`Setting assignees and reviewers as status checks failed`); await addAssigneesReviewers(config, existingPr); }