diff --git a/lib/platform/github/__snapshots__/index.spec.ts.snap b/lib/platform/github/__snapshots__/index.spec.ts.snap index 824f9d30b8171ceb51687d71b85a29829ada1011..62ceb6e3d44ed5f2a991c66ff6a05070c3acf501 100644 --- a/lib/platform/github/__snapshots__/index.spec.ts.snap +++ b/lib/platform/github/__snapshots__/index.spec.ts.snap @@ -1762,6 +1762,41 @@ Array [ exports[`platform/github findPr(branchName, prTitle, state) returns true if no title and all state 1`] = ` Array [ + Object { + "graphql": Object { + "query": Object { + "repository": Object { + "__args": Object { + "name": "repo", + "owner": "some", + }, + "defaultBranchRef": Object { + "name": null, + "target": Object { + "oid": null, + }, + }, + "isArchived": null, + "isFork": null, + "mergeCommitAllowed": null, + "nameWithOwner": null, + "rebaseMergeAllowed": null, + "squashMergeAllowed": null, + }, + }, + }, + "headers": Object { + "accept": "application/vnd.github.v3+json", + "accept-encoding": "gzip, deflate", + "authorization": "token abc123", + "content-length": "330", + "content-type": "application/json", + "host": "api.github.com", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "POST", + "url": "https://api.github.com/graphql", + }, Object { "headers": Object { "accept": "application/vnd.github.v3+json", @@ -1771,7 +1806,7 @@ Array [ "user-agent": "https://github.com/renovatebot/renovate", }, "method": "GET", - "url": "https://api.github.com/repos/undefined/pulls?per_page=100&state=all", + "url": "https://api.github.com/repos/some/repo/pulls?per_page=100&state=all", }, ] `; diff --git a/lib/platform/github/index.spec.ts b/lib/platform/github/index.spec.ts index ea9c07c292aeee66b77b0f4baebf13360dc4a57b..2aacadf589f9123d254665e7a965654ba0a02290 100644 --- a/lib/platform/github/index.spec.ts +++ b/lib/platform/github/index.spec.ts @@ -1502,17 +1502,37 @@ describe('platform/github', () => { }); describe('findPr(branchName, prTitle, state)', () => { it('returns true if no title and all state', async () => { - httpMock + const scope = httpMock .scope(githubApiHost) - .get('/repos/undefined/pulls?per_page=100&state=all') + .get('/repos/some/repo/pulls?per_page=100&state=all') .reply(200, [ + { + number: 2, + head: { + ref: 'branch-a', + repo: { full_name: 'some/repo' }, + }, + title: 'branch a pr', + state: PrState.Open, + user: { login: 'not-me' }, + }, { number: 1, - head: { ref: 'branch-a' }, + head: { + ref: 'branch-a', + repo: { full_name: 'some/repo' }, + }, title: 'branch a pr', state: PrState.Open, + user: { login: 'me' }, }, ]); + initRepoMock(scope, 'some/repo'); + await github.initRepo({ + repository: 'some/repo', + token: 'token', + renovateUsername: 'me', + } as any); const res = await github.findPr({ branchName: 'branch-a', diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index 6bf90a67e521ff95e3ad7e08a04cd05deb7e9bd9..7ce2b2630c002b56a92455b8fc9503890a0f843e 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -50,6 +50,7 @@ import { GhBranchStatus, GhGraphQlPr, GhPr, + GhPulls, GhRepo, GhRestPr, LocalRepoConfig, @@ -693,39 +694,42 @@ export async function getPrList(): Promise<Pr[]> { logger.trace('getPrList()'); if (!config.prList) { logger.debug('Retrieving PR list'); - let res; + let prList: GhPulls; try { - res = await githubApi.getJson<{ - number: number; - head: { ref: string; sha: string; repo: { full_name: string } }; - title: string; - state: string; - merged_at: string; - created_at: string; - closed_at: string; - }>( - `repos/${ - config.parentRepo || config.repository - }/pulls?per_page=100&state=all`, - { paginate: true } - ); + prList = ( + await githubApi.getJson<GhPulls>( + `repos/${ + config.parentRepo || config.repository + }/pulls?per_page=100&state=all`, + { paginate: true } + ) + ).body; } catch (err) /* istanbul ignore next */ { logger.debug({ err }, 'getPrList err'); throw new ExternalHostError(err, PLATFORM_TYPE_GITHUB); } - config.prList = res.body.map((pr) => ({ - number: pr.number, - branchName: pr.head.ref, - sha: pr.head.sha, - title: pr.title, - state: - pr.state === PrState.Closed && pr.merged_at?.length - ? /* istanbul ignore next */ PrState.Merged - : pr.state, - createdAt: pr.created_at, - closed_at: pr.closed_at, - sourceRepo: pr.head?.repo?.full_name, - })); + config.prList = prList + .filter((pr) => { + return pr?.user?.login && config?.renovateUsername + ? pr.user.login === config.renovateUsername + : true; + }) + .map( + (pr) => + ({ + number: pr.number, + branchName: pr.head.ref, + sha: pr.head.sha, + title: pr.title, + state: + pr.state === PrState.Closed && pr.merged_at?.length + ? /* istanbul ignore next */ PrState.Merged + : pr.state, + createdAt: pr.created_at, + closed_at: pr.closed_at, + sourceRepo: pr.head?.repo?.full_name, + } as never) + ); logger.debug(`Retrieved ${config.prList.length} Pull Requests`); } return config.prList; diff --git a/lib/platform/github/types.ts b/lib/platform/github/types.ts index fe009d192385797940c86ba07228388da225a07e..f48867c89f3f515229a32e2920a1bfa25a46dcf3 100644 --- a/lib/platform/github/types.ts +++ b/lib/platform/github/types.ts @@ -81,3 +81,18 @@ export interface GhRepo { }; }; } + +export type GhPulls = { + number: number; + head: { + ref: string; + sha: string; + repo: { full_name: string }; + }; + title: string; + state: string; + merged_at: string; + created_at: string; + closed_at: string; + user?: { login?: string }; +}[];