Skip to content

Commit

Permalink
Merge pull request #611 from immobiliare/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
antoniomuso authored Oct 18, 2024
2 parents 4a72cae + 3e72141 commit 0c50aeb
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,25 @@ spec:
# ...
```

It's possible to disable the GitLab plugins and cards by setting these annotations to an empty string.

This is useful if the entity (catalog-info.yaml) is hosted on GitLab but the actual source code is hosted
somewhere else or GitLab isn't used for issue tracking.

```yaml
# Example catalog-info.yaml entity definition file
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
# ...
annotations:
gitlab.com/instance: '' # don't show the issue and merge requests cards
gitlab.com/project-slug: ''
spec:
type: service
# ...
```

### Code owners file

The plugins support also the `gitlab.com/codeowners-path` annotation:
Expand Down
48 changes: 48 additions & 0 deletions packages/gitlab-backend/src/processor/processor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,54 @@ describe('Processor', () => {
).toBeUndefined();
});

it('The processor does not update GITLAB_PROJECT_SLUG if the annotations GITLAB_PROJECT_ID or GITLAB_PROJECT_SLUG is empty', async () => {
const processor = new GitlabFillerProcessor(config);
const entity: Entity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
metadata: {
name: 'backstage',
annotations: {
[GITLAB_PROJECT_ID]: '',
},
},
};
await processor.postProcessEntity(
entity,
{
type: 'url',
target: 'https://my.custom-gitlab.com/backstage/backstage/blob/next/catalog.yaml',
},
() => undefined
);

expect(entity.metadata?.annotations?.[GITLAB_PROJECT_ID]).toEqual('');
});

it('The processor does not update GITLAB_INSTANCE if the annotation is empty', async () => {
const processor = new GitlabFillerProcessor(config);
const entity: Entity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'Component',
metadata: {
name: 'backstage',
annotations: {
[GITLAB_INSTANCE]: '',
},
},
};
await processor.postProcessEntity(
entity,
{
type: 'url',
target: 'https://my.custom-gitlab.com/backstage/backstage/blob/next/catalog.yaml',
},
() => undefined
);

expect(entity.metadata?.annotations?.[GITLAB_INSTANCE]).toEqual('');
});

it('The processor does not update annotation if the location is not a gitlab instance', async () => {
const processor = new GitlabFillerProcessor(config);
const entity: Entity = {
Expand Down
20 changes: 13 additions & 7 deletions packages/gitlab-backend/src/processor/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,24 @@ export class GitlabFillerProcessor implements CatalogProcessor {
if (!entity.metadata.annotations)
entity.metadata.annotations = {};

// Set GitLab Instance
if (!entity.metadata.annotations?.[GITLAB_INSTANCE]) {
entity.metadata.annotations![GITLAB_INSTANCE] =
// Set GitLab Instance when it's there yet, but handle an empty string as specified.
if (
!entity.metadata.annotations[GITLAB_INSTANCE] &&
entity.metadata.annotations[GITLAB_INSTANCE] !== ''
) {
entity.metadata.annotations[GITLAB_INSTANCE] =
gitlabInstanceConfig?.host;
}

// Generate Project Slug from location URL if neither Project ID nor Project Slug are specified
// Generate Project Slug from location URL if neither Project ID nor Project Slug are specified.
// Handle empty strings as specified.
if (
!entity.metadata.annotations?.[GITLAB_PROJECT_ID] &&
!entity.metadata.annotations?.[GITLAB_PROJECT_SLUG]
!entity.metadata.annotations[GITLAB_PROJECT_ID] &&
entity.metadata.annotations[GITLAB_PROJECT_ID] !== '' &&
!entity.metadata.annotations[GITLAB_PROJECT_SLUG] &&
entity.metadata.annotations[GITLAB_PROJECT_SLUG] !== ''
) {
entity.metadata.annotations![GITLAB_PROJECT_SLUG] =
entity.metadata.annotations[GITLAB_PROJECT_SLUG] =
getProjectPath(
location.target,
this.getGitlabSubPath(gitlabInstanceConfig)
Expand Down

0 comments on commit 0c50aeb

Please sign in to comment.