Skip to content

Commit

Permalink
feat(platform/gitea): support new forgejo versioning schema (#28492)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceice committed Apr 18, 2024
1 parent 3392179 commit 0858ccb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
59 changes: 59 additions & 0 deletions lib/modules/platform/gitea/index.spec.ts
Expand Up @@ -1593,6 +1593,8 @@ describe('modules/platform/gitea/index', () => {

it('should use platform automerge', async () => {
memCache.set('gitea-pr-cache-synced', true);
const helper = await import('./gitea-helper');
const mergePR = jest.spyOn(helper, 'mergePR');
const scope = httpMock
.scope('https://gitea.com/api/v1')
.post('/repos/some/repo/pulls')
Expand All @@ -1614,6 +1616,63 @@ describe('modules/platform/gitea/index', () => {
number: 42,
title: 'pr-title',
});
expect(mergePR).toHaveBeenCalled();
});

it('should use platform automerge on forgejo v7', async () => {
memCache.set('gitea-pr-cache-synced', true);
const helper = await import('./gitea-helper');
const mergePR = jest.spyOn(helper, 'mergePR');
const scope = httpMock
.scope('https://gitea.com/api/v1')
.post('/repos/some/repo/pulls')
.reply(200, mockNewPR)
.post('/repos/some/repo/pulls/42/merge')
.reply(200);
await initFakePlatform(scope, '7.0.0-dev-2136-f075579c95+gitea-1.22.0');
await initFakeRepo(scope);

const res = await gitea.createPr({
sourceBranch: mockNewPR.head.label,
targetBranch: 'master',
prTitle: mockNewPR.title,
prBody: mockNewPR.body,
platformOptions: { usePlatformAutomerge: true },
});

expect(res).toMatchObject({
number: 42,
title: 'pr-title',
});
expect(mergePR).toHaveBeenCalled();
});

it('should use platform automerge on forgejo v7 LTS', async () => {
memCache.set('gitea-pr-cache-synced', true);
const helper = await import('./gitea-helper');
const mergePR = jest.spyOn(helper, 'mergePR');
const scope = httpMock
.scope('https://gitea.com/api/v1')
.post('/repos/some/repo/pulls')
.reply(200, mockNewPR)
.post('/repos/some/repo/pulls/42/merge')
.reply(200);
await initFakePlatform(scope, '7.0.0+LTS-gitea-1.22.0');
await initFakeRepo(scope);

const res = await gitea.createPr({
sourceBranch: mockNewPR.head.label,
targetBranch: 'master',
prTitle: mockNewPR.title,
prBody: mockNewPR.body,
platformOptions: { usePlatformAutomerge: true },
});

expect(res).toMatchObject({
number: 42,
title: 'pr-title',
});
expect(mergePR).toHaveBeenCalled();
});

it('continues on platform automerge error', async () => {
Expand Down
7 changes: 7 additions & 0 deletions lib/modules/platform/gitea/index.ts
Expand Up @@ -78,6 +78,7 @@ const defaults = {
hostType: 'gitea',
endpoint: 'https://gitea.com/',
version: '0.0.0',
isForgejo: false,
};

let config: GiteaRepoConfig = {} as any;
Expand Down Expand Up @@ -200,6 +201,12 @@ const platform: Platform = {
botUserID = user.id;
botUserName = user.username;
defaults.version = await helper.getVersion({ token });
if (defaults.version?.includes('gitea-')) {
defaults.version = defaults.version.substring(
defaults.version.indexOf('gitea-') + 6,
);
defaults.isForgejo = true;
}
} catch (err) {
logger.debug(
{ err },
Expand Down

0 comments on commit 0858ccb

Please sign in to comment.