feat(web): filter GitLab merge requests by source branch
This commit is contained in:
@@ -105,6 +105,46 @@ describe('createWebGitLabAPI', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('passes sourceBranch query param to mrsList', async () => {
|
||||
const result = {
|
||||
connected: true,
|
||||
repo: null,
|
||||
mrs: [],
|
||||
page: 1,
|
||||
hasMore: false,
|
||||
};
|
||||
runtimeFetchMock.mockResolvedValueOnce(Response.json(result));
|
||||
|
||||
const api = await createAPI();
|
||||
await expect(api.mrsList('/workspace', { page: 1, query: 'search', sourceBranch: 'feat/api' })).resolves.toEqual(result);
|
||||
|
||||
const params = new URLSearchParams({ directory: '/workspace', page: '1', query: 'search', sourceBranch: 'feat/api' });
|
||||
expect(runtimeFetchMock).toHaveBeenCalledWith(`/api/gitlab/mrs/list?${params.toString()}`, {
|
||||
method: 'GET',
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
});
|
||||
|
||||
it('omits sourceBranch when not provided to mrsList', async () => {
|
||||
const result = {
|
||||
connected: true,
|
||||
repo: null,
|
||||
mrs: [],
|
||||
page: 1,
|
||||
hasMore: false,
|
||||
};
|
||||
runtimeFetchMock.mockResolvedValueOnce(Response.json(result));
|
||||
|
||||
const api = await createAPI();
|
||||
await expect(api.mrsList('/workspace', { page: 1 })).resolves.toEqual(result);
|
||||
|
||||
const params = new URLSearchParams({ directory: '/workspace', page: '1' });
|
||||
expect(runtimeFetchMock).toHaveBeenCalledWith(`/api/gitlab/mrs/list?${params.toString()}`, {
|
||||
method: 'GET',
|
||||
headers: { Accept: 'application/json' },
|
||||
});
|
||||
});
|
||||
|
||||
it('throws the server error message on {error} payloads', async () => {
|
||||
runtimeFetchMock.mockResolvedValueOnce(Response.json({ error: 'Not connected to GitLab' }, { status: 401 }));
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ export const createWebGitLabAPI = ({ urls }: WebGitLabAPIOptions): GitLabAPI =>
|
||||
return payload;
|
||||
},
|
||||
|
||||
async mrsList(directory: string, options?: { page?: number; query?: string }): Promise<GitLabMergeRequestsListResult> {
|
||||
async mrsList(directory: string, options?: { page?: number; query?: string; sourceBranch?: string }): Promise<GitLabMergeRequestsListResult> {
|
||||
const page = options?.page ?? 1;
|
||||
const params = new URLSearchParams({
|
||||
directory,
|
||||
@@ -138,6 +138,9 @@ export const createWebGitLabAPI = ({ urls }: WebGitLabAPIOptions): GitLabAPI =>
|
||||
if (options?.query) {
|
||||
params.set('query', options.query);
|
||||
}
|
||||
if (options?.sourceBranch) {
|
||||
params.set('sourceBranch', options.sourceBranch);
|
||||
}
|
||||
const response = await runtimeFetch(
|
||||
`/api/gitlab/mrs/list?${params.toString()}`,
|
||||
{ method: 'GET', headers: { Accept: 'application/json' } }
|
||||
|
||||
Reference in New Issue
Block a user