From 3f9dd175989c87693aba596f30c4ae1f6472ec5b Mon Sep 17 00:00:00 2001 From: "@pawelmitka" Date: Mon, 23 Aug 2021 13:23:49 +0200 Subject: [PATCH 1/7] feat(scaffolder-plugin-backend): GitHub create repository webhook `github:repository:webhook:create` action has been added for GitHub. This allows creating custom webhooks, e.g.: for CI integration. Configuration has been simplified to the usage of secrets. Therefore, `config.token` and `config.digest` has been ommitted in favor of Secrets usage as through GitHub GUI. Secrets are assumed to be passed through environment variable name. Reference for `octokit.rest.repos.createWebhook` - https://octokit.github.io/rest.js/v18. All the defaults are aligned with the Octokit defaults. Note: there is some duplicated code related to GitHub integration that is shared between `createGithubCreateRepositoryWebhookAction`, `createGithubActionsDispatchAction` and `createPublishGithubAction` that I intend to refactor in a separate PR afterwards. Signed-off-by: @pawelmitka --- .changeset/fair-files-rest.md | 5 + .../__mocks__/@octokit/rest/index.ts | 1 + .../actions/builtin/createBuiltinActions.ts | 8 +- .../githubCreateRepositoryWebhook.test.ts | 228 ++++++++++++++++++ .../github/githubCreateRepositoryWebhook.ts | 176 ++++++++++++++ .../actions/builtin/github/index.ts | 1 + 6 files changed, 418 insertions(+), 1 deletion(-) create mode 100644 .changeset/fair-files-rest.md create mode 100644 plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.test.ts create mode 100644 plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.ts diff --git a/.changeset/fair-files-rest.md b/.changeset/fair-files-rest.md new file mode 100644 index 0000000000..3a16bb98ef --- /dev/null +++ b/.changeset/fair-files-rest.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': patch +--- + +GitHub create repository webhook action: 'github:repository:webhook:create' for Backstage plugin Scaffolder has been added. diff --git a/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts b/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts index 7505c3a30e..b60c3fcb2d 100644 --- a/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts @@ -23,6 +23,7 @@ export const mockGithubClient = { repos: { createInOrg: jest.fn(), createForAuthenticatedUser: jest.fn(), + createWebhook: jest.fn(), addCollaborator: jest.fn(), replaceAllTopics: jest.fn(), }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/createBuiltinActions.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/createBuiltinActions.ts index 5a16ef9a55..698389b7a7 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/createBuiltinActions.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/createBuiltinActions.ts @@ -37,7 +37,10 @@ import { createPublishGithubPullRequestAction, createPublishGitlabAction, } from './publish'; -import { createGithubActionsDispatchAction } from './github'; +import { + createGithubActionsDispatchAction, + createGithubCreateRepositoryWebhookAction, +} from './github'; export const createBuiltinActions = (options: { reader: UrlReader; @@ -90,5 +93,8 @@ export const createBuiltinActions = (options: { createGithubActionsDispatchAction({ integrations, }), + createGithubCreateRepositoryWebhookAction({ + integrations, + }), ]; }; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.test.ts new file mode 100644 index 0000000000..166ca15272 --- /dev/null +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.test.ts @@ -0,0 +1,228 @@ +/* + * Copyright 2021 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. + */ + +jest.mock('@octokit/rest'); + +import { createGithubCreateRepositoryWebhookAction } from './githubCreateRepositoryWebhook'; +import { ScmIntegrations } from '@backstage/integration'; +import { ConfigReader } from '@backstage/config'; +import { getVoidLogger } from '@backstage/backend-common'; +import { PassThrough } from 'stream'; + +describe('github:repository:webhook:create', () => { + const config = new ConfigReader({ + integrations: { + github: [ + { host: 'github.com', token: 'tokenlols' }, + { host: 'ghe.github.com' }, + ], + }, + }); + + const integrations = ScmIntegrations.fromConfig(config); + const action = createGithubCreateRepositoryWebhookAction({ integrations }); + + const mockContext = { + input: { + repoUrl: 'github.com?repo=repo&owner=owner', + webhookUrl: 'https://example.com/payload', + webhookSecretEnv: 'SUPER_SECRET', + }, + workspacePath: 'lol', + logger: getVoidLogger(), + logStream: new PassThrough(), + output: jest.fn(), + createTemporaryDirectory: jest.fn(), + }; + + const { mockGithubClient } = require('@octokit/rest'); + + beforeEach(() => { + jest.resetAllMocks(); + }); + + it('should throw an error when the repoUrl is not well formed', async () => { + await expect( + action.handler({ + ...mockContext, + input: { repoUrl: 'github.com?repo=bob' }, + }), + ).rejects.toThrow(/missing owner/); + + await expect( + action.handler({ + ...mockContext, + input: { repoUrl: 'github.com?owner=owner' }, + }), + ).rejects.toThrow(/missing repo/); + }); + + it('should throw if there is no integration config provided', async () => { + await expect( + action.handler({ + ...mockContext, + input: { repoUrl: 'missing.com?repo=bob&owner=owner' }, + }), + ).rejects.toThrow(/No matching integration configuration/); + }); + + it('should throw if there is no token in the integration config that is returned', async () => { + await expect( + action.handler({ + ...mockContext, + input: { + repoUrl: 'ghe.github.com?repo=bob&owner=owner', + }, + }), + ).rejects.toThrow(/No token available for host/); + }); + + it('should throw if environment variable in secret is invalid', async () => { + await expect(action.handler(mockContext)).rejects.toThrow( + /Environment variable: SUPER_SECRET does not exist./, + ); + }); + + it('should call the githubApi for creating repository Webhook', async () => { + const repoUrl = 'github.com?repo=repo&owner=owner'; + const webhookUrl = 'https://example.com/payload'; + const webhookSecretEnv = 'SUPER_SECRET'; + const secret = 'aafdfdivierernfdk23f'; + process.env[webhookSecretEnv] = secret; + const ctx = Object.assign({}, mockContext, { + input: { repoUrl, webhookUrl, webhookSecretEnv }, + }); + await action.handler(ctx); + + expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + events: ['push'], + active: true, + config: { + url: webhookUrl, + content_type: 'form', + secret, + insecure_ssl: '0', + }, + }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + events: ['push', 'pull_request'], + }, + }); + + expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + events: ['push', 'pull_request'], + active: true, + config: { + url: webhookUrl, + content_type: 'form', + secret, + insecure_ssl: '0', + }, + }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + contentType: 'json', + }, + }); + + expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + events: ['push'], + active: true, + config: { + url: webhookUrl, + content_type: 'json', + secret, + insecure_ssl: '0', + }, + }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + insecureSsl: true, + }, + }); + + expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + events: ['push'], + active: true, + config: { + url: webhookUrl, + content_type: 'form', + secret, + insecure_ssl: '1', + }, + }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + insecureSsl: true, + }, + }); + + expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + events: ['push'], + active: true, + config: { + url: webhookUrl, + content_type: 'form', + secret, + insecure_ssl: '1', + }, + }); + + await action.handler({ + ...mockContext, + input: { + ...mockContext.input, + active: false, + }, + }); + + expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + events: ['push'], + active: false, + config: { + url: webhookUrl, + content_type: 'form', + secret, + insecure_ssl: '0', + }, + }); + }); +}); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.ts new file mode 100644 index 0000000000..32ebbcae31 --- /dev/null +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.ts @@ -0,0 +1,176 @@ +/* + * Copyright 2021 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. + */ +import { InputError } from '@backstage/errors'; +import { + GithubCredentialsProvider, + ScmIntegrationRegistry, +} from '@backstage/integration'; +import { Octokit } from '@octokit/rest'; +import { parseRepoUrl } from '../publish/util'; +import { createTemplateAction } from '../../createTemplateAction'; + +type ContentType = 'form' | 'json'; + +export function createGithubCreateRepositoryWebhookAction(options: { + integrations: ScmIntegrationRegistry; +}) { + const { integrations } = options; + + const credentialsProviders = new Map( + integrations.github.list().map(integration => { + const provider = GithubCredentialsProvider.create(integration.config); + return [integration.config.host, provider]; + }), + ); + + return createTemplateAction<{ + repoUrl: string; + webhookUrl: string; + webhookSecretEnv?: string; + events?: string[]; + active?: boolean; + contentType?: ContentType; + insecureSsl?: boolean; + }>({ + id: 'github:repository:webhook:create', + description: 'Creates webhook for a repository on GitHub.', + schema: { + input: { + type: 'object', + required: ['repoUrl', 'webhookUrl'], + properties: { + repoUrl: { + title: 'Repository Location', + description: `Accepts the format 'github.com?repo=reponame&owner=owner' where 'reponame' is the new repository name and 'owner' is an organization or username`, + type: 'string', + }, + webhookUrl: { + title: 'Webhook URL', + description: 'The URL to which the payloads will be delivered', + type: 'string', + }, + webhookSecretEnv: { + title: 'Environment variable containing Webhook Secret', + description: 'Name of the environment variable containing secret', + type: 'string', + }, + events: { + title: 'Triggering Events', + description: + 'Determines what events the hook is triggered for. Default: push', + type: 'array', + items: { + type: 'string', + }, + }, + active: { + title: 'Active', + type: 'boolean', + description: `Determines if notifications are sent when the webhook is triggered. Default: true`, + }, + contentType: { + title: 'Content Type', + type: 'string', + enum: ['form', 'json'], + description: `The media type used to serialize the payloads. The default is 'form'`, + }, + insecureSsl: { + title: 'Insecure SSL', + type: 'boolean', + description: `Determines whether the SSL certificate of the host for url will be verified when delivering payloads. Default 'false'`, + }, + }, + }, + }, + async handler(ctx) { + const { + repoUrl, + webhookUrl, + webhookSecretEnv, + events = ['push'], + active = true, + contentType = 'form', + insecureSsl = false, + } = ctx.input; + + const { owner, repo, host } = parseRepoUrl(repoUrl, integrations); + + if (!owner) { + throw new InputError(`No owner provided for repo ${repoUrl}`); + } + + let secret; + if (webhookSecretEnv) { + secret = process.env[webhookSecretEnv]; + if (!secret) { + throw new InputError( + `Environment variable: ${webhookSecretEnv} does not exist.`, + ); + } + } + + ctx.logger.info(`Creating webhook ${webhookUrl} for repo ${repoUrl}`); + + const credentialsProvider = credentialsProviders.get(host); + const integrationConfig = integrations.github.byHost(host); + + if (!credentialsProvider || !integrationConfig) { + throw new InputError( + `No matching integration configuration for host ${host}, please check your integrations config`, + ); + } + + const { token } = await credentialsProvider.getCredentials({ + url: `https://${host}/${encodeURIComponent(owner)}/${encodeURIComponent( + repo, + )}`, + }); + + if (!token) { + throw new InputError( + `No token available for host: ${host}, with owner ${owner}, and repo ${repo}`, + ); + } + + const client = new Octokit({ + auth: token, + baseUrl: integrationConfig.config.apiBaseUrl, + previews: ['nebula-preview'], + }); + + try { + const insecure_ssl = insecureSsl ? '1' : '0'; + await client.repos.createWebhook({ + owner, + repo, + config: { + url: webhookUrl, + content_type: contentType, + secret, + insecure_ssl, + }, + events, + active, + }); + ctx.logger.info(`Webhook '${webhookUrl}' created successfully`); + } catch (e) { + ctx.logger.warn( + `Failed: create webhook '${webhookUrl}' on repo: '${repo}', ${e.message}`, + ); + } + }, + }); +} diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/index.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/index.ts index 50abd2c3dc..9c12d40a65 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/index.ts @@ -15,3 +15,4 @@ */ export { createGithubActionsDispatchAction } from './githubActionsDispatch'; +export { createGithubCreateRepositoryWebhookAction } from './githubCreateRepositoryWebhook'; From 7666065a1e705b63bd270cfe42f5b03a345a153d Mon Sep 17 00:00:00 2001 From: "@pawelmitka" Date: Mon, 23 Aug 2021 14:34:00 +0200 Subject: [PATCH 2/7] fix: vale errors Signed-off-by: @pawelmitka --- .changeset/fair-files-rest.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/fair-files-rest.md b/.changeset/fair-files-rest.md index 3a16bb98ef..c15a4bb8cf 100644 --- a/.changeset/fair-files-rest.md +++ b/.changeset/fair-files-rest.md @@ -2,4 +2,4 @@ '@backstage/plugin-scaffolder-backend': patch --- -GitHub create repository webhook action: 'github:repository:webhook:create' for Backstage plugin Scaffolder has been added. +GitHub create repository webhook action: `github:repository:webhook:create` for Backstage plugin Scaffolder has been added. From 882882c87a3d286c05adb3faa597b66827e9f39f Mon Sep 17 00:00:00 2001 From: "@pawelmitka" Date: Mon, 23 Aug 2021 16:43:50 +0200 Subject: [PATCH 3/7] fix: update API report Signed-off-by: @pawelmitka --- plugins/scaffolder-backend/api-report.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index f763904fe7..af52e7749d 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -114,6 +114,13 @@ export function createGithubActionsDispatchAction(options: { integrations: ScmIntegrationRegistry; }): TemplateAction; +// Warning: (ae-missing-release-tag) "createGithubCreateRepositoryWebhookAction" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export function createGithubCreateRepositoryWebhookAction(options: { + integrations: ScmIntegrationRegistry; +}): TemplateAction; + // Warning: (ae-missing-release-tag) "createPublishAzureAction" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) From 8ebd2b639932a39d36d3435fba9250db7b63a460 Mon Sep 17 00:00:00 2001 From: "@pawelmitka" Date: Fri, 27 Aug 2021 12:23:35 +0200 Subject: [PATCH 4/7] refactor: avoid using env variables in action Signed-off-by: @pawelmitka --- .../githubCreateRepositoryWebhook.test.ts | 26 +++++++------------ .../github/githubCreateRepositoryWebhook.ts | 22 +++++----------- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.test.ts index 166ca15272..4b74799dbe 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.test.ts @@ -39,7 +39,7 @@ describe('github:repository:webhook:create', () => { input: { repoUrl: 'github.com?repo=repo&owner=owner', webhookUrl: 'https://example.com/payload', - webhookSecretEnv: 'SUPER_SECRET', + webhookSecret: 'aafdfdivierernfdk23f', }, workspacePath: 'lol', logger: getVoidLogger(), @@ -90,20 +90,12 @@ describe('github:repository:webhook:create', () => { ).rejects.toThrow(/No token available for host/); }); - it('should throw if environment variable in secret is invalid', async () => { - await expect(action.handler(mockContext)).rejects.toThrow( - /Environment variable: SUPER_SECRET does not exist./, - ); - }); - it('should call the githubApi for creating repository Webhook', async () => { const repoUrl = 'github.com?repo=repo&owner=owner'; const webhookUrl = 'https://example.com/payload'; - const webhookSecretEnv = 'SUPER_SECRET'; - const secret = 'aafdfdivierernfdk23f'; - process.env[webhookSecretEnv] = secret; + const webhookSecret = 'aafdfdivierernfdk23f'; const ctx = Object.assign({}, mockContext, { - input: { repoUrl, webhookUrl, webhookSecretEnv }, + input: { repoUrl, webhookUrl, webhookSecret }, }); await action.handler(ctx); @@ -115,7 +107,7 @@ describe('github:repository:webhook:create', () => { config: { url: webhookUrl, content_type: 'form', - secret, + secret: webhookSecret, insecure_ssl: '0', }, }); @@ -136,7 +128,7 @@ describe('github:repository:webhook:create', () => { config: { url: webhookUrl, content_type: 'form', - secret, + secret: webhookSecret, insecure_ssl: '0', }, }); @@ -157,7 +149,7 @@ describe('github:repository:webhook:create', () => { config: { url: webhookUrl, content_type: 'json', - secret, + secret: webhookSecret, insecure_ssl: '0', }, }); @@ -178,7 +170,7 @@ describe('github:repository:webhook:create', () => { config: { url: webhookUrl, content_type: 'form', - secret, + secret: webhookSecret, insecure_ssl: '1', }, }); @@ -199,7 +191,7 @@ describe('github:repository:webhook:create', () => { config: { url: webhookUrl, content_type: 'form', - secret, + secret: webhookSecret, insecure_ssl: '1', }, }); @@ -220,7 +212,7 @@ describe('github:repository:webhook:create', () => { config: { url: webhookUrl, content_type: 'form', - secret, + secret: webhookSecret, insecure_ssl: '0', }, }); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.ts index 32ebbcae31..cec68c09f2 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.ts @@ -39,7 +39,7 @@ export function createGithubCreateRepositoryWebhookAction(options: { return createTemplateAction<{ repoUrl: string; webhookUrl: string; - webhookSecretEnv?: string; + webhookSecret?: string; events?: string[]; active?: boolean; contentType?: ContentType; @@ -62,9 +62,9 @@ export function createGithubCreateRepositoryWebhookAction(options: { description: 'The URL to which the payloads will be delivered', type: 'string', }, - webhookSecretEnv: { - title: 'Environment variable containing Webhook Secret', - description: 'Name of the environment variable containing secret', + webhookSecret: { + title: 'Webhook Secret', + description: 'Webhook secret value', type: 'string', }, events: { @@ -99,7 +99,7 @@ export function createGithubCreateRepositoryWebhookAction(options: { const { repoUrl, webhookUrl, - webhookSecretEnv, + webhookSecret, events = ['push'], active = true, contentType = 'form', @@ -112,16 +112,6 @@ export function createGithubCreateRepositoryWebhookAction(options: { throw new InputError(`No owner provided for repo ${repoUrl}`); } - let secret; - if (webhookSecretEnv) { - secret = process.env[webhookSecretEnv]; - if (!secret) { - throw new InputError( - `Environment variable: ${webhookSecretEnv} does not exist.`, - ); - } - } - ctx.logger.info(`Creating webhook ${webhookUrl} for repo ${repoUrl}`); const credentialsProvider = credentialsProviders.get(host); @@ -159,7 +149,7 @@ export function createGithubCreateRepositoryWebhookAction(options: { config: { url: webhookUrl, content_type: contentType, - secret, + secret: webhookSecret, insecure_ssl, }, events, From c5c229966fb49a5d3984cb536dbf355ae240b133 Mon Sep 17 00:00:00 2001 From: "@pawelmitka" Date: Fri, 27 Aug 2021 16:34:38 +0200 Subject: [PATCH 5/7] refactor: rename github:repository:webhook:create to github:webhook Signed-off-by: @pawelmitka --- .../src/scaffolder/actions/builtin/createBuiltinActions.ts | 4 ++-- ...bCreateRepositoryWebhook.test.ts => githubWebhook.test.ts} | 4 ++-- .../{githubCreateRepositoryWebhook.ts => githubWebhook.ts} | 4 ++-- .../src/scaffolder/actions/builtin/github/index.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/{githubCreateRepositoryWebhook.test.ts => githubWebhook.test.ts} (97%) rename plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/{githubCreateRepositoryWebhook.ts => githubWebhook.ts} (97%) diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/createBuiltinActions.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/createBuiltinActions.ts index 698389b7a7..d38dfe3cdc 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/createBuiltinActions.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/createBuiltinActions.ts @@ -39,7 +39,7 @@ import { } from './publish'; import { createGithubActionsDispatchAction, - createGithubCreateRepositoryWebhookAction, + createGithubWebhookAction, } from './github'; export const createBuiltinActions = (options: { @@ -93,7 +93,7 @@ export const createBuiltinActions = (options: { createGithubActionsDispatchAction({ integrations, }), - createGithubCreateRepositoryWebhookAction({ + createGithubWebhookAction({ integrations, }), ]; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.test.ts similarity index 97% rename from plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.test.ts rename to plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.test.ts index 4b74799dbe..8f11eefce1 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.test.ts @@ -16,7 +16,7 @@ jest.mock('@octokit/rest'); -import { createGithubCreateRepositoryWebhookAction } from './githubCreateRepositoryWebhook'; +import { createGithubWebhookAction } from './githubWebhook'; import { ScmIntegrations } from '@backstage/integration'; import { ConfigReader } from '@backstage/config'; import { getVoidLogger } from '@backstage/backend-common'; @@ -33,7 +33,7 @@ describe('github:repository:webhook:create', () => { }); const integrations = ScmIntegrations.fromConfig(config); - const action = createGithubCreateRepositoryWebhookAction({ integrations }); + const action = createGithubWebhookAction({ integrations }); const mockContext = { input: { diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.ts similarity index 97% rename from plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.ts rename to plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.ts index cec68c09f2..50877d3bca 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubCreateRepositoryWebhook.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.ts @@ -24,7 +24,7 @@ import { createTemplateAction } from '../../createTemplateAction'; type ContentType = 'form' | 'json'; -export function createGithubCreateRepositoryWebhookAction(options: { +export function createGithubWebhookAction(options: { integrations: ScmIntegrationRegistry; }) { const { integrations } = options; @@ -45,7 +45,7 @@ export function createGithubCreateRepositoryWebhookAction(options: { contentType?: ContentType; insecureSsl?: boolean; }>({ - id: 'github:repository:webhook:create', + id: 'github:webhook', description: 'Creates webhook for a repository on GitHub.', schema: { input: { diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/index.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/index.ts index 9c12d40a65..07614e8a03 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/index.ts @@ -15,4 +15,4 @@ */ export { createGithubActionsDispatchAction } from './githubActionsDispatch'; -export { createGithubCreateRepositoryWebhookAction } from './githubCreateRepositoryWebhook'; +export { createGithubWebhookAction } from './githubWebhook'; From 82fecb0405a81d33c1aad6b043be046aba456b2c Mon Sep 17 00:00:00 2001 From: "@pawelmitka" Date: Fri, 27 Aug 2021 16:37:49 +0200 Subject: [PATCH 6/7] fix: update CHANGESET Signed-off-by: @pawelmitka --- .changeset/fair-files-rest.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/fair-files-rest.md b/.changeset/fair-files-rest.md index c15a4bb8cf..68d3246aa4 100644 --- a/.changeset/fair-files-rest.md +++ b/.changeset/fair-files-rest.md @@ -2,4 +2,4 @@ '@backstage/plugin-scaffolder-backend': patch --- -GitHub create repository webhook action: `github:repository:webhook:create` for Backstage plugin Scaffolder has been added. +GitHub create repository webhook action: `github:webhook` for Backstage plugin Scaffolder has been added. From 5b125edfcce0acbdded12bddf33497bae9855a01 Mon Sep 17 00:00:00 2001 From: "@pawelmitka" Date: Fri, 27 Aug 2021 16:59:19 +0200 Subject: [PATCH 7/7] fix: update api-report.md Signed-off-by: @pawelmitka --- plugins/scaffolder-backend/api-report.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index af52e7749d..dfda1ff2fc 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -114,10 +114,10 @@ export function createGithubActionsDispatchAction(options: { integrations: ScmIntegrationRegistry; }): TemplateAction; -// Warning: (ae-missing-release-tag) "createGithubCreateRepositoryWebhookAction" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// Warning: (ae-missing-release-tag) "createGithubWebhookAction" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -export function createGithubCreateRepositoryWebhookAction(options: { +export function createGithubWebhookAction(options: { integrations: ScmIntegrationRegistry; }): TemplateAction;