Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
refactor(repository): leverage extracted github plugin for scaffoldin…
Browse files Browse the repository at this point in the history
…g repo
  • Loading branch information
travi committed Jul 2, 2024
1 parent cedc8dc commit 048ff38
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/scaffolder.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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);
Expand Down
35 changes: 13 additions & 22 deletions src/scaffolder.test.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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)
Expand All @@ -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});
});
});

0 comments on commit 048ff38

Please sign in to comment.