Merge pull request #9621 from backstage/rugvip/loco

catalog-backend: deprecated location result optional flag
This commit is contained in:
Patrik Oldsberg
2022-02-18 13:48:43 +01:00
committed by GitHub
15 changed files with 67 additions and 96 deletions
+23
View File
@@ -0,0 +1,23 @@
---
'@backstage/plugin-catalog-backend': patch
---
Deprecated the second parameter of `results.location()` that determines whether an emitted location is optional. In cases where this is currently being set to `false`, the parameter can simply be dropped, as that is the default. Usage where this was being set to `true` should be migrated to set the `presence` option of the emitted location to `optional`. For example:
```ts
results.location(
{
type: 'url',
target: 'http://example.com/foo',
},
true,
);
// migrated to
results.location({
type: 'url',
target: 'http://example.com/foo',
presence: 'optional',
});
```
+2 -2
View File
@@ -430,7 +430,7 @@ export type CatalogProcessorErrorResult = {
export type CatalogProcessorLocationResult = {
type: 'location';
location: LocationSpec;
optional: boolean;
optional?: boolean;
};
// Warning: (ae-missing-release-tag) "CatalogProcessorParser" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
@@ -903,7 +903,7 @@ function inputError(
// @public (undocumented)
function location_2(
newLocation: LocationSpec,
optional: boolean,
optional?: boolean,
): CatalogProcessorResult;
// Warning: (ae-missing-release-tag) "LocationAnalyzer" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
@@ -167,7 +167,6 @@ describe('AzureDevOpsDiscoveryProcessor', () => {
'https://dev.azure.com/shopify/engineering/_git/backstage?path=/catalog-info.yaml',
presence: 'optional',
},
optional: true,
});
expect(emitter).toHaveBeenCalledWith({
type: 'location',
@@ -177,7 +176,6 @@ describe('AzureDevOpsDiscoveryProcessor', () => {
'https://dev.azure.com/shopify/engineering/_git/ios-app?path=/src/catalog-info.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -215,7 +213,6 @@ describe('AzureDevOpsDiscoveryProcessor', () => {
'https://dev.azure.com/shopify/engineering/_git/backstage?path=/catalog-info.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -254,7 +251,6 @@ describe('AzureDevOpsDiscoveryProcessor', () => {
'https://dev.azure.com/shopify/engineering/_git/backstage?path=/src/main/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -101,17 +101,14 @@ export class AzureDevOpsDiscoveryProcessor implements CatalogProcessor {
for (const file of files) {
emit(
results.location(
{
type: 'url',
target: `${baseUrl}/${org}/${project}/_git/${file.repository.name}?path=${file.path}`,
presence: 'optional',
},
results.location({
type: 'url',
target: `${baseUrl}/${org}/${project}/_git/${file.repository.name}?path=${file.path}`,
// Not all locations may actually exist, since the user defined them as a wildcard pattern.
// Thus, we emit them as optional and let the downstream processor find them while not outputting
// an error if it couldn't.
true,
),
presence: 'optional',
}),
);
}
@@ -210,7 +210,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.mycompany.com/projects/backstage/repos/backstage/browse/catalog.yaml',
presence: 'optional',
},
optional: true,
});
expect(emitter).toHaveBeenCalledWith({
type: 'location',
@@ -220,7 +219,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.mycompany.com/projects/demo/repos/demo/browse/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -246,7 +244,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.mycompany.com/projects/backstage/repos/techdocs-cli/browse/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -269,7 +266,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.mycompany.com/projects/demo/repos/demo/browse/catalog.yaml?ref=branch-name',
presence: 'optional',
},
optional: true,
});
});
@@ -292,7 +288,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.mycompany.com/projects/backstage/repos/test/browse/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -321,7 +316,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.mycompany.com/projects/backstage/repos/techdocs-cli/browse/catalog-info.yaml',
presence: 'optional',
},
optional: true,
});
});
});
@@ -369,7 +363,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.mycompany.com/custom-path/projects/backstage/repos/backstage/browse/catalog.yaml',
presence: 'optional',
},
optional: true,
});
expect(emitter).toHaveBeenCalledWith({
type: 'location',
@@ -379,7 +372,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.mycompany.com/custom-path/projects/demo/repos/demo/browse/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -408,7 +400,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.mycompany.com/custom-path/projects/backstage/repos/techdocs-cli/browse/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -434,7 +425,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.mycompany.com/custom-path/projects/demo/repos/demo/browse/catalog.yaml?ref=branch-name',
presence: 'optional',
},
optional: true,
});
});
@@ -460,7 +450,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.mycompany.com/custom-path/projects/backstage/repos/test/browse/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -492,7 +481,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.mycompany.com/custom-path/projects/backstage/repos/techdocs-cli/browse/catalog-info.yaml',
presence: 'optional',
},
optional: true,
});
});
});
@@ -536,7 +524,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.org/myworkspace/repository-one/src/master/catalog-info.yaml',
presence: 'optional',
},
optional: true,
});
expect(emitter).toHaveBeenCalledWith({
type: 'location',
@@ -546,7 +533,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.org/myworkspace/repository-two/src/master/catalog-info.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -574,7 +560,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.org/myworkspace/repository-one/src/master/my/nested/path/catalog.yaml',
presence: 'optional',
},
optional: true,
});
expect(emitter).toHaveBeenCalledWith({
type: 'location',
@@ -584,7 +569,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.org/myworkspace/repository-two/src/master/my/nested/path/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -612,7 +596,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.org/myworkspace/repository-one/src/master/catalog.yaml',
presence: 'optional',
},
optional: true,
});
expect(emitter).toHaveBeenCalledWith({
type: 'location',
@@ -622,7 +605,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.org/myworkspace/repository-two/src/master/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -649,7 +631,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.org/myworkspace/repository-one/src/master/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -677,7 +658,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.org/myworkspace/repository-three/src/master/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -703,7 +683,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.org/myworkspace/repository-one/src/master/catalog-info.yaml',
presence: 'optional',
},
optional: true,
});
expect(mockCall).toBeCalledTimes(1);
// it should be possible to do this via an `expect.objectContaining` check but seems to fail with some encoding issue.
@@ -739,7 +718,6 @@ describe('BitbucketDiscoveryProcessor', () => {
'https://bitbucket.org/myworkspace/repository-one/src/master/catalog-info.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -766,13 +744,11 @@ describe('BitbucketDiscoveryProcessor', () => {
describe('Custom repository parser', () => {
const customRepositoryParser: BitbucketRepositoryParser =
async function* customRepositoryParser({}) {
yield results.location(
{
type: 'custom-location-type',
target: 'custom-target',
},
true,
);
yield results.location({
type: 'custom-location-type',
target: 'custom-target',
presence: 'optional',
});
};
const processor = BitbucketDiscoveryProcessor.fromConfig(
@@ -808,8 +784,8 @@ describe('BitbucketDiscoveryProcessor', () => {
location: {
type: 'custom-location-type',
target: 'custom-target',
presence: 'optional',
},
optional: true,
});
});
});
@@ -210,7 +210,6 @@ describe('GitlabDiscoveryProcessor', () => {
target: 'https://gitlab.fake/1/-/blob/main/catalog-info.yaml',
presence: 'optional',
},
optional: true,
},
{
type: 'location',
@@ -219,7 +218,6 @@ describe('GitlabDiscoveryProcessor', () => {
target: 'https://gitlab.fake/2/-/blob/master/catalog-info.yaml',
presence: 'optional',
},
optional: true,
},
]);
});
@@ -257,7 +255,6 @@ describe('GitlabDiscoveryProcessor', () => {
target: 'https://gitlab.fake/1/-/blob/master/catalog-info.yaml',
presence: 'optional',
},
optional: true,
},
]);
});
@@ -117,20 +117,17 @@ export class GitLabDiscoveryProcessor implements CatalogProcessor {
const project_branch = branch === '*' ? project.default_branch : branch;
emit(
results.location(
{
type: 'url',
// The format expected by the GitLabUrlReader:
// https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath
//
// This unfortunately will trigger another API call in `getGitLabFileFetchUrl` to get the project ID.
// The alternative is using the `buildRawUrl` function, which does not support subgroups, so providing a raw
// URL here won't work either.
target: `${project.web_url}/-/blob/${project_branch}/${catalogPath}`,
presence: 'optional',
},
true,
),
results.location({
type: 'url',
// The format expected by the GitLabUrlReader:
// https://gitlab.com/groupA/teams/teamA/subgroupA/repoA/-/blob/branch/filepath
//
// This unfortunately will trigger another API call in `getGitLabFileFetchUrl` to get the project ID.
// The alternative is using the `buildRawUrl` function, which does not support subgroups, so providing a raw
// URL here won't work either.
target: `${project.web_url}/-/blob/${project_branch}/${catalogPath}`,
presence: 'optional',
}),
);
}
@@ -175,7 +175,6 @@ describe('GithubDiscoveryProcessor', () => {
'https://github.com/backstage/backstage/blob/master/catalog.yaml',
presence: 'optional',
},
optional: true,
});
expect(emitter).toHaveBeenCalledWith({
type: 'location',
@@ -184,7 +183,6 @@ describe('GithubDiscoveryProcessor', () => {
target: 'https://github.com/backstage/demo/blob/master/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -217,7 +215,6 @@ describe('GithubDiscoveryProcessor', () => {
'https://github.com/backstage/tech-docs/blob/main/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -272,7 +269,6 @@ describe('GithubDiscoveryProcessor', () => {
'https://github.com/backstage/backstage/blob/master/catalog-info.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -328,7 +324,6 @@ describe('GithubDiscoveryProcessor', () => {
'https://github.com/backstage/techdocs-cli/blob/master/catalog.yaml',
presence: 'optional',
},
optional: true,
});
expect(emitter).toHaveBeenCalledWith({
type: 'location',
@@ -338,7 +333,6 @@ describe('GithubDiscoveryProcessor', () => {
'https://github.com/backstage/techdocs-container/blob/master/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
@@ -394,7 +388,6 @@ describe('GithubDiscoveryProcessor', () => {
target: 'https://github.com/backstage/test/blob/master/catalog.yaml',
presence: 'optional',
},
optional: true,
});
});
});
@@ -140,17 +140,14 @@ export class GithubDiscoveryProcessor implements CatalogProcessor {
const path = `/blob/${branchName}${catalogPath}`;
emit(
results.location(
{
type: 'url',
target: `${repository.url}${path}`,
presence: 'optional',
},
results.location({
type: 'url',
target: `${repository.url}${path}`,
// Not all locations may actually exist, since the user defined them as a wildcard pattern.
// Thus, we emit them as optional and let the downstream processor find them while not outputting
// an error if it couldn't.
true,
),
presence: 'optional',
}),
);
}
@@ -81,7 +81,7 @@ export class LocationEntityProcessor implements CatalogProcessor {
location,
maybeRelativeTarget,
);
emit(result.location({ type, target }, false));
emit(result.location({ type, target }));
}
}
@@ -48,7 +48,7 @@ export class StaticLocationProcessor implements StaticLocationProcessor {
}
for (const staticLocation of this.staticLocations) {
emit(result.location(staticLocation, false));
emit(result.location(staticLocation));
}
return true;
@@ -25,14 +25,11 @@ describe('BitbucketRepositoryParser', () => {
'https://bitbucket.mycompany.com/projects/project-key/repos/repo-slug/browse';
const path = '/catalog-info.yaml';
const expected = [
results.location(
{
type: 'url',
target: `${browseUrl}${path}`,
presence: 'optional',
},
true,
),
results.location({
type: 'url',
target: `${browseUrl}${path}`,
presence: 'optional',
}),
];
const actual = await defaultRepositoryParser({
integration: {} as BitbucketIntegration,
@@ -26,15 +26,12 @@ export type BitbucketRepositoryParser = (options: {
export const defaultRepositoryParser: BitbucketRepositoryParser =
async function* defaultRepositoryParser({ target }) {
yield results.location(
{
type: 'url',
target: target,
presence: 'optional',
},
yield results.location({
type: 'url',
target: target,
// Not all locations may actually exist, since the user defined them as a wildcard pattern.
// Thus, we emit them as optional and let the downstream processor find them while not outputting
// an error if it couldn't.
true,
);
presence: 'optional',
});
};
@@ -53,7 +53,7 @@ export function generalError(
export function location(
newLocation: LocationSpec,
optional: boolean,
optional?: boolean,
): CatalogProcessorResult {
return { type: 'location', location: newLocation, optional };
}
@@ -158,7 +158,8 @@ export type CatalogProcessorEmit = (generated: CatalogProcessorResult) => void;
export type CatalogProcessorLocationResult = {
type: 'location';
location: LocationSpec;
optional: boolean;
/** @deprecated Set `location.presence = 'optional'` instead */
optional?: boolean;
};
export type CatalogProcessorEntityResult = {