From 048ff38519b913b457436f602e45289bf63ece09 Mon Sep 17 00:00:00 2001 From: Matt Travi Date: Mon, 1 Jul 2024 22:51:03 -0500 Subject: [PATCH] refactor(repository): leverage extracted github plugin for scaffolding repo --- package-lock.json | 14 ++++++++++++++ package.json | 1 + src/scaffolder.js | 8 ++++---- src/scaffolder.test.js | 35 +++++++++++++---------------------- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9b418af9..700ce70d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.0.0-semantically-released", "license": "MIT", "dependencies": { + "@form8ion/github": "^1.0.0-alpha.3", "@form8ion/overridable-prompts": "^1.1.0", "@form8ion/repository-settings": "^1.0.0-alpha.1", "@octokit/rest": "^20.0.0", @@ -3252,6 +3253,19 @@ "eslint-plugin-cucumber": "2.0.0" } }, + "node_modules/@form8ion/github": { + "version": "1.0.0-alpha.3", + "resolved": "https://registry.npmjs.org/@form8ion/github/-/github-1.0.0-alpha.3.tgz", + "integrity": "sha512-3ne1G6AOSc2hCsc+bmJhadZWVafU7jlFaqOHww4pWvesDM5JO4E6hbswX9lbQPaDwsFr8PyIdJYYkDfZdpkzWw==", + "dependencies": { + "@octokit/rest": "^20.0.0", + "@travi/cli-messages": "^1.1.1", + "octokit-auth-netrc": "^3.1.1" + }, + "engines": { + "node": "^18.17 || >=20.6.1" + } + }, "node_modules/@form8ion/overridable-prompts": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@form8ion/overridable-prompts/-/overridable-prompts-1.2.0.tgz", diff --git a/package.json b/package.json index 288835d5..5ca74d8c 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ } }, "dependencies": { + "@form8ion/github": "^1.0.0-alpha.3", "@form8ion/overridable-prompts": "^1.1.0", "@form8ion/repository-settings": "^1.0.0-alpha.1", "@octokit/rest": "^20.0.0", diff --git a/src/scaffolder.js b/src/scaffolder.js index 0bf24182..238d4632 100644 --- a/src/scaffolder.js +++ b/src/scaffolder.js @@ -1,9 +1,9 @@ import {info} from '@travi/cli-messages'; import {scaffold as scaffoldSettings} from '@form8ion/repository-settings'; +import {scaffold as scaffoldGithub} from '@form8ion/github'; -import create from './create'; -import {factory} from './github-client-factory'; -import nextStepsAdder from './next-steps'; +import {factory} from './github-client-factory.js'; +import nextStepsAdder from './next-steps.js'; export async function scaffold({name, owner, projectRoot, description, homepage, visibility, tags, nextSteps}) { info('Generating GitHub'); @@ -12,7 +12,7 @@ export async function scaffold({name, owner, projectRoot, description, homepage, const [, creationResult] = await Promise.all([ scaffoldSettings({projectRoot, projectName: name, description, homepage, visibility, topics: tags}), - ...octokit ? [create(name, owner, visibility, octokit)] : [] + scaffoldGithub({name, owner, visibility}) ]); const nextStepsResult = await nextStepsAdder(octokit, nextSteps, name, owner); diff --git a/src/scaffolder.test.js b/src/scaffolder.test.js index d0bd2a1b..db7d298e 100644 --- a/src/scaffolder.test.js +++ b/src/scaffolder.test.js @@ -1,16 +1,18 @@ +import {scaffold as scaffoldGithub} from '@form8ion/github'; +import {scaffold as scaffoldSettings} from '@form8ion/repository-settings'; + import {afterEach, describe, expect, it, vi} from 'vitest'; import any from '@travi/any'; import {when} from 'jest-when'; -import * as creator from './create'; -import * as clientFactory from './github-client-factory'; -import * as nextSteps from './next-steps'; -import {scaffold} from './scaffolder'; +import * as clientFactory from './github-client-factory.js'; +import * as nextSteps from './next-steps.js'; +import {scaffold} from './scaffolder.js'; vi.mock('@form8ion/repository-settings'); -vi.mock('./create'); -vi.mock('./github-client-factory'); -vi.mock('./next-steps'); +vi.mock('@form8ion/github'); +vi.mock('./github-client-factory.js'); +vi.mock('./next-steps.js'); describe('github', () => { const projectRoot = any.string(); @@ -30,8 +32,8 @@ describe('github', () => { const octokitClient = any.simpleObject(); const topics = any.listOf(any.word); const providedNextSteps = any.listOf(any.simpleObject); - when(creator.default) - .calledWith(projectName, projectOwner, visibility, octokitClient) + when(scaffoldGithub) + .calledWith({name: projectName, owner: projectOwner, visibility}) .mockResolvedValue(creationResult); when(nextSteps.default) .calledWith(octokitClient, providedNextSteps, projectName, projectOwner) @@ -48,18 +50,7 @@ describe('github', () => { tags: topics, nextSteps: providedNextSteps })).toEqual({...creationResult, ...nextStepsResult}); - }); - - it('should not create the repo if an octokit client is not available', async () => { - clientFactory.factory.mockReturnValue(undefined); - - expect(await scaffold({ - projectRoot, - name: projectName, - owner: projectOwner, - description, - homepage, - visibility - })).toEqual({}); + expect(scaffoldSettings) + .toHaveBeenCalledWith({projectRoot, projectName, description, homepage, visibility, topics}); }); });