Skip to content

Commit

Permalink
feat(vcs-host): remove requirement to provide a prompt as plugins a…
Browse files Browse the repository at this point in the history
…re now expected to internally

BREAKING CHANGE: `owner` is no longer prompted for or provided as input to the `scaffold` function
of vcs-host plugins. plugins are expected to do this prompted internally within the `scaffold`
function instead. remove the `prompt` function from provided plugins
  • Loading branch information
travi committed Jul 30, 2024
1 parent 7954df4 commit 0297618
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/vcs/host/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export default async function (hosts, visibility, decisions) {
}], decisions);
const host = hosts[answers[questionNames.REPO_HOST]];

return {...answers, ...host && await host.prompt({decisions})};
return {...answers, ...host};
}
10 changes: 2 additions & 8 deletions src/vcs/host/prompt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ describe('vcs host details prompt', () => {
it('should prompt for the vcs hosting details', async () => {
const host = any.string();
const hostNames = [...any.listOf(any.string), host];
const hostPrompt = vi.fn();
const hosts = any.objectWithKeys(
hostNames,
{factory: key => ({prompt: host === key ? hostPrompt : () => undefined})}
);
const hosts = any.objectWithKeys(hostNames, {factory: () => ({})});
const answersWithHostChoice = {...answers, [questionNames.REPO_HOST]: host};
const hostAnswers = any.simpleObject();
when(hostPrompt).calledWith({decisions}).mockResolvedValue(hostAnswers);
when(conditionals.filterChoicesByVisibility).calledWith(hosts, null).mockReturnValue(filteredHostChoices);
when(prompts.prompt).calledWith([{
name: questionNames.REPO_HOST,
Expand All @@ -39,7 +33,7 @@ describe('vcs host details prompt', () => {
choices: filteredHostChoices
}], decisions).mockResolvedValue(answersWithHostChoice);

expect(await promptForVcsHostDetails(hosts, null, decisions)).toEqual({...answersWithHostChoice, ...hostAnswers});
expect(await promptForVcsHostDetails(hosts, null, decisions)).toEqual(answersWithHostChoice);
});

it('should not throw an error when `Other` is chosen as the host', async () => {
Expand Down
7 changes: 2 additions & 5 deletions src/vcs/host/scaffolder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import terminalPromptFactory from '../../prompts/terminal-prompt.js';
import promptForVcsHostDetails from './prompt.js';

export default async function (hosts, visibility, decisions, options) {
const {
[questionNames.REPO_HOST]: chosenHost,
[questionNames.REPO_OWNER]: owner
} = await promptForVcsHostDetails(hosts, visibility, decisions);
const {[questionNames.REPO_HOST]: chosenHost} = await promptForVcsHostDetails(hosts, visibility, decisions);

const lowercasedHosts = Object.fromEntries(
Object.entries(hosts).map(([name, details]) => [name.toLowerCase(), details])
);
const host = lowercasedHosts[chosenHost.toLowerCase()];

if (host) return host.scaffold({...options, owner}, {prompt: terminalPromptFactory(decisions)});
if (host) return host.scaffold(options, {prompt: terminalPromptFactory(decisions)});

return {vcs: {}};
}
7 changes: 2 additions & 5 deletions src/vcs/host/scaffolder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ describe('vcs host scaffolder', () => {
when(promptForVcsHostDetails)
.calledWith(hostPlugins, visibility, decisions)
.mockResolvedValue({[questionNames.REPO_HOST]: chosenHost, [questionNames.REPO_OWNER]: owner});
when(chosenHostScaffolder)
.calledWith({...options, owner}, {prompt: terminalPrompt})
.mockResolvedValue(results);
when(chosenHostScaffolder).calledWith(options, {prompt: terminalPrompt}).mockResolvedValue(results);

expect(await scaffoldVcsHost(hostPlugins, visibility, decisions, options))
.toEqual(results);
expect(await scaffoldVcsHost(hostPlugins, visibility, decisions, options)).toEqual(results);
});

it('should return empty `vcs` results when no matching host is available', async () => {
Expand Down
1 change: 0 additions & 1 deletion src/vcs/host/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import joi from 'joi';
import {optionsSchemas} from '@form8ion/core';

export default joi.object().pattern(/^/, optionsSchemas.form8ionPlugin.keys({
prompt: joi.func().required(),
public: joi.bool(),
private: joi.bool()
}));
10 changes: 0 additions & 10 deletions src/vcs/host/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,6 @@ describe('vcs-host plugins schema', () => {
.toThrowError(`"${key}.scaffold" must have an arity of 1`);
});

it('should require a `prompt` property', () => {
expect(() => validateOptions(vcsHostSchema, {[key]: {scaffold: foo => foo}}))
.toThrowError(`"${key}.prompt" is required`);
});

it('should require the `prompt` to be a function', () => {
expect(() => validateOptions(vcsHostSchema, {[key]: {scaffold: foo => foo, prompt: any.word()}}))
.toThrowError(`"${key}.prompt" must be of type function`);
});

it('should require the `public` property to be a boolean', () => {
expect(() => validateOptions(
vcsHostSchema,
Expand Down
3 changes: 1 addition & 2 deletions test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ When(/^the project is scaffolded$/, async function () {
[vcsHost]: {
scaffold: ({projectName, owner}) => ({
vcs: {sshUrl: this.remoteOriginUrl, name: projectName, owner, host: vcsHost}
}),
prompt: () => undefined
})
}
}
}
Expand Down

0 comments on commit 0297618

Please sign in to comment.