Loading src/gitlab/gitlab_service.test.ts +16 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ import { DEFAULT_FETCH_RESPONSE } from '../__mocks__/cross-fetch'; import { CustomQueryType } from './custom_query_type'; import { CustomQuery } from './custom_query'; import { asMock } from '../test_utils/as_mock'; import { externalStatus, gqlProject, project } from '../test_utils/entities'; import { externalStatus, gqlProject, mr, pipeline, project } from '../test_utils/entities'; import { getExtensionConfiguration } from '../utils/extension_configuration'; import { getHttpAgentOptions } from './http/get_http_agent_options'; import { HelpError } from '../errors/help_error'; Loading Loading @@ -134,6 +134,21 @@ describe('gitlab_service', () => { }); }); describe('getLastPipelineForMr', () => { it('returns pipeline with largest iid', async () => { asMock(crossFetch).mockReturnValue( crossFetchResponse([ { ...pipeline, iid: 1 }, { ...pipeline, iid: 2 }, ]), ); const result = await service.getLastPipelineForMr(mr); expect(result!.iid).toBe(2); }); }); describe('getFile', () => { it('constructs the correct URL', async () => { await service.getFile('foo', 'bar', 12345); Loading src/gitlab/gitlab_service.ts +4 −1 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ import { HelpError } from '../errors/help_error'; import { Credentials } from '../accounts/credentials'; import { newCreateNoteMutation, oldCreateNoteMutation } from './graphql/create_note'; import { createQueryString, QueryValue } from '../utils/create_query_string'; import { sort } from '../utils/sort'; interface CreateNoteResult { createNote: { Loading Loading @@ -936,7 +937,9 @@ export class GitLabService { {}, 'pipelines for MR', ); return pipelines[0]; // the sort is a fix for an ordering issue https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/issues/569 // the sort can be removed once https://gitlab.com/gitlab-org/gitlab/-/issues/344853 is fixed return sort(pipelines, (p1, p2) => p2.iid - p1.iid)[0]; } async getOpenMergeRequestForCurrentBranch( Loading src/test_utils/entities.ts +1 −0 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ export const pipeline: RestPipeline = { status: 'success', updated_at: '2021-02-12T12:06:17Z', id: 123456, iid: 1, project_id: 567890, sha: 'aaaaaaaa', ref: 'main', Loading src/types.d.ts +1 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ interface RestPipeline { | 'preparing'; updated_at: string; id: number; iid: number; ref: string | null; sha: string; /** Loading Loading
src/gitlab/gitlab_service.test.ts +16 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ import { DEFAULT_FETCH_RESPONSE } from '../__mocks__/cross-fetch'; import { CustomQueryType } from './custom_query_type'; import { CustomQuery } from './custom_query'; import { asMock } from '../test_utils/as_mock'; import { externalStatus, gqlProject, project } from '../test_utils/entities'; import { externalStatus, gqlProject, mr, pipeline, project } from '../test_utils/entities'; import { getExtensionConfiguration } from '../utils/extension_configuration'; import { getHttpAgentOptions } from './http/get_http_agent_options'; import { HelpError } from '../errors/help_error'; Loading Loading @@ -134,6 +134,21 @@ describe('gitlab_service', () => { }); }); describe('getLastPipelineForMr', () => { it('returns pipeline with largest iid', async () => { asMock(crossFetch).mockReturnValue( crossFetchResponse([ { ...pipeline, iid: 1 }, { ...pipeline, iid: 2 }, ]), ); const result = await service.getLastPipelineForMr(mr); expect(result!.iid).toBe(2); }); }); describe('getFile', () => { it('constructs the correct URL', async () => { await service.getFile('foo', 'bar', 12345); Loading
src/gitlab/gitlab_service.ts +4 −1 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ import { HelpError } from '../errors/help_error'; import { Credentials } from '../accounts/credentials'; import { newCreateNoteMutation, oldCreateNoteMutation } from './graphql/create_note'; import { createQueryString, QueryValue } from '../utils/create_query_string'; import { sort } from '../utils/sort'; interface CreateNoteResult { createNote: { Loading Loading @@ -936,7 +937,9 @@ export class GitLabService { {}, 'pipelines for MR', ); return pipelines[0]; // the sort is a fix for an ordering issue https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/issues/569 // the sort can be removed once https://gitlab.com/gitlab-org/gitlab/-/issues/344853 is fixed return sort(pipelines, (p1, p2) => p2.iid - p1.iid)[0]; } async getOpenMergeRequestForCurrentBranch( Loading
src/test_utils/entities.ts +1 −0 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ export const pipeline: RestPipeline = { status: 'success', updated_at: '2021-02-12T12:06:17Z', id: 123456, iid: 1, project_id: 567890, sha: 'aaaaaaaa', ref: 'main', Loading
src/types.d.ts +1 −0 Original line number Diff line number Diff line Loading @@ -72,6 +72,7 @@ interface RestPipeline { | 'preparing'; updated_at: string; id: number; iid: number; ref: string | null; sha: string; /** Loading