Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gitea): check for disabled issues #26134

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/modules/platform/gitea/gitea-helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('modules/platform/gitea/gitea-helper', () => {
push: true,
admin: false,
},
has_issues: true,
};

const otherMockRepo: Repo = {
Expand Down
29 changes: 29 additions & 0 deletions lib/modules/platform/gitea/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,13 @@ describe('modules/platform/gitea/index', () => {
});
});

describe('getIssueList', () => {
it('should return empty for disabled issues', async () => {
await initFakeRepo({ has_issues: false });
expect(await gitea.getIssueList()).toBeEmptyArray();
});
});

describe('getIssue', () => {
it('should return the issue', async () => {
const mockIssue = mockIssues.find((i) => i.number === 1)!;
Expand All @@ -1338,6 +1345,11 @@ describe('modules/platform/gitea/index', () => {
mockIssue.number,
);
});

it('should return null for disabled issues', async () => {
await initFakeRepo({ has_issues: false });
expect(await gitea.getIssue!(1)).toBeNull();
});
});

describe('findIssue', () => {
Expand Down Expand Up @@ -1657,6 +1669,18 @@ describe('modules/platform/gitea/index', () => {

expect(logger.warn).toHaveBeenCalledTimes(1);
});

it('should return null for disabled issues', async () => {
await initFakeRepo({ has_issues: false });
expect(
await gitea.ensureIssue({
title: 'new-title',
body: 'new-body',
shouldReOpen: false,
once: false,
}),
).toBeNull();
});
});

describe('ensureIssueClosing', () => {
Expand All @@ -1672,6 +1696,11 @@ describe('modules/platform/gitea/index', () => {
mockIssue.number,
);
});

it('should return for disabled issues', async () => {
await initFakeRepo({ has_issues: false });
await expect(gitea.ensureIssueClosing('new-title')).toResolve();
});
});

describe('deleteLabel', () => {
Expand Down
20 changes: 20 additions & 0 deletions lib/modules/platform/gitea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ interface GiteaRepoConfig {
labelList: Promise<Label[]> | null;
defaultBranch: string;
cloneSubmodules: boolean;
hasIssuesEnabled: boolean;
}

export const id = 'gitea';
Expand Down Expand Up @@ -334,6 +335,7 @@ const platform: Platform = {
config.prList = null;
config.issueList = null;
config.labelList = null;
config.hasIssuesEnabled = repo.has_issues;

return {
defaultBranch: config.defaultBranch,
Expand Down Expand Up @@ -655,6 +657,9 @@ const platform: Platform = {
},

getIssueList(): Promise<Issue[]> {
if (config.hasIssuesEnabled === false) {
return Promise.resolve([]);
}
if (config.issueList === null) {
config.issueList = helper
.searchIssues(config.repository, { state: 'all' }, { memCache: false })
Expand All @@ -669,6 +674,9 @@ const platform: Platform = {
},

async getIssue(number: number, memCache = true): Promise<Issue | null> {
if (config.hasIssuesEnabled === false) {
return null;
}
try {
const body = (
await helper.getIssue(config.repository, number, { memCache })
Expand Down Expand Up @@ -707,6 +715,12 @@ const platform: Platform = {
once,
}: EnsureIssueConfig): Promise<'updated' | 'created' | null> {
logger.debug(`ensureIssue(${title})`);
if (config.hasIssuesEnabled === false) {
logger.info(
'Cannot ensure issue because issues are disabled in this repository',
);
return null;
}
try {
const body = smartLinks(content);

Expand Down Expand Up @@ -819,6 +833,12 @@ const platform: Platform = {

async ensureIssueClosing(title: string): Promise<void> {
logger.debug(`ensureIssueClosing(${title})`);
if (config.hasIssuesEnabled === false) {
logger.info(
'Cannot ensure issue because issues are disabled in this repository',
);
return;
}
const issueList = await platform.getIssueList();
for (const issue of issueList) {
if (issue.state === 'open' && issue.title === title) {
Expand Down
7 changes: 7 additions & 0 deletions lib/modules/platform/gitea/schema.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ContentsListResponseSchema } from './schema';

describe('modules/platform/gitea/schema', () => {
it('ContentsResponseSchema', () => {
expect(ContentsListResponseSchema.parse([])).toBeEmptyArray();
});
});
1 change: 1 addition & 0 deletions lib/modules/platform/gitea/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface Repo {
allow_squash_merge: boolean;
archived: boolean;
clone_url?: string;
has_issues: boolean;
ssh_url?: string;
default_branch: string;
empty: boolean;
Expand Down