Skip to content

Commit

Permalink
fix(gitea): wrong state for merged PR (#30398)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice authored Jul 26, 2024
1 parent e5f4a1e commit 6cc830a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
51 changes: 50 additions & 1 deletion lib/modules/platform/gitea/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,30 @@ describe('modules/platform/gitea/index', () => {
repo: partial<Repo>({ full_name: mockRepo.full_name }),
},
}),
partial<MockPr>({
number: 4,
title: 'Merged PR',
body: 'other random merged pull request',
state: 'closed',
diff_url: 'https://gitea.renovatebot.com/some/repo/pulls/4.diff',
created_at: '2011-08-18T22:30:38Z',
closed_at: '2016-01-09T10:03:21Z',
updated_at: '2016-01-09T10:03:21Z',
mergeable: true,
merged: true,
base: { ref: 'other-base-branch' },
head: {
label: 'merged-head-branch',
sha: 'merged-head-sha' as LongCommitSha,
repo: partial<Repo>({ full_name: mockRepo.full_name }),
},
labels: [
{
id: 1,
name: 'bug',
},
],
}),
];

const mockIssues: Issue[] = [
Expand Down Expand Up @@ -1145,6 +1169,7 @@ describe('modules/platform/gitea/index', () => {
{ number: 1, title: 'Some PR' },
{ number: 2, title: 'Other PR' },
{ number: 3, title: 'Draft PR' },
{ number: 4, title: 'Merged PR' },
]);
});

Expand Down Expand Up @@ -1187,6 +1212,7 @@ describe('modules/platform/gitea/index', () => {
{ number: 1, title: 'Some PR' },
{ number: 2, title: 'Other PR' },
{ number: 3, title: 'Draft PR' },
{ number: 4, title: 'Merged PR' },
]);
});

Expand Down Expand Up @@ -1223,7 +1249,12 @@ describe('modules/platform/gitea/index', () => {
memCache.set('gitea-pr-cache-synced', false);

const res2 = await gitea.getPrList();
expect(res2).toMatchObject([{ number: 1 }, { number: 2 }, { number: 3 }]);
expect(res2).toMatchObject([
{ number: 1 },
{ number: 2 },
{ number: 3 },
{ number: 4 },
]);
});
});

Expand Down Expand Up @@ -1403,6 +1434,24 @@ describe('modules/platform/gitea/index', () => {
});
});

it('should find merged pull request', async () => {
const scope = httpMock
.scope('https://gitea.com/api/v1')
.get('/repos/some/repo/pulls')
.query({ state: 'all', sort: 'recentupdate' })
.reply(200, mockPRs);
await initFakePlatform(scope);
await initFakeRepo(scope);

const res = await gitea.findPr({ branchName: 'merged-head-branch' });

expect(res).toMatchObject({
number: 4,
sourceBranch: 'merged-head-branch',
state: 'merged',
});
});

it('should return null for missing pull request', async () => {
const scope = httpMock
.scope('https://gitea.com/api/v1')
Expand Down
1 change: 1 addition & 0 deletions lib/modules/platform/gitea/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface PR {
title: string;
body: string;
mergeable: boolean;
merged?: boolean;
created_at: string;
updated_at: string;
closed_at: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/platform/gitea/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function toRenovatePR(data: PR, author: string | null): Pr | null {
return {
labels,
number: data.number,
state: data.state,
state: data.merged ? 'merged' : data.state,
title,
isDraft,
bodyStruct: getPrBodyStruct(data.body),
Expand Down

0 comments on commit 6cc830a

Please sign in to comment.