@@ -3,6 +3,7 @@ import { toUnixPath } from '../transform';
3
3
import {
4
4
formatFileLink ,
5
5
formatGitHubLink ,
6
+ formatGitLabLink ,
6
7
formatSourceLine ,
7
8
linkToLocalSourceForIde ,
8
9
metaDescription ,
@@ -226,6 +227,57 @@ describe('formatGitHubLink', () => {
226
227
} ) ;
227
228
} ) ;
228
229
230
+ describe ( 'formatGitLabLink' , ( ) => {
231
+ beforeEach ( ( ) => {
232
+ vi . stubEnv ( 'TERM_PROGRAM' , '' ) ;
233
+ vi . stubEnv ( 'GITHUB_ACTIONS' , 'false' ) ;
234
+ vi . stubEnv ( 'GITLAB_CI' , 'true' ) ;
235
+ vi . stubEnv ( 'CI_SERVER_URL' , 'https://gitlab.com' ) ;
236
+ vi . stubEnv ( 'CI_PROJECT_PATH' , 'user/repo' ) ;
237
+ vi . stubEnv ( 'CI_COMMIT_SHA' , '1234567890abcdef' ) ;
238
+ } ) ;
239
+
240
+ it . each ( [
241
+ [
242
+ { startLine : 2 } ,
243
+ 'https://gitlab.com/user/repo/-/blob/1234567890abcdef/src/index.ts#L2' ,
244
+ ] ,
245
+ [
246
+ { startLine : 2 , endLine : 5 } ,
247
+ 'https://gitlab.com/user/repo/-/blob/1234567890abcdef/src/index.ts#L2-5' ,
248
+ ] ,
249
+ [
250
+ { startLine : 2 , startColumn : 1 } ,
251
+ 'https://gitlab.com/user/repo/-/blob/1234567890abcdef/src/index.ts#L2' ,
252
+ ] ,
253
+ [
254
+ { startLine : 2 , endLine : 2 , startColumn : 1 , endColumn : 5 } ,
255
+ 'https://gitlab.com/user/repo/-/blob/1234567890abcdef/src/index.ts#L2' ,
256
+ ] ,
257
+ [
258
+ { startLine : 2 , endLine : 5 , startColumn : 1 , endColumn : 6 } ,
259
+ 'https://gitlab.com/user/repo/-/blob/1234567890abcdef/src/index.ts#L2-5' ,
260
+ ] ,
261
+ [
262
+ { startLine : 2 , endLine : 2 , startColumn : 1 , endColumn : 1 } ,
263
+ 'https://gitlab.com/user/repo/-/blob/1234567890abcdef/src/index.ts#L2' ,
264
+ ] ,
265
+ ] ) (
266
+ 'should generate a GitLab repository link for the file with position %o' ,
267
+ ( position , expected ) => {
268
+ expect ( formatGitLabLink ( toUnixPath ( 'src/index.ts' ) , position ) ) . toBe (
269
+ expected ,
270
+ ) ;
271
+ } ,
272
+ ) ;
273
+
274
+ it ( 'should generate a GitLab repository link for the file when the position is undefined' , ( ) => {
275
+ expect ( formatGitLabLink ( toUnixPath ( 'src/index.ts' ) , undefined ) ) . toBe (
276
+ 'https://gitlab.com/user/repo/-/blob/1234567890abcdef/src/index.ts' ,
277
+ ) ;
278
+ } ) ;
279
+ } ) ;
280
+
229
281
describe ( 'formatFileLink' , ( ) => {
230
282
it ( 'should return a GitHub repository link when running in GitHub Actions' , ( ) => {
231
283
vi . stubEnv ( 'TERM_PROGRAM' , '' ) ;
@@ -245,6 +297,25 @@ describe('formatFileLink', () => {
245
297
) ;
246
298
} ) ;
247
299
300
+ it ( 'should return a GitLab repository link when running in GitLab CI/CD' , ( ) => {
301
+ vi . stubEnv ( 'TERM_PROGRAM' , '' ) ;
302
+ vi . stubEnv ( 'GITHUB_ACTIONS' , 'false' ) ;
303
+ vi . stubEnv ( 'GITLAB_CI' , 'true' ) ;
304
+ vi . stubEnv ( 'CI_SERVER_URL' , 'https://gitlab.com' ) ;
305
+ vi . stubEnv ( 'CI_PROJECT_PATH' , 'user/repo' ) ;
306
+ vi . stubEnv ( 'CI_COMMIT_SHA' , '1234567890abcdef' ) ;
307
+
308
+ expect (
309
+ formatFileLink (
310
+ toUnixPath ( 'src/index.ts' ) ,
311
+ { startLine : 2 } ,
312
+ toUnixPath ( '.code-pushup' ) ,
313
+ ) ,
314
+ ) . toBe (
315
+ `https://gitlab.com/user/repo/-/blob/1234567890abcdef/src/index.ts#L2` ,
316
+ ) ;
317
+ } ) ;
318
+
248
319
it . each ( [
249
320
[ { startLine : 2 } , '../src/index.ts#L2' ] ,
250
321
[ { startLine : 2 , endLine : 5 } , '../src/index.ts#L2' ] ,
@@ -276,9 +347,10 @@ describe('formatFileLink', () => {
276
347
) . toBe ( '../src/index.ts' ) ;
277
348
} ) ;
278
349
279
- it ( 'should return a relative file path when the environment is neither VS Code nor GitHub' , ( ) => {
350
+ it ( 'should return a relative file path when the environment is neither VS Code nor GitHub, nor GitLab ' , ( ) => {
280
351
vi . stubEnv ( 'TERM_PROGRAM' , '' ) ;
281
352
vi . stubEnv ( 'GITHUB_ACTIONS' , 'false' ) ;
353
+ vi . stubEnv ( 'GITLAB_CI' , 'false' ) ;
282
354
expect (
283
355
formatFileLink (
284
356
toUnixPath ( 'src/index.ts' ) ,
0 commit comments