Skip to content

Commit 0c50aeb

Browse files
authored
Merge pull request #611 from immobiliare/next
Next
2 parents 4a72cae + 3e72141 commit 0c50aeb

File tree

3 files changed

+80
-7
lines changed

3 files changed

+80
-7
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,25 @@ spec:
306306
# ...
307307
```
308308

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+
309328
### Code owners file
310329

311330
The plugins support also the `gitlab.com/codeowners-path` annotation:

packages/gitlab-backend/src/processor/processor.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,54 @@ describe('Processor', () => {
173173
).toBeUndefined();
174174
});
175175

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+
176224
it('The processor does not update annotation if the location is not a gitlab instance', async () => {
177225
const processor = new GitlabFillerProcessor(config);
178226
const entity: Entity = {

packages/gitlab-backend/src/processor/processor.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,24 @@ export class GitlabFillerProcessor implements CatalogProcessor {
5454
if (!entity.metadata.annotations)
5555
entity.metadata.annotations = {};
5656

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] =
6063
gitlabInstanceConfig?.host;
6164
}
6265

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.
6468
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] !== ''
6773
) {
68-
entity.metadata.annotations![GITLAB_PROJECT_SLUG] =
74+
entity.metadata.annotations[GITLAB_PROJECT_SLUG] =
6975
getProjectPath(
7076
location.target,
7177
this.getGitlabSubPath(gitlabInstanceConfig)

0 commit comments

Comments
 (0)