Skip to content

Commit

Permalink
feat(gitea): Add PR cache (renovatebot#26451)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <[email protected]>
  • Loading branch information
2 people authored and zT-1337 committed Jan 22, 2024
1 parent 966f4a4 commit 0ddedd0
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 162 deletions.
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

0 comments on commit 0ddedd0

Please sign in to comment.