Skip to content

Commit

Permalink
Replace @octokit/rest in scaffolder-backend
Browse files Browse the repository at this point in the history
Signed-off-by: Crevil <bjoern.soerensen@gmail.com>
  • Loading branch information
Crevil committed Jan 26, 2022
1 parent 3bbf612 commit 2e0dbb0
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 87 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-teachers-remain.md
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': minor
---

Migrate from deprecated package @octokit/rest to octokit
2 changes: 1 addition & 1 deletion plugins/scaffolder-backend/package.json
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Expand Up @@ -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(),
},
},
};

Expand Down
Expand Up @@ -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 = {
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

jest.mock('@octokit/rest');
jest.mock('octokit');
import { TemplateAction } from '../../types';
import { createGithubActionsDispatchAction } from './githubActionsDispatch';

Expand Down Expand Up @@ -54,7 +54,7 @@ describe('github:actions:dispatch', () => {
createTemporaryDirectory: jest.fn(),
};

const { mockGithubClient } = require('@octokit/rest');
const { mockGithubClient } = require('octokit');

beforeEach(() => {
jest.resetAllMocks();
Expand Down
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

jest.mock('@octokit/rest');
jest.mock('octokit');

import { createGithubWebhookAction } from './githubWebhook';
import {
Expand Down Expand Up @@ -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';
Expand All @@ -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'],
Expand All @@ -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'],
Expand All @@ -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'],
Expand All @@ -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'],
Expand All @@ -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'],
Expand All @@ -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'],
Expand All @@ -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'],
Expand Down
Expand Up @@ -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: {
Expand Down
Expand Up @@ -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 = {
Expand Down Expand Up @@ -139,7 +139,7 @@ export const enableBranchProtectionOnDefaultRepoBranch = async ({
}: BranchProtectionOptions): Promise<void> => {
const tryOnce = async () => {
try {
await client.repos.updateBranchProtection({
await client.rest.repos.updateBranchProtection({
mediaType: {
/**
* 👇 we need this preview because allowing a custom
Expand Down

0 comments on commit 2e0dbb0

Please sign in to comment.