File tree Expand file tree Collapse file tree 3 files changed +80
-7
lines changed
packages/gitlab-backend/src/processor Expand file tree Collapse file tree 3 files changed +80
-7
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,25 @@ spec:
306
306
# ...
307
307
` ` `
308
308
309
+ It's possible to disable the GitLab plugins and cards by setting these annotations to an empty string.
310
+
311
+ This is useful if the entity (catalog-info.yaml) is hosted on GitLab but the actual source code is hosted
312
+ somewhere else or GitLab isn't used for issue tracking.
313
+
314
+ ` ` ` yaml
315
+ # Example catalog-info.yaml entity definition file
316
+ apiVersion: backstage.io/v1alpha1
317
+ kind: Component
318
+ metadata:
319
+ # ...
320
+ annotations:
321
+ gitlab.com/instance: '' # don't show the issue and merge requests cards
322
+ gitlab.com/project-slug: ''
323
+ spec:
324
+ type: service
325
+ # ...
326
+ ` ` `
327
+
309
328
# ## Code owners file
310
329
311
330
The plugins support also the `gitlab.com/codeowners-path` annotation :
Original file line number Diff line number Diff line change @@ -173,6 +173,54 @@ describe('Processor', () => {
173
173
) . toBeUndefined ( ) ;
174
174
} ) ;
175
175
176
+ it ( 'The processor does not update GITLAB_PROJECT_SLUG if the annotations GITLAB_PROJECT_ID or GITLAB_PROJECT_SLUG is empty' , async ( ) => {
177
+ const processor = new GitlabFillerProcessor ( config ) ;
178
+ const entity : Entity = {
179
+ apiVersion : 'backstage.io/v1alpha1' ,
180
+ kind : 'Component' ,
181
+ metadata : {
182
+ name : 'backstage' ,
183
+ annotations : {
184
+ [ GITLAB_PROJECT_ID ] : '' ,
185
+ } ,
186
+ } ,
187
+ } ;
188
+ await processor . postProcessEntity (
189
+ entity ,
190
+ {
191
+ type : 'url' ,
192
+ target : 'https://my.custom-gitlab.com/backstage/backstage/blob/next/catalog.yaml' ,
193
+ } ,
194
+ ( ) => undefined
195
+ ) ;
196
+
197
+ expect ( entity . metadata ?. annotations ?. [ GITLAB_PROJECT_ID ] ) . toEqual ( '' ) ;
198
+ } ) ;
199
+
200
+ it ( 'The processor does not update GITLAB_INSTANCE if the annotation is empty' , async ( ) => {
201
+ const processor = new GitlabFillerProcessor ( config ) ;
202
+ const entity : Entity = {
203
+ apiVersion : 'backstage.io/v1alpha1' ,
204
+ kind : 'Component' ,
205
+ metadata : {
206
+ name : 'backstage' ,
207
+ annotations : {
208
+ [ GITLAB_INSTANCE ] : '' ,
209
+ } ,
210
+ } ,
211
+ } ;
212
+ await processor . postProcessEntity (
213
+ entity ,
214
+ {
215
+ type : 'url' ,
216
+ target : 'https://my.custom-gitlab.com/backstage/backstage/blob/next/catalog.yaml' ,
217
+ } ,
218
+ ( ) => undefined
219
+ ) ;
220
+
221
+ expect ( entity . metadata ?. annotations ?. [ GITLAB_INSTANCE ] ) . toEqual ( '' ) ;
222
+ } ) ;
223
+
176
224
it ( 'The processor does not update annotation if the location is not a gitlab instance' , async ( ) => {
177
225
const processor = new GitlabFillerProcessor ( config ) ;
178
226
const entity : Entity = {
Original file line number Diff line number Diff line change @@ -54,18 +54,24 @@ export class GitlabFillerProcessor implements CatalogProcessor {
54
54
if ( ! entity . metadata . annotations )
55
55
entity . metadata . annotations = { } ;
56
56
57
- // Set GitLab Instance
58
- if ( ! entity . metadata . annotations ?. [ GITLAB_INSTANCE ] ) {
59
- entity . metadata . annotations ! [ GITLAB_INSTANCE ] =
57
+ // Set GitLab Instance when it's there yet, but handle an empty string as specified.
58
+ if (
59
+ ! entity . metadata . annotations [ GITLAB_INSTANCE ] &&
60
+ entity . metadata . annotations [ GITLAB_INSTANCE ] !== ''
61
+ ) {
62
+ entity . metadata . annotations [ GITLAB_INSTANCE ] =
60
63
gitlabInstanceConfig ?. host ;
61
64
}
62
65
63
- // Generate Project Slug from location URL if neither Project ID nor Project Slug are specified
66
+ // Generate Project Slug from location URL if neither Project ID nor Project Slug are specified.
67
+ // Handle empty strings as specified.
64
68
if (
65
- ! entity . metadata . annotations ?. [ GITLAB_PROJECT_ID ] &&
66
- ! entity . metadata . annotations ?. [ GITLAB_PROJECT_SLUG ]
69
+ ! entity . metadata . annotations [ GITLAB_PROJECT_ID ] &&
70
+ entity . metadata . annotations [ GITLAB_PROJECT_ID ] !== '' &&
71
+ ! entity . metadata . annotations [ GITLAB_PROJECT_SLUG ] &&
72
+ entity . metadata . annotations [ GITLAB_PROJECT_SLUG ] !== ''
67
73
) {
68
- entity . metadata . annotations ! [ GITLAB_PROJECT_SLUG ] =
74
+ entity . metadata . annotations [ GITLAB_PROJECT_SLUG ] =
69
75
getProjectPath (
70
76
location . target ,
71
77
this . getGitlabSubPath ( gitlabInstanceConfig )
You can’t perform that action at this time.
0 commit comments