diff --git a/lib/platform/gitea/__snapshots__/gitea-helper.spec.ts.snap b/lib/platform/gitea/__snapshots__/gitea-helper.spec.ts.snap index f1bed54e7a155fc3caea23f8575a39c2ca080175..bf1ff386c24781517d551331453a70c862f253fe 100644 --- a/lib/platform/gitea/__snapshots__/gitea-helper.spec.ts.snap +++ b/lib/platform/gitea/__snapshots__/gitea-helper.spec.ts.snap @@ -1,5 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`platform/gitea/gitea-helper addReviewers should call /api/v1/repos/[repo]/pulls/[pull]/requested_reviewers endpoint 1`] = ` +Array [ + Object { + "body": "{}", + "headers": Object { + "accept": "application/json", + "accept-encoding": "gzip, deflate", + "content-length": "2", + "content-type": "application/json", + "host": "gitea.renovatebot.com", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "POST", + "url": "https://gitea.renovatebot.com/api/v1/repos/some/repo/pulls/13/requested_reviewers", + }, +] +`; + exports[`platform/gitea/gitea-helper closeIssue should call /api/v1/repos/[repo]/issues/[issue] endpoint 1`] = ` Array [ Object { diff --git a/lib/platform/gitea/gitea-helper.spec.ts b/lib/platform/gitea/gitea-helper.spec.ts index c57615537ad45b9a8a837ad5d4b85abb35829d47..7b588e6fb02e7473754904cfe39da0ae6e6971ba 100644 --- a/lib/platform/gitea/gitea-helper.spec.ts +++ b/lib/platform/gitea/gitea-helper.spec.ts @@ -371,6 +371,20 @@ describe('platform/gitea/gitea-helper', () => { }); }); + describe('addReviewers', () => { + it('should call /api/v1/repos/[repo]/pulls/[pull]/requested_reviewers endpoint', async () => { + httpMock + .scope(baseUrl) + .post( + `/repos/${mockRepo.full_name}/pulls/${mockPR.number}/requested_reviewers` + ) + .reply(200); + + await ght.requestPrReviewers(mockRepo.full_name, mockPR.number, {}); + expect(httpMock.getTrace()).toMatchSnapshot(); + }); + }); + describe('searchPRs', () => { it('should call /api/v1/repos/[repo]/pulls endpoint', async () => { httpMock diff --git a/lib/platform/gitea/gitea-helper.ts b/lib/platform/gitea/gitea-helper.ts index ed91a3f7992c9ce6c01863c37d1e81da30e5775e..592aacd0e4e428fa29ef3d2780b3d1a397c7532b 100644 --- a/lib/platform/gitea/gitea-helper.ts +++ b/lib/platform/gitea/gitea-helper.ts @@ -1,6 +1,7 @@ import { URLSearchParams } from 'url'; import { BranchStatus, PrState } from '../../types'; import { GiteaHttp, GiteaHttpOptions } from '../../util/http/gitea'; +import { PrReviewersParams } from './types'; const giteaHttp = new GiteaHttp(); @@ -323,6 +324,19 @@ export async function getPR( return res.body; } +export async function requestPrReviewers( + repoPath: string, + idx: number, + params: PrReviewersParams, + options?: GiteaHttpOptions +): Promise<void> { + const url = `repos/${repoPath}/pulls/${idx}/requested_reviewers`; + await giteaHttp.postJson(url, { + ...options, + body: params, + }); +} + export async function searchPRs( repoPath: string, params: PRSearchParams, diff --git a/lib/platform/gitea/index.spec.ts b/lib/platform/gitea/index.spec.ts index 090bd901a753b3dac23cc7f91ba759a39b292f3d..146dda9c666cf9003a25d95ff2ae40a5fa228452 100644 --- a/lib/platform/gitea/index.spec.ts +++ b/lib/platform/gitea/index.spec.ts @@ -1294,11 +1294,22 @@ describe('platform/gitea', () => { }); describe('addReviewers', () => { - it('should do nothing - unsupported by platform', async () => { + it('should assign reviewers', async () => { + expect.assertions(2); const mockPR = mockPRs[0]; await expect( gitea.addReviewers(mockPR.number, ['me', 'you']) ).resolves.not.toThrow(); + + expect(helper.requestPrReviewers).toHaveBeenCalledTimes(1); + }); + it('catches errors', async () => { + expect.assertions(1); + const mockPR = mockPRs[0]; + helper.requestPrReviewers.mockRejectedValueOnce(null); + await expect( + gitea.addReviewers(mockPR.number, ['me', 'you']) + ).resolves.not.toThrow(); }); }); diff --git a/lib/platform/gitea/index.ts b/lib/platform/gitea/index.ts index d3981b9913ebfab5938b4cdbd12a2810d3cffb40..a028bf8ed203b41e0bba1c1120a56213f8bd1ada 100644 --- a/lib/platform/gitea/index.ts +++ b/lib/platform/gitea/index.ts @@ -791,14 +791,13 @@ const platform: Platform = { }); }, - addReviewers(number: number, reviewers: string[]): Promise<void> { - // Adding reviewers to a PR through API is not supported by Gitea as of today - // See tracking issue: https://github.com/go-gitea/gitea/issues/5733 - logger.debug( - `Updating reviewers '${reviewers?.join(', ')}' on Pull Request #${number}` - ); - logger.warn('Unimplemented in Gitea: Reviewers'); - return Promise.resolve(); + async addReviewers(number: number, reviewers: string[]): Promise<void> { + logger.debug(`Adding reviewers '${reviewers?.join(', ')}' to #${number}`); + try { + await helper.requestPrReviewers(config.repository, number, { reviewers }); + } catch (err) { + logger.warn({ err, number, reviewers }, 'Failed to assign reviewer'); + } }, getPrBody(prBody: string): string { diff --git a/lib/platform/gitea/types.ts b/lib/platform/gitea/types.ts new file mode 100644 index 0000000000000000000000000000000000000000..9505586dfc05ab4f80077866fbca378ff970132b --- /dev/null +++ b/lib/platform/gitea/types.ts @@ -0,0 +1,4 @@ +export type PrReviewersParams = { + reviewers?: string[]; + team_reviewers?: string[]; +};