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

feat(gitea): Add PR cache #26451

Merged
merged 12 commits into from
Jan 15, 2024
29 changes: 1 addition & 28 deletions lib/modules/platform/gitea/gitea-helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
mergePR,
requestPrReviewers,
searchIssues,
searchPRs,
searchRepos,
unassignLabel,
updateComment,
Expand Down Expand Up @@ -124,6 +123,7 @@ describe('modules/platform/gitea/gitea-helper', () => {
},
created_at: '2018-08-13T20:45:37Z',
closed_at: '2020-04-01T19:19:22Z',
updated_at: '2020-04-01T19:19:22Z',
};

const mockIssue: Issue = {
Expand Down Expand Up @@ -423,33 +423,6 @@ describe('modules/platform/gitea/gitea-helper', () => {
});
});

describe('searchPRs', () => {
it('should call /api/v1/repos/[repo]/pulls endpoint', async () => {
httpMock
.scope(baseUrl)
.get(`/repos/${mockRepo.full_name}/pulls`)
.reply(200, [mockPR]);

const res = await searchPRs(mockRepo.full_name, {});
expect(res).toEqual([mockPR]);
});

it('should construct proper query parameters', async () => {
httpMock
.scope(baseUrl)
.get(
`/repos/${mockRepo.full_name}/pulls?state=open&labels=${mockLabel.id}&labels=${otherMockLabel.id}`,
)
.reply(200, [mockPR]);

const res = await searchPRs(mockRepo.full_name, {
state: 'open',
labels: [mockLabel.id, otherMockLabel.id],
});
expect(res).toEqual([mockPR]);
});
});

describe('createIssue', () => {
it('should call /api/v1/repos/[repo]/issues endpoint', async () => {
httpMock
Expand Down
21 changes: 2 additions & 19 deletions lib/modules/platform/gitea/gitea-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
PR,
PRCreateParams,
PRMergeParams,
PRSearchParams,
PRUpdateParams,
PrReviewersParams,
Repo,
Expand All @@ -28,10 +27,9 @@ import type {
RepoSearchResults,
User,
} from './types';
import { API_PATH } from './utils';

const giteaHttp = new GiteaHttp();

const API_PATH = '/api/v1';
export const giteaHttp = new GiteaHttp();

const urlEscape = (raw: string): string => encodeURIComponent(raw);
const commitStatusStates: CommitStatusType[] = [
Expand Down Expand Up @@ -181,21 +179,6 @@ export async function requestPrReviewers(
});
}

export async function searchPRs(
repoPath: string,
params: PRSearchParams,
options?: GiteaHttpOptions,
): Promise<PR[]> {
const query = getQueryString(params);
const url = `${API_PATH}/repos/${repoPath}/pulls?${query}`;
const res = await giteaHttp.getJson<PR[]>(url, {
...options,
paginate: true,
});

return res.body;
}

export async function createIssue(
repoPath: string,
params: IssueCreateParams,
Expand Down
Loading