From 2e0dbb0e50e2774c70ce819c774a6b5eebcfcc25 Mon Sep 17 00:00:00 2001 From: Crevil Date: Wed, 26 Jan 2022 20:46:09 +0100 Subject: [PATCH] Replace @octokit/rest in scaffolder-backend Signed-off-by: Crevil --- .changeset/grumpy-teachers-remain.md | 5 + plugins/scaffolder-backend/package.json | 2 +- .../{@octokit/rest => octokit}/index.ts | 26 ++-- .../actions/builtin/github/OctokitProvider.ts | 2 +- .../github/githubActionsDispatch.test.ts | 4 +- .../builtin/github/githubWebhook.test.ts | 18 +-- .../actions/builtin/github/githubWebhook.ts | 2 +- .../src/scaffolder/actions/builtin/helpers.ts | 4 +- .../actions/builtin/publish/github.test.ts | 92 +++++------ .../actions/builtin/publish/github.ts | 14 +- .../builtin/publish/githubPullRequest.ts | 2 +- yarn.lock | 146 +++++++++++++++++- 12 files changed, 230 insertions(+), 87 deletions(-) create mode 100644 .changeset/grumpy-teachers-remain.md rename plugins/scaffolder-backend/src/scaffolder/__mocks__/{@octokit/rest => octokit}/index.ts (71%) diff --git a/.changeset/grumpy-teachers-remain.md b/.changeset/grumpy-teachers-remain.md new file mode 100644 index 0000000000000..e1d29a7edd98a --- /dev/null +++ b/.changeset/grumpy-teachers-remain.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend': minor +--- + +Migrate from deprecated package @octokit/rest to octokit diff --git a/plugins/scaffolder-backend/package.json b/plugins/scaffolder-backend/package.json index e9c932a211a70..2ab6dca6f3061 100644 --- a/plugins/scaffolder-backend/package.json +++ b/plugins/scaffolder-backend/package.json @@ -43,7 +43,6 @@ "@backstage/types": "^0.1.1", "@gitbeaker/core": "^34.6.0", "@gitbeaker/node": "^35.1.0", - "@octokit/rest": "^18.5.3", "@octokit/webhooks": "^9.14.1", "@types/express": "^4.17.6", "azure-devops-node-api": "^11.0.1", @@ -66,6 +65,7 @@ "morgan": "^1.10.0", "node-fetch": "^2.6.1", "nunjucks": "^3.2.3", + "octokit": "^1.7.1", "octokit-plugin-create-pull-request": "^3.10.0", "uuid": "^8.2.0", "winston": "^3.2.1", diff --git a/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts b/plugins/scaffolder-backend/src/scaffolder/__mocks__/octokit/index.ts similarity index 71% rename from plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts rename to plugins/scaffolder-backend/src/scaffolder/__mocks__/octokit/index.ts index b60c3fcb2d708..de320ef498b18 100644 --- a/plugins/scaffolder-backend/src/scaffolder/__mocks__/@octokit/rest/index.ts +++ b/plugins/scaffolder-backend/src/scaffolder/__mocks__/octokit/index.ts @@ -19,19 +19,19 @@ export const mockGithubClient = { actions: { createWorkflowDispatch: jest.fn(), }, - }, - repos: { - createInOrg: jest.fn(), - createForAuthenticatedUser: jest.fn(), - createWebhook: jest.fn(), - addCollaborator: jest.fn(), - replaceAllTopics: jest.fn(), - }, - users: { - getByUsername: jest.fn(), - }, - teams: { - addOrUpdateRepoPermissionsInOrg: jest.fn(), + repos: { + createInOrg: jest.fn(), + createForAuthenticatedUser: jest.fn(), + createWebhook: jest.fn(), + addCollaborator: jest.fn(), + replaceAllTopics: jest.fn(), + }, + users: { + getByUsername: jest.fn(), + }, + teams: { + addOrUpdateRepoPermissionsInOrg: jest.fn(), + }, }, }; diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/OctokitProvider.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/OctokitProvider.ts index bf91c0e37c2c6..a3eeec4373b35 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/OctokitProvider.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/OctokitProvider.ts @@ -20,7 +20,7 @@ import { GithubCredentialsProvider, ScmIntegrationRegistry, } from '@backstage/integration'; -import { Octokit } from '@octokit/rest'; +import { Octokit } from 'octokit'; import { parseRepoUrl } from '../publish/util'; export type OctokitIntegration = { diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.test.ts index b725f825fe2db..68ef88021ee16 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubActionsDispatch.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -jest.mock('@octokit/rest'); +jest.mock('octokit'); import { TemplateAction } from '../../types'; import { createGithubActionsDispatchAction } from './githubActionsDispatch'; @@ -54,7 +54,7 @@ describe('github:actions:dispatch', () => { createTemporaryDirectory: jest.fn(), }; - const { mockGithubClient } = require('@octokit/rest'); + const { mockGithubClient } = require('octokit'); beforeEach(() => { jest.resetAllMocks(); diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.test.ts index fe2535ca42a55..b80691fdcc822 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.test.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -jest.mock('@octokit/rest'); +jest.mock('octokit'); import { createGithubWebhookAction } from './githubWebhook'; import { @@ -65,7 +65,7 @@ describe('github:repository:webhook:create', () => { createTemporaryDirectory: jest.fn(), }; - const { mockGithubClient } = require('@octokit/rest'); + const { mockGithubClient } = require('octokit'); it('should call the githubApi for creating repository Webhook', async () => { const repoUrl = 'github.com?repo=repo&owner=owner'; @@ -75,7 +75,7 @@ describe('github:repository:webhook:create', () => { }); await action.handler(ctx); - expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + expect(mockGithubClient.rest.repos.createWebhook).toHaveBeenCalledWith({ owner: 'owner', repo: 'repo', events: ['push'], @@ -97,7 +97,7 @@ describe('github:repository:webhook:create', () => { }, }); - expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + expect(mockGithubClient.rest.repos.createWebhook).toHaveBeenCalledWith({ owner: 'owner', repo: 'repo', events: ['push'], @@ -118,7 +118,7 @@ describe('github:repository:webhook:create', () => { }, }); - expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + expect(mockGithubClient.rest.repos.createWebhook).toHaveBeenCalledWith({ owner: 'owner', repo: 'repo', events: ['push', 'pull_request'], @@ -139,7 +139,7 @@ describe('github:repository:webhook:create', () => { }, }); - expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + expect(mockGithubClient.rest.repos.createWebhook).toHaveBeenCalledWith({ owner: 'owner', repo: 'repo', events: ['push'], @@ -160,7 +160,7 @@ describe('github:repository:webhook:create', () => { }, }); - expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + expect(mockGithubClient.rest.repos.createWebhook).toHaveBeenCalledWith({ owner: 'owner', repo: 'repo', events: ['push'], @@ -181,7 +181,7 @@ describe('github:repository:webhook:create', () => { }, }); - expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + expect(mockGithubClient.rest.repos.createWebhook).toHaveBeenCalledWith({ owner: 'owner', repo: 'repo', events: ['push'], @@ -202,7 +202,7 @@ describe('github:repository:webhook:create', () => { }, }); - expect(mockGithubClient.repos.createWebhook).toHaveBeenCalledWith({ + expect(mockGithubClient.rest.repos.createWebhook).toHaveBeenCalledWith({ owner: 'owner', repo: 'repo', events: ['push'], diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.ts index 95f18888820f3..39e8c3aa70581 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/githubWebhook.ts @@ -127,7 +127,7 @@ export function createGithubWebhookAction(options: { try { const insecure_ssl = insecureSsl ? '1' : '0'; - await client.repos.createWebhook({ + await client.rest.repos.createWebhook({ owner, repo, config: { diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts index 90f060fd889da..92b578d385f24 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/helpers.ts @@ -18,7 +18,7 @@ import { SpawnOptionsWithoutStdio, spawn } from 'child_process'; import { PassThrough, Writable } from 'stream'; import { Logger } from 'winston'; import { Git } from '@backstage/backend-common'; -import { Octokit } from '@octokit/rest'; +import { Octokit } from 'octokit'; import { assertError } from '@backstage/errors'; export type RunCommandOptions = { @@ -139,7 +139,7 @@ export const enableBranchProtectionOnDefaultRepoBranch = async ({ }: BranchProtectionOptions): Promise => { const tryOnce = async () => { try { - await client.repos.updateBranchProtection({ + await client.rest.repos.updateBranchProtection({ mediaType: { /** * 👇 we need this preview because allowing a custom diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts index 7724dec85e710..5467ca651cfb3 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.test.ts @@ -17,7 +17,7 @@ import { TemplateAction } from '../../types'; jest.mock('../helpers'); -jest.mock('@octokit/rest'); +jest.mock('octokit'); import { createPublishGithubAction } from './github'; import { @@ -62,7 +62,7 @@ describe('publish:github', () => { createTemporaryDirectory: jest.fn(), }; - const { mockGithubClient } = require('@octokit/rest'); + const { mockGithubClient } = require('octokit'); beforeEach(() => { jest.resetAllMocks(); @@ -76,14 +76,14 @@ describe('publish:github', () => { }); it('should call the githubApis with the correct values for createInOrg', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'Organization' }, }); - mockGithubClient.repos.createInOrg.mockResolvedValue({ data: {} }); + mockGithubClient.rest.repos.createInOrg.mockResolvedValue({ data: {} }); await action.handler(mockContext); - expect(mockGithubClient.repos.createInOrg).toHaveBeenCalledWith({ + expect(mockGithubClient.rest.repos.createInOrg).toHaveBeenCalledWith({ description: 'description', name: 'repo', org: 'owner', @@ -98,7 +98,7 @@ describe('publish:github', () => { repoVisibility: 'public', }, }); - expect(mockGithubClient.repos.createInOrg).toHaveBeenCalledWith({ + expect(mockGithubClient.rest.repos.createInOrg).toHaveBeenCalledWith({ description: 'description', name: 'repo', org: 'owner', @@ -108,17 +108,17 @@ describe('publish:github', () => { }); it('should call the githubApis with the correct values for createForAuthenticatedUser', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: {}, }); await action.handler(mockContext); expect( - mockGithubClient.repos.createForAuthenticatedUser, + mockGithubClient.rest.repos.createForAuthenticatedUser, ).toHaveBeenCalledWith({ description: 'description', name: 'repo', @@ -133,7 +133,7 @@ describe('publish:github', () => { }, }); expect( - mockGithubClient.repos.createForAuthenticatedUser, + mockGithubClient.rest.repos.createForAuthenticatedUser, ).toHaveBeenCalledWith({ description: 'description', name: 'repo', @@ -142,11 +142,11 @@ describe('publish:github', () => { }); it('should call initRepoAndPush with the correct values', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { clone_url: 'https://github.com/clone/url.git', html_url: 'https://github.com/html/url', @@ -166,11 +166,11 @@ describe('publish:github', () => { }); it('should call initRepoAndPush with the correct defaultBranch main', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { clone_url: 'https://github.com/clone/url.git', html_url: 'https://github.com/html/url', @@ -219,11 +219,11 @@ describe('publish:github', () => { githubCredentialsProvider, }); - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { clone_url: 'https://github.com/clone/url.git', html_url: 'https://github.com/html/url', @@ -263,11 +263,11 @@ describe('publish:github', () => { githubCredentialsProvider, }); - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { clone_url: 'https://github.com/clone/url.git', html_url: 'https://github.com/html/url', @@ -288,11 +288,11 @@ describe('publish:github', () => { }); it('should add access for the team when it starts with the owner', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { clone_url: 'https://github.com/clone/url.git', html_url: 'https://github.com/html/url', @@ -302,7 +302,7 @@ describe('publish:github', () => { await action.handler(mockContext); expect( - mockGithubClient.teams.addOrUpdateRepoPermissionsInOrg, + mockGithubClient.rest.teams.addOrUpdateRepoPermissionsInOrg, ).toHaveBeenCalledWith({ org: 'owner', team_slug: 'blam', @@ -313,11 +313,11 @@ describe('publish:github', () => { }); it('should add outside collaborators when provided', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { clone_url: 'https://github.com/clone/url.git', html_url: 'https://github.com/html/url', @@ -332,7 +332,7 @@ describe('publish:github', () => { }, }); - expect(mockGithubClient.repos.addCollaborator).toHaveBeenCalledWith({ + expect(mockGithubClient.rest.repos.addCollaborator).toHaveBeenCalledWith({ username: 'outsidecollaborator', owner: 'owner', repo: 'repo', @@ -341,11 +341,11 @@ describe('publish:github', () => { }); it('should add multiple collaborators when provided', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { clone_url: 'https://github.com/clone/url.git', html_url: 'https://github.com/html/url', @@ -376,7 +376,7 @@ describe('publish:github', () => { }; expect( - mockGithubClient.teams.addOrUpdateRepoPermissionsInOrg.mock.calls[1], + mockGithubClient.rest.teams.addOrUpdateRepoPermissionsInOrg.mock.calls[1], ).toEqual([ { ...commonProperties, @@ -386,7 +386,7 @@ describe('publish:github', () => { ]); expect( - mockGithubClient.teams.addOrUpdateRepoPermissionsInOrg.mock.calls[2], + mockGithubClient.rest.teams.addOrUpdateRepoPermissionsInOrg.mock.calls[2], ).toEqual([ { ...commonProperties, @@ -397,18 +397,18 @@ describe('publish:github', () => { }); it('should ignore failures when adding multiple collaborators', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { clone_url: 'https://github.com/clone/url.git', html_url: 'https://github.com/html/url', }, }); - when(mockGithubClient.teams.addOrUpdateRepoPermissionsInOrg) + when(mockGithubClient.rest.teams.addOrUpdateRepoPermissionsInOrg) .calledWith({ org: 'owner', owner: 'owner', @@ -436,7 +436,7 @@ describe('publish:github', () => { }); expect( - mockGithubClient.teams.addOrUpdateRepoPermissionsInOrg.mock.calls[2], + mockGithubClient.rest.teams.addOrUpdateRepoPermissionsInOrg.mock.calls[2], ).toEqual([ { org: 'owner', @@ -449,18 +449,18 @@ describe('publish:github', () => { }); it('should add topics when provided', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { clone_url: 'https://github.com/clone/url.git', html_url: 'https://github.com/html/url', }, }); - mockGithubClient.repos.replaceAllTopics.mockResolvedValue({ + mockGithubClient.rest.repos.replaceAllTopics.mockResolvedValue({ data: { names: ['node.js'], }, @@ -474,7 +474,7 @@ describe('publish:github', () => { }, }); - expect(mockGithubClient.repos.replaceAllTopics).toHaveBeenCalledWith({ + expect(mockGithubClient.rest.repos.replaceAllTopics).toHaveBeenCalledWith({ owner: 'owner', repo: 'repo', names: ['node.js'], @@ -482,18 +482,18 @@ describe('publish:github', () => { }); it('should lowercase topics when provided', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { clone_url: 'https://github.com/clone/url.git', html_url: 'https://github.com/html/url', }, }); - mockGithubClient.repos.replaceAllTopics.mockResolvedValue({ + mockGithubClient.rest.repos.replaceAllTopics.mockResolvedValue({ data: { names: ['backstage'], }, @@ -507,7 +507,7 @@ describe('publish:github', () => { }, }); - expect(mockGithubClient.repos.replaceAllTopics).toHaveBeenCalledWith({ + expect(mockGithubClient.rest.repos.replaceAllTopics).toHaveBeenCalledWith({ owner: 'owner', repo: 'repo', names: ['backstage'], @@ -515,11 +515,11 @@ describe('publish:github', () => { }); it('should call output with the remoteUrl and the repoContentsUrl', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { clone_url: 'https://github.com/clone/url.git', html_url: 'https://github.com/html/url', @@ -539,11 +539,11 @@ describe('publish:github', () => { }); it('should use main as default branch', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { clone_url: 'https://github.com/clone/url.git', html_url: 'https://github.com/html/url', @@ -569,11 +569,11 @@ describe('publish:github', () => { }); it('should call enableBranchProtectionOnDefaultRepoBranch with the correct values of requireCodeOwnerReviews', async () => { - mockGithubClient.users.getByUsername.mockResolvedValue({ + mockGithubClient.rest.users.getByUsername.mockResolvedValue({ data: { type: 'User' }, }); - mockGithubClient.repos.createForAuthenticatedUser.mockResolvedValue({ + mockGithubClient.rest.repos.createForAuthenticatedUser.mockResolvedValue({ data: { name: 'repository', }, diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts index 3e529b1f17015..081f9616ac856 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/github.ts @@ -155,20 +155,20 @@ export function createPublishGithubAction(options: { repoUrl, ); - const user = await client.users.getByUsername({ + const user = await client.rest.users.getByUsername({ username: owner, }); const repoCreationPromise = user.data.type === 'Organization' - ? client.repos.createInOrg({ + ? client.rest.repos.createInOrg({ name: repo, org: owner, private: repoVisibility === 'private', visibility: repoVisibility, description: description, }) - : client.repos.createForAuthenticatedUser({ + : client.rest.repos.createForAuthenticatedUser({ name: repo, private: repoVisibility === 'private', description: description, @@ -177,7 +177,7 @@ export function createPublishGithubAction(options: { const { data: newRepo } = await repoCreationPromise; if (access?.startsWith(`${owner}/`)) { const [, team] = access.split('/'); - await client.teams.addOrUpdateRepoPermissionsInOrg({ + await client.rest.teams.addOrUpdateRepoPermissionsInOrg({ org: owner, team_slug: team, owner, @@ -186,7 +186,7 @@ export function createPublishGithubAction(options: { }); // No need to add access if it's the person who owns the personal account } else if (access && access !== owner) { - await client.repos.addCollaborator({ + await client.rest.repos.addCollaborator({ owner, repo, username: access, @@ -200,7 +200,7 @@ export function createPublishGithubAction(options: { username: team_slug, } of collaborators) { try { - await client.teams.addOrUpdateRepoPermissionsInOrg({ + await client.rest.teams.addOrUpdateRepoPermissionsInOrg({ org: owner, team_slug, owner, @@ -218,7 +218,7 @@ export function createPublishGithubAction(options: { if (topics) { try { - await client.repos.replaceAllTopics({ + await client.rest.repos.replaceAllTopics({ owner, repo, names: topics.map(t => t.toLowerCase()), diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts index 7b3e89ac2a782..841d4c7a82248 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts @@ -24,7 +24,7 @@ import { } from '@backstage/integration'; import { zipObject } from 'lodash'; import { createTemplateAction } from '../../createTemplateAction'; -import { Octokit } from '@octokit/rest'; +import { Octokit } from 'octokit'; import { InputError, CustomErrorBase } from '@backstage/errors'; import { createPullRequest } from 'octokit-plugin-create-pull-request'; import globby from 'globby'; diff --git a/yarn.lock b/yarn.lock index 0df29fb7d7eec..200406631cd6e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4209,6 +4209,35 @@ puka "^1.0.1" read-package-json-fast "^2.0.1" +"@octokit/app@^12.0.4": + version "12.0.5" + resolved "https://registry.npmjs.org/@octokit/app/-/app-12.0.5.tgz#0b25446daffcb36967b26944410eab1ccbba0c06" + integrity sha512-lM3pIfx2h+UbvsXHFVs1ApJ9Rmp8LO4ciFSr5q/9MdHmhsH6WtwayieUn875xwB77IoR9r8czxxxASu2WCtdeA== + dependencies: + "@octokit/auth-app" "^3.3.0" + "@octokit/auth-unauthenticated" "^2.0.4" + "@octokit/core" "^3.4.0" + "@octokit/oauth-app" "^3.3.2" + "@octokit/plugin-paginate-rest" "^2.13.3" + "@octokit/types" "^6.27.1" + "@octokit/webhooks" "^9.0.1" + +"@octokit/auth-app@^3.3.0": + version "3.6.1" + resolved "https://registry.npmjs.org/@octokit/auth-app/-/auth-app-3.6.1.tgz#aa5b02cc211175cbc28ce6c03c73373c1206d632" + integrity sha512-6oa6CFphIYI7NxxHrdVOzhG7hkcKyGyYocg7lNDSJVauVOLtylg8hNJzoUyPAYKKK0yUeoZamE/lMs2tG+S+JA== + dependencies: + "@octokit/auth-oauth-app" "^4.3.0" + "@octokit/auth-oauth-user" "^1.2.3" + "@octokit/request" "^5.6.0" + "@octokit/request-error" "^2.1.0" + "@octokit/types" "^6.0.3" + "@types/lru-cache" "^5.1.0" + deprecation "^2.3.1" + lru-cache "^6.0.0" + universal-github-app-jwt "^1.0.1" + universal-user-agent "^6.0.0" + "@octokit/auth-app@^3.4.0": version "3.4.0" resolved "https://registry.npmjs.org/@octokit/auth-app/-/auth-app-3.4.0.tgz#af9f68512e7b8dd071b49e1470a1ddf88ff6a3a3" @@ -4225,6 +4254,19 @@ universal-github-app-jwt "^1.0.1" universal-user-agent "^6.0.0" +"@octokit/auth-oauth-app@^4.0.0", "@octokit/auth-oauth-app@^4.3.0": + version "4.3.0" + resolved "https://registry.npmjs.org/@octokit/auth-oauth-app/-/auth-oauth-app-4.3.0.tgz#de02f184360ffd7cfccef861053784fc4410e7ea" + integrity sha512-cETmhmOQRHCz6cLP7StThlJROff3A/ln67Q961GuIr9zvyFXZ4lIJy9RE6Uw5O7D8IXWPU3jhDnG47FTSGQr8Q== + dependencies: + "@octokit/auth-oauth-device" "^3.1.1" + "@octokit/auth-oauth-user" "^1.2.1" + "@octokit/request" "^5.3.0" + "@octokit/types" "^6.0.3" + "@types/btoa-lite" "^1.0.0" + btoa-lite "^1.0.0" + universal-user-agent "^6.0.0" + "@octokit/auth-oauth-app@^4.1.0": version "4.1.2" resolved "https://registry.npmjs.org/@octokit/auth-oauth-app/-/auth-oauth-app-4.1.2.tgz#bf3ff30c260e6e9f10b950386f279befb8fe907d" @@ -4260,6 +4302,18 @@ btoa-lite "^1.0.0" universal-user-agent "^6.0.0" +"@octokit/auth-oauth-user@^1.3.0": + version "1.3.0" + resolved "https://registry.npmjs.org/@octokit/auth-oauth-user/-/auth-oauth-user-1.3.0.tgz#da4e4529145181a6aa717ae858afb76ebd6e3360" + integrity sha512-3QC/TAdk7onnxfyZ24BnJRfZv8TRzQK7SEFUS9vLng4Vv6Hv6I64ujdk/CUkREec8lhrwU764SZ/d+yrjjqhaQ== + dependencies: + "@octokit/auth-oauth-device" "^3.1.1" + "@octokit/oauth-methods" "^1.1.0" + "@octokit/request" "^5.4.14" + "@octokit/types" "^6.12.2" + btoa-lite "^1.0.0" + universal-user-agent "^6.0.0" + "@octokit/auth-token@^2.4.4": version "2.4.4" resolved "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-2.4.4.tgz#ee31c69b01d0378c12fd3ffe406030f3d94d3b56" @@ -4267,6 +4321,14 @@ dependencies: "@octokit/types" "^6.0.0" +"@octokit/auth-unauthenticated@^2.0.0", "@octokit/auth-unauthenticated@^2.0.4": + version "2.1.0" + resolved "https://registry.npmjs.org/@octokit/auth-unauthenticated/-/auth-unauthenticated-2.1.0.tgz#ef97de366836e09f130de4e2205be955f9cf131c" + integrity sha512-+baofLfSL0CAv3CfGQ9rxiZZQEX8VNJMGuuS4PgrMRBUL52Ho5+hQYb63UJQshw7EXYMPDZxbXznc0y33cbPqw== + dependencies: + "@octokit/request-error" "^2.1.0" + "@octokit/types" "^6.0.3" + "@octokit/core@^3.2.3": version "3.2.4" resolved "https://registry.npmjs.org/@octokit/core/-/core-3.2.4.tgz#5791256057a962eca972e31818f02454897fd106" @@ -4279,7 +4341,7 @@ before-after-hook "^2.1.0" universal-user-agent "^6.0.0" -"@octokit/core@^3.5.1": +"@octokit/core@^3.3.2", "@octokit/core@^3.4.0", "@octokit/core@^3.5.1": version "3.5.1" resolved "https://registry.npmjs.org/@octokit/core/-/core-3.5.1.tgz#8601ceeb1ec0e1b1b8217b960a413ed8e947809b" integrity sha512-omncwpLVxMP+GLpLPgeGJBF6IWJFjXDS5flY5VbppePYX9XehevbDykRH9PdCdvqt9TS5AOTiDide7h0qrkHjw== @@ -4310,6 +4372,26 @@ "@octokit/types" "^6.0.3" universal-user-agent "^6.0.0" +"@octokit/oauth-app@^3.3.2", "@octokit/oauth-app@^3.5.1": + version "3.6.0" + resolved "https://registry.npmjs.org/@octokit/oauth-app/-/oauth-app-3.6.0.tgz#36f660c7eb6b5a5cd23f6207a8d95e74b6834db0" + integrity sha512-OxPw4ItQXaC2GuEXyZB7EmZ2rHvNFX4y3yAsqdFIRW7qg2HyoEPxacxza6c8wqbEEvu84b98AJ5BXm+IjPWrww== + dependencies: + "@octokit/auth-oauth-app" "^4.0.0" + "@octokit/auth-oauth-user" "^1.3.0" + "@octokit/auth-unauthenticated" "^2.0.0" + "@octokit/core" "^3.3.2" + "@octokit/oauth-authorization-url" "^4.2.1" + "@octokit/oauth-methods" "^1.2.2" + "@types/aws-lambda" "^8.10.83" + fromentries "^1.3.1" + universal-user-agent "^6.0.0" + +"@octokit/oauth-authorization-url@^4.2.1": + version "4.3.3" + resolved "https://registry.npmjs.org/@octokit/oauth-authorization-url/-/oauth-authorization-url-4.3.3.tgz#6a6ef38f243086fec882b62744f39b517528dfb9" + integrity sha512-lhP/t0i8EwTmayHG4dqLXgU+uPVys4WD/qUNvC+HfB1S1dyqULm5Yx9uKc1x79aP66U1Cb4OZeW8QU/RA9A4XA== + "@octokit/oauth-authorization-url@^4.3.1": version "4.3.1" resolved "https://registry.npmjs.org/@octokit/oauth-authorization-url/-/oauth-authorization-url-4.3.1.tgz#008d09bf427a7f61c70b5283040d60a456011a51" @@ -4326,6 +4408,17 @@ "@octokit/types" "^6.12.2" btoa-lite "^1.0.0" +"@octokit/oauth-methods@^1.2.2": + version "1.2.6" + resolved "https://registry.npmjs.org/@octokit/oauth-methods/-/oauth-methods-1.2.6.tgz#b9ac65e374b2cc55ee9dd8dcdd16558550438ea7" + integrity sha512-nImHQoOtKnSNn05uk2o76om1tJWiAo4lOu2xMAHYsNr0fwopP+Dv+2MlGvaMMlFjoqVd3fF3X5ZDTKCsqgmUaQ== + dependencies: + "@octokit/oauth-authorization-url" "^4.3.1" + "@octokit/request" "^5.4.14" + "@octokit/request-error" "^2.0.5" + "@octokit/types" "^6.12.2" + btoa-lite "^1.0.0" + "@octokit/openapi-types@^11.2.0": version "11.2.0" resolved "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-11.2.0.tgz#b38d7fc3736d52a1e96b230c1ccd4a58a2f400a6" @@ -4341,7 +4434,7 @@ resolved "https://registry.npmjs.org/@octokit/plugin-enterprise-rest/-/plugin-enterprise-rest-6.0.1.tgz#e07896739618dab8da7d4077c658003775f95437" integrity sha512-93uGjlhUD+iNg1iWhUENAtJata6w5nE+V4urXOAlIXdco6xNZtUSfYY8dzp3Udy74aqO/B5UZL80x/YMa5PKRw== -"@octokit/plugin-paginate-rest@^2.16.8": +"@octokit/plugin-paginate-rest@^2.13.3", "@octokit/plugin-paginate-rest@^2.16.8": version "2.17.0" resolved "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.17.0.tgz#32e9c7cab2a374421d3d0de239102287d791bce7" integrity sha512-tzMbrbnam2Mt4AhuyCHvpRkS0oZ5MvwwcQPYGtMv4tUa5kkzG58SVB0fcsLulOZQeRnOgdkZWkRUiyBlh0Bkyw== @@ -4381,6 +4474,22 @@ "@octokit/types" "^6.34.0" deprecation "^2.3.1" +"@octokit/plugin-retry@^3.0.9": + version "3.0.9" + resolved "https://registry.npmjs.org/@octokit/plugin-retry/-/plugin-retry-3.0.9.tgz#ae625cca1e42b0253049102acd71c1d5134788fe" + integrity sha512-r+fArdP5+TG6l1Rv/C9hVoty6tldw6cE2pRHNGmFPdyfrc696R6JjrQ3d7HdVqGwuzfyrcaLAKD7K8TX8aehUQ== + dependencies: + "@octokit/types" "^6.0.3" + bottleneck "^2.15.3" + +"@octokit/plugin-throttling@^3.5.1": + version "3.5.2" + resolved "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-3.5.2.tgz#8b1797a5f14edbca0b8af619394056ed0ed5c9b5" + integrity sha512-Eu7kfJxU8vmHqWGNszWpg+GVp2tnAfax3XQV5CkYPEE69C+KvInJXW9WajgSeW+cxYe0UVdouzCtcreGNuJo7A== + dependencies: + "@octokit/types" "^6.0.1" + bottleneck "^2.15.3" + "@octokit/request-error@^2.0.0", "@octokit/request-error@^2.0.2", "@octokit/request-error@^2.0.5", "@octokit/request-error@^2.1.0": version "2.1.0" resolved "https://registry.npmjs.org/@octokit/request-error/-/request-error-2.1.0.tgz#9e150357831bfc788d13a4fd4b1913d60c74d677" @@ -4436,7 +4545,7 @@ dependencies: "@octokit/openapi-types" "^7.3.2" -"@octokit/types@^6.34.0": +"@octokit/types@^6.26.0", "@octokit/types@^6.27.1", "@octokit/types@^6.34.0": version "6.34.0" resolved "https://registry.npmjs.org/@octokit/types/-/types-6.34.0.tgz#c6021333334d1ecfb5d370a8798162ddf1ae8218" integrity sha512-s1zLBjWhdEI2zwaoSgyOFoKSl109CUcVBCc7biPJ3aAf6LGLU6szDvi31JPU7bxfla2lqfhjbbg/5DdFNxOwHw== @@ -4453,7 +4562,7 @@ resolved "https://registry.npmjs.org/@octokit/webhooks-types/-/webhooks-types-5.2.0.tgz#9d1d451f37460107409c81cab04dd473108abb02" integrity sha512-OZhKy1w8/GF4GWtdiJc+o8sloWAHRueGB78FWFLZnueK7EHV9MzDVr4weJZMflJwMK4uuYLzcnJVnAoy3yB35g== -"@octokit/webhooks@^9.14.1": +"@octokit/webhooks@^9.0.1", "@octokit/webhooks@^9.14.1": version "9.22.0" resolved "https://registry.npmjs.org/@octokit/webhooks/-/webhooks-9.22.0.tgz#07a36a10358d39c1870758fae2b1ad3c24ca578d" integrity sha512-wUd7nGfDRHG6xkz311djmq6lIB2tQ+r94SNkyv9o0bQhOsrkwH8fQCM7uVsbpkGUU2lqCYsVoa8z/UC9HJgRaw== @@ -5233,6 +5342,11 @@ resolved "https://registry.npmjs.org/@types/aria-query/-/aria-query-4.2.0.tgz#14264692a9d6e2fa4db3df5e56e94b5e25647ac0" integrity sha512-iIgQNzCm0v7QMhhe4Jjn9uRh+I6GoPmt03CbEtwx3ao8/EfoQcmgtqH4vQ5Db/lxiIGaWDv6nwvunuh0RyX0+A== +"@types/aws-lambda@^8.10.83": + version "8.10.92" + resolved "https://registry.npmjs.org/@types/aws-lambda/-/aws-lambda-8.10.92.tgz#645f769ff88b8eba1acd35542695ac322c7757c4" + integrity sha512-dB14TltT1SNq73z3MaZfKyyBZ37NAgAFl8jze59bisR4fJ6pB6AYGxItHFkooZbN7UcVJX/cFudM4p8wp1W4rA== + "@types/aws4@^1.5.1": version "1.5.2" resolved "https://registry.npmjs.org/@types/aws4/-/aws4-1.5.2.tgz#34e35b4405a619b9205be3e7678963bc7c8a47db" @@ -8083,6 +8197,11 @@ boolbase@^1.0.0, boolbase@~1.0.0: resolved "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e" integrity sha1-aN/1++YMUes3cl6p4+0xDcwed24= +bottleneck@^2.15.3: + version "2.19.5" + resolved "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz#5df0b90f59fd47656ebe63c78a98419205cadd91" + integrity sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw== + boxen@^1.3.0: version "1.3.0" resolved "https://registry.npmjs.org/boxen/-/boxen-1.3.0.tgz#55c6c39a8ba58d9c61ad22cd877532deb665a20b" @@ -12513,6 +12632,11 @@ from@~0: resolved "https://registry.npmjs.org/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe" integrity sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4= +fromentries@^1.3.1: + version "1.3.2" + resolved "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz#e4bca6808816bf8f93b52750f1127f5a6fd86e3a" + integrity sha512-cHEpEQHUg0f8XdtZCc2ZAhrHzKzT0MrFUTcvx+hfxYu7rGMDc5SKoXFh+n4YigxsHXRzc6OrCshdR1bWH6HHyg== + fs-constants@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" @@ -18434,6 +18558,20 @@ octokit-plugin-create-pull-request@^3.10.0: dependencies: "@octokit/types" "^6.8.2" +octokit@^1.7.1: + version "1.7.1" + resolved "https://registry.npmjs.org/octokit/-/octokit-1.7.1.tgz#d86e51c8e0cec65cb64822ca2c9ff1b052593799" + integrity sha512-1b7eRgU8uWetHOWr8f9ptnVo2EKbrkOfocMeQdpgCt7tl/LK67HptFsy2Xg4fMjsJ/+onoBJW0hy/fO0In3/uA== + dependencies: + "@octokit/app" "^12.0.4" + "@octokit/core" "^3.5.1" + "@octokit/oauth-app" "^3.5.1" + "@octokit/plugin-paginate-rest" "^2.16.8" + "@octokit/plugin-rest-endpoint-methods" "^5.12.0" + "@octokit/plugin-retry" "^3.0.9" + "@octokit/plugin-throttling" "^3.5.1" + "@octokit/types" "^6.26.0" + oidc-token-hash@^5.0.1: version "5.0.1" resolved "https://registry.npmjs.org/oidc-token-hash/-/oidc-token-hash-5.0.1.tgz#ae6beec3ec20f0fd885e5400d175191d6e2f10c6"