diff --git a/lib/platform/gitea/__snapshots__/index.spec.ts.snap b/lib/platform/gitea/__snapshots__/index.spec.ts.snap index eb328c1496a03faf819d684cdcce6ae1d6959033..094944432f2b50dc3206a013475ad085042163a3 100644 --- a/lib/platform/gitea/__snapshots__/index.spec.ts.snap +++ b/lib/platform/gitea/__snapshots__/index.spec.ts.snap @@ -72,6 +72,48 @@ Object { } `; +exports[`platform/gitea getPrList should filter list by creator 1`] = ` +Object { + "endpoint": "https://gitea.com/api/v1/", + "gitAuthor": "Renovate Bot <renovate@example.com>", +} +`; + +exports[`platform/gitea getPrList should filter list by creator 2`] = ` +Array [ + Object { + "body": "some random pull request", + "branchName": "some-head-branch", + "canMerge": true, + "createdAt": "2015-03-22T20:36:16Z", + "displayNumber": "Pull Request #1", + "hasAssignees": false, + "isConflicted": false, + "number": 1, + "sha": "some-head-sha", + "sourceRepo": "some/repo", + "state": "open", + "targetBranch": "some-base-branch", + "title": "Some PR", + }, + Object { + "body": "other random pull request", + "branchName": "other-head-branch", + "canMerge": true, + "createdAt": "2011-08-18T22:30:38Z", + "displayNumber": "Pull Request #2", + "hasAssignees": false, + "isConflicted": false, + "number": 2, + "sha": "other-head-sha", + "sourceRepo": "some/repo", + "state": "closed", + "targetBranch": "other-base-branch", + "title": "Other PR", + }, +] +`; + exports[`platform/gitea getPrList should return list of pull requests 1`] = ` Array [ Object { diff --git a/lib/platform/gitea/gitea-helper.ts b/lib/platform/gitea/gitea-helper.ts index a9436f2ae5d9a397ee424d4d3c381f4ebe6e129f..ed91a3f7992c9ce6c01863c37d1e81da30e5775e 100644 --- a/lib/platform/gitea/gitea-helper.ts +++ b/lib/platform/gitea/gitea-helper.ts @@ -36,6 +36,7 @@ export interface PR { login?: string; }; assignees?: any[]; + user?: { username?: string }; } export interface Issue { diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts index bb80df56c22efafd66ee389553ade4b9af69dde3..20101dd20650b251e57532d14927c26a80cc4627 100644 --- a/lib/platform/gitea/index.spec.ts +++ b/lib/platform/gitea/index.spec.ts @@ -514,6 +514,41 @@ describe('platform/gitea', () => { expect(res).toMatchSnapshot(); }); + it('should filter list by creator', async () => { + helper.getCurrentUser.mockResolvedValueOnce(mockUser); + + expect( + await gitea.initPlatform({ token: 'some-token' }) + ).toMatchSnapshot(); + + await initFakeRepo(); + + helper.searchPRs.mockResolvedValueOnce([ + partial<ght.PR>({ + number: 3, + title: 'Third-party PR', + body: 'other random pull request', + state: PrState.Open, + diff_url: 'https://gitea.renovatebot.com/some/repo/pulls/3.diff', + created_at: '2011-08-18T22:30:38Z', + closed_at: '2016-01-09T10:03:21Z', + mergeable: true, + base: { ref: 'third-party-base-branch' }, + head: { + label: 'other-head-branch', + sha: 'other-head-sha', + repo: partial<ght.Repo>({ full_name: mockRepo.full_name }), + }, + user: { username: 'not-renovate' }, + }), + ...mockPRs.map((pr) => ({ ...pr, user: { username: 'renovate' } })), + ]); + + const res = await gitea.getPrList(); + expect(res).toHaveLength(mockPRs.length); + expect(res).toMatchSnapshot(); + }); + it('should cache results after first query', async () => { helper.searchPRs.mockResolvedValueOnce(mockPRs); await initFakeRepo(); diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index 003b87cd3e73ac6a4d2ec6d0f8c66fcd52b159df..80d4f6733b487edc0ab5506b88af0193ac3dfcd3 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -58,6 +58,7 @@ const defaultConfigFile = configFileNames[0]; let config: GiteaRepoConfig = {} as any; let botUserID: number; +let botUserName: string; function toRenovateIssue(data: helper.Issue): Issue { return { @@ -85,6 +86,11 @@ function toRenovatePR(data: helper.PR): Pr | null { return null; } + const createdBy = data.user?.username; + if (createdBy && botUserName && createdBy !== botUserName) { + return null; + } + return { number: data.number, displayNumber: `Pull Request #${data.number}`, @@ -187,6 +193,7 @@ const platform: Platform = { const user = await helper.getCurrentUser({ token }); gitAuthor = `${user.full_name || user.username} <${user.email}>`; botUserID = user.id; + botUserName = user.username; } catch (err) { logger.debug( { err },