From 209fd128e6c84e7c679721e44c2e9918cddcdc1c Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 17 Feb 2022 14:48:29 +0100 Subject: [PATCH] removed all references to the removed SCM-specific location types Signed-off-by: Patrik Oldsberg --- .changeset/cold-ravens-grin.md | 5 + .changeset/quiet-waves-film.md | 5 + .changeset/silent-kiwis-allow.md | 6 + docs/features/techdocs/cli.md | 2 +- packages/techdocs-cli/src/commands/index.ts | 2 +- packages/techdocs-common/README.md | 2 +- .../src/stages/prepare/dir.test.ts | 6 +- .../DefaultApiExplorerPage.test.tsx | 2 +- .../src/ingestion/CatalogRules.test.ts | 8 +- .../processors/CodeOwnersProcessor.test.ts | 2 +- .../processors/CodeOwnersProcessor.ts | 10 +- .../processors/PlaceholderProcessor.test.ts | 12 +- .../CatalogPage/DefaultCatalogPage.test.tsx | 2 +- plugins/github-deployments/src/api/index.ts | 2 +- .../components/GithubDeploymentsCard.test.tsx | 8 +- scripts/migrate-location-types.js | 110 ------------------ 16 files changed, 41 insertions(+), 143 deletions(-) create mode 100644 .changeset/cold-ravens-grin.md create mode 100644 .changeset/quiet-waves-film.md create mode 100644 .changeset/silent-kiwis-allow.md delete mode 100755 scripts/migrate-location-types.js diff --git a/.changeset/cold-ravens-grin.md b/.changeset/cold-ravens-grin.md new file mode 100644 index 0000000000..5ca43809ea --- /dev/null +++ b/.changeset/cold-ravens-grin.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': minor +--- + +The `CodeOwnersProcessor` no longer supports the deprecated SCM-specific location types like `'github/api'`. This is a breaking change but it is unlikely to have an impact, as these location types haven't been supported by the rest of the catalog for a long time. diff --git a/.changeset/quiet-waves-film.md b/.changeset/quiet-waves-film.md new file mode 100644 index 0000000000..206cef6287 --- /dev/null +++ b/.changeset/quiet-waves-film.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-github-deployments': patch +--- + +The removed `'github'` catalog location type no longer triggers a GitHub integration configuration lookup. diff --git a/.changeset/silent-kiwis-allow.md b/.changeset/silent-kiwis-allow.md new file mode 100644 index 0000000000..cfe5e9d1b7 --- /dev/null +++ b/.changeset/silent-kiwis-allow.md @@ -0,0 +1,6 @@ +--- +'@techdocs/cli': patch +'@backstage/techdocs-common': patch +--- + +Updated usage of `github:` location types in docs to use `url:` instead. diff --git a/docs/features/techdocs/cli.md b/docs/features/techdocs/cli.md index 8122fefdcd..a5dc8c3c54 100644 --- a/docs/features/techdocs/cli.md +++ b/docs/features/techdocs/cli.md @@ -123,7 +123,7 @@ Options: --no-pull Do not pull the latest docker image --no-docker Do not use Docker, use MkDocs executable and plugins in current user environment. --techdocs-ref The repository hosting documentation source files e.g. - github:https://ghe.mycompany.net.com/org/repo. + url:https://ghe.mycompany.net.com/org/repo. This value is same as the backstage.io/techdocs-ref annotation of the corresponding Backstage entity. It is completely fine to skip this as it is only being used to set repo_url in mkdocs.yml diff --git a/packages/techdocs-cli/src/commands/index.ts b/packages/techdocs-cli/src/commands/index.ts index d4f41cf7a3..115fe8e364 100644 --- a/packages/techdocs-cli/src/commands/index.ts +++ b/packages/techdocs-cli/src/commands/index.ts @@ -45,7 +45,7 @@ export function registerCommands(program: CommanderStatic) { ) .option( '--techdocs-ref ', - 'The repository hosting documentation source files e.g. github:https://ghe.mycompany.net.com/org/repo.' + + 'The repository hosting documentation source files e.g. url:https://ghe.mycompany.net.com/org/repo.' + '\nThis value is same as the backstage.io/techdocs-ref annotation of the corresponding Backstage entity.' + '\nIt is completely fine to skip this as it is only being used to set repo_url in mkdocs.yml if not found.\n', ) diff --git a/packages/techdocs-common/README.md b/packages/techdocs-common/README.md index e4889d6f79..bbaac85e9b 100644 --- a/packages/techdocs-common/README.md +++ b/packages/techdocs-common/README.md @@ -39,7 +39,7 @@ Currently the build process is split up in these three stages. - Generators - Publishers -Preparers read your entity data and creates a working directory with your documentation source code. For example if you have set your `backstage.io/techdocs-ref` to `github:https://github.com/backstage/backstage.git` it will clone that repository to a temp folder and pass that on to the generator. +Preparers read your entity data and creates a working directory with your documentation source code. For example if you have set your `backstage.io/techdocs-ref` to `url:https://github.com/backstage/backstage.git` it will clone that repository to a temp folder and pass that on to the generator. Generators takes the prepared source and runs the `techdocs-container` on it. It then passes on the output folder of that build to the publisher. diff --git a/packages/techdocs-common/src/stages/prepare/dir.test.ts b/packages/techdocs-common/src/stages/prepare/dir.test.ts index 019bf51fe9..2bf3fe29fc 100644 --- a/packages/techdocs-common/src/stages/prepare/dir.test.ts +++ b/packages/techdocs-common/src/stages/prepare/dir.test.ts @@ -86,7 +86,7 @@ describe('directory preparer', () => { ); }); - it('should reject when managed-by-location is a git repository', async () => { + it('should reject when managed-by-location has an unknown type', async () => { const directoryPreparer = new DirectoryPreparer( mockConfig, logger, @@ -95,12 +95,12 @@ describe('directory preparer', () => { const mockEntity = createMockEntity({ 'backstage.io/managed-by-location': - 'github:https://github.com/backstage/backstage/blob/master/catalog-info.yaml', + 'does-not-exist:https://github.com/backstage/backstage/blob/master/catalog-info.yaml', 'backstage.io/techdocs-ref': 'dir:./docs', }); await expect(directoryPreparer.prepare(mockEntity)).rejects.toThrow( - /Unable to resolve location type github/, + /Unable to resolve location type does-not-exist/, ); }); }); diff --git a/plugins/api-docs/src/components/ApiExplorerPage/DefaultApiExplorerPage.test.tsx b/plugins/api-docs/src/components/ApiExplorerPage/DefaultApiExplorerPage.test.tsx index 9b79263b5f..18222eea3a 100644 --- a/plugins/api-docs/src/components/ApiExplorerPage/DefaultApiExplorerPage.test.tsx +++ b/plugins/api-docs/src/components/ApiExplorerPage/DefaultApiExplorerPage.test.tsx @@ -57,7 +57,7 @@ describe('DefaultApiExplorerPage', () => { ] as Entity[], }), getLocationByRef: () => - Promise.resolve({ id: 'id', type: 'github', target: 'url' }), + Promise.resolve({ id: 'id', type: 'url', target: 'url' }), getEntityByName: async entityName => { return { apiVersion: 'backstage.io/v1alpha1', diff --git a/plugins/catalog-backend/src/ingestion/CatalogRules.test.ts b/plugins/catalog-backend/src/ingestion/CatalogRules.test.ts index 24d6b2fd66..88245d9b81 100644 --- a/plugins/catalog-backend/src/ingestion/CatalogRules.test.ts +++ b/plugins/catalog-backend/src/ingestion/CatalogRules.test.ts @@ -35,11 +35,11 @@ const entity = { const location: Record = { x: { - type: 'github', + type: 'url', target: 'https://github.com/a/b/blob/master/x.yaml', }, y: { - type: 'github', + type: 'url', target: 'https://github.com/a/b/blob/master/y.yaml', }, z: { @@ -180,7 +180,7 @@ describe('DefaultCatalogRulesEnforcer', () => { rules: [{ allow: ['user'] }], locations: [ { - type: 'github', + type: 'url', target: 'https://github.com/a/b/blob/master/x.yaml', rules: [ { @@ -204,7 +204,7 @@ describe('DefaultCatalogRulesEnforcer', () => { const enforcer = DefaultCatalogRulesEnforcer.fromConfig( new ConfigReader({ catalog: { - rules: [{ allow: ['Group'], locations: [{ type: 'github' }] }], + rules: [{ allow: ['Group'], locations: [{ type: 'url' }] }], }, }), ); diff --git a/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.test.ts index 2f52a1ddd9..3d7d6fde84 100644 --- a/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.test.ts @@ -27,7 +27,7 @@ const mockCodeOwnersText = () => ` describe('CodeOwnersProcessor', () => { const mockLocation = ({ basePath = '', - type = 'github', + type = 'url', } = {}): LocationSpec => ({ type, target: `https://github.com/backstage/backstage/blob/master/${basePath}catalog-info.yaml`, diff --git a/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.ts index b46070d173..ff5dedcbbf 100644 --- a/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/CodeOwnersProcessor.ts @@ -27,15 +27,7 @@ import { CatalogProcessor } from './types'; const ALLOWED_KINDS = ['API', 'Component', 'Domain', 'Resource', 'System']; -const ALLOWED_LOCATION_TYPES = [ - 'url', - 'azure/api', - 'bitbucket/api', - 'github', - 'github/api', - 'gitlab', - 'gitlab/api', -]; +const ALLOWED_LOCATION_TYPES = ['url']; export class CodeOwnersProcessor implements CatalogProcessor { private readonly integrations: ScmIntegrationRegistry; diff --git a/plugins/catalog-backend/src/ingestion/processors/PlaceholderProcessor.test.ts b/plugins/catalog-backend/src/ingestion/processors/PlaceholderProcessor.test.ts index c7a49353ae..7bfc66276e 100644 --- a/plugins/catalog-backend/src/ingestion/processors/PlaceholderProcessor.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/PlaceholderProcessor.test.ts @@ -154,7 +154,7 @@ describe('PlaceholderProcessor', () => { spec: { data: { $text: '../file.txt' } }, }, { - type: 'github', + type: 'url', target: 'https://github.com/backstage/backstage/a/b/catalog-info.yaml', }, @@ -190,7 +190,7 @@ describe('PlaceholderProcessor', () => { spec: { data: { $json: './file.json' } }, }, { - type: 'github', + type: 'url', target: 'https://github.com/backstage/backstage/a/b/catalog-info.yaml', }, @@ -224,7 +224,7 @@ describe('PlaceholderProcessor', () => { spec: { data: { $yaml: '../file.yaml' } }, }, { - type: 'github', + type: 'url', target: 'https://github.com/backstage/backstage/a/b/catalog-info.yaml', }, @@ -262,7 +262,7 @@ describe('PlaceholderProcessor', () => { }, }, { - type: 'github', + type: 'url', target: 'https://github.com/backstage/backstage/a/b/catalog-info.yaml', }, @@ -300,7 +300,7 @@ describe('PlaceholderProcessor', () => { }, }, { - type: 'github', + type: 'url', target: './a/b/catalog-info.yaml', }, ), @@ -340,7 +340,7 @@ describe('PlaceholderProcessor', () => { }, }, { - type: 'github', + type: 'url', target: './a/b/catalog-info.yaml', }, ), diff --git a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx index aa93d25c82..34aee0bbf3 100644 --- a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx +++ b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx @@ -101,7 +101,7 @@ describe('DefaultCatalogPage', () => { ] as Entity[], }), getLocationByRef: () => - Promise.resolve({ id: 'id', type: 'github', target: 'url' }), + Promise.resolve({ id: 'id', type: 'url', target: 'url' }), getEntityByName: async entityName => { return { apiVersion: 'backstage.io/v1alpha1', diff --git a/plugins/github-deployments/src/api/index.ts b/plugins/github-deployments/src/api/index.ts index e0eef7cc1d..48363557ff 100644 --- a/plugins/github-deployments/src/api/index.ts +++ b/plugins/github-deployments/src/api/index.ts @@ -28,7 +28,7 @@ const getBaseUrl = ( } const location = parseLocationRef(host); - if (location.type !== 'github' && location.type !== 'url') { + if (location.type !== 'url') { return 'https://api.github.com'; } diff --git a/plugins/github-deployments/src/components/GithubDeploymentsCard.test.tsx b/plugins/github-deployments/src/components/GithubDeploymentsCard.test.tsx index dba5bbfe1c..dedd2c3082 100644 --- a/plugins/github-deployments/src/components/GithubDeploymentsCard.test.tsx +++ b/plugins/github-deployments/src/components/GithubDeploymentsCard.test.tsx @@ -254,7 +254,7 @@ describe('github-deployments', () => { entity.entity.metadata.annotations = { 'github.com/project-slug': 'org/repo', 'backstage.io/source-location': - 'github:https://my-github-1.com/org/repo/tree/master/', + 'url:https://my-github-1.com/org/repo/tree/master/', }; }); @@ -276,7 +276,7 @@ describe('github-deployments', () => { entity.entity.metadata.annotations = { 'github.com/project-slug': 'org/repo', 'backstage.io/managed-by-location': - 'github:https://my-github-2.com/org/repo/blob/master/catalog-info.yaml', + 'url:https://my-github-2.com/org/repo/blob/master/catalog-info.yaml', }; }); @@ -298,7 +298,7 @@ describe('github-deployments', () => { entity.entity.metadata.annotations = { 'github.com/project-slug': 'org/repo', 'backstage.io/managed-by-location': - 'github:https://my-github-3.com/org/repo/blob/master/catalog-info.yaml', + 'url:https://my-github-3.com/org/repo/blob/master/catalog-info.yaml', }; }); @@ -323,7 +323,7 @@ describe('github-deployments', () => { entity.entity.metadata.annotations = { 'github.com/project-slug': 'org/repo', 'backstage.io/managed-by-location': - 'github:https://my-github-unknown.com/org/repo/blob/master/catalog-info.yaml', + 'url:https://my-github-unknown.com/org/repo/blob/master/catalog-info.yaml', }; }); diff --git a/scripts/migrate-location-types.js b/scripts/migrate-location-types.js deleted file mode 100755 index 168a5e825c..0000000000 --- a/scripts/migrate-location-types.js +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env node -/* - * Copyright 2020 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This is a script that helps you migrate any locations that are using -// deprecated location types. Change the below URL to point towards your -// catalog API endpoint and execute the script. It will delete and add -// back the locations with the correct type one by one. - -const BASE_URL = 'http://localhost:7007/api/catalog'; // Change me - -const deprecatedTypes = [ - 'github', - 'github/api', - 'bitbucket/api', - 'gitlab/api', - 'azure/api', -]; - -async function main() { - const locations = await request('GET', `${BASE_URL}/locations`); - - for (const { data: location } of locations) { - if (!deprecatedTypes.includes(location.type)) { - continue; - } - console.log(`${location.type} -> url : ${location.target}`); - await request('DELETE', `${BASE_URL}/locations/${location.id}`); - try { - await request('POST', `${BASE_URL}/locations`, { - type: 'url', - target: location.target, - }); - } catch (error) { - console.log(`Failed to add back location ${location.target}`); - throw error; - } - } -} - -async function request(method, url, body) { - return new Promise((resolve, reject) => { - const parsedUrl = require('url').parse(url); - - const req = require('http').request( - { - method, - ...parsedUrl, - headers: body - ? { - 'Content-Type': 'application/json', - } - : {}, - }, - res => { - const chunks = []; - res.on('data', chunk => { - chunks.push(chunk); - }); - - res.on('end', () => { - if (res.statusCode >= 300) { - reject( - new Error( - `${method} to ${url} failed with status ${res.statusCode}`, - ), - ); - return; - } - try { - const responseBody = Buffer.concat(chunks).toString('utf8').trim(); - if (responseBody) { - resolve(JSON.parse(responseBody)); - } else { - resolve(); - } - } catch (error) { - reject(error); - } - }); - }, - ); - - req.on('error', reject); - - if (body) { - req.write(JSON.stringify(body)); - } - - req.end(); - }); -} - -main().catch(error => { - console.error(error.stack); - process.exit(1); -});