Skip to content

Commit 0297618

Browse files
committed
feat(vcs-host): remove requirement to provide a prompt as plugins are 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
1 parent 7954df4 commit 0297618

File tree

7 files changed

+8
-32
lines changed

7 files changed

+8
-32
lines changed

src/vcs/host/prompt.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export default async function (hosts, visibility, decisions) {
1212
}], decisions);
1313
const host = hosts[answers[questionNames.REPO_HOST]];
1414

15-
return {...answers, ...host && await host.prompt({decisions})};
15+
return {...answers, ...host};
1616
}

src/vcs/host/prompt.test.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,8 @@ describe('vcs host details prompt', () => {
2323
it('should prompt for the vcs hosting details', async () => {
2424
const host = any.string();
2525
const hostNames = [...any.listOf(any.string), host];
26-
const hostPrompt = vi.fn();
27-
const hosts = any.objectWithKeys(
28-
hostNames,
29-
{factory: key => ({prompt: host === key ? hostPrompt : () => undefined})}
30-
);
26+
const hosts = any.objectWithKeys(hostNames, {factory: () => ({})});
3127
const answersWithHostChoice = {...answers, [questionNames.REPO_HOST]: host};
32-
const hostAnswers = any.simpleObject();
33-
when(hostPrompt).calledWith({decisions}).mockResolvedValue(hostAnswers);
3428
when(conditionals.filterChoicesByVisibility).calledWith(hosts, null).mockReturnValue(filteredHostChoices);
3529
when(prompts.prompt).calledWith([{
3630
name: questionNames.REPO_HOST,
@@ -39,7 +33,7 @@ describe('vcs host details prompt', () => {
3933
choices: filteredHostChoices
4034
}], decisions).mockResolvedValue(answersWithHostChoice);
4135

42-
expect(await promptForVcsHostDetails(hosts, null, decisions)).toEqual({...answersWithHostChoice, ...hostAnswers});
36+
expect(await promptForVcsHostDetails(hosts, null, decisions)).toEqual(answersWithHostChoice);
4337
});
4438

4539
it('should not throw an error when `Other` is chosen as the host', async () => {

src/vcs/host/scaffolder.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ import terminalPromptFactory from '../../prompts/terminal-prompt.js';
33
import promptForVcsHostDetails from './prompt.js';
44

55
export default async function (hosts, visibility, decisions, options) {
6-
const {
7-
[questionNames.REPO_HOST]: chosenHost,
8-
[questionNames.REPO_OWNER]: owner
9-
} = await promptForVcsHostDetails(hosts, visibility, decisions);
6+
const {[questionNames.REPO_HOST]: chosenHost} = await promptForVcsHostDetails(hosts, visibility, decisions);
107

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

16-
if (host) return host.scaffold({...options, owner}, {prompt: terminalPromptFactory(decisions)});
13+
if (host) return host.scaffold(options, {prompt: terminalPromptFactory(decisions)});
1714

1815
return {vcs: {}};
1916
}

src/vcs/host/scaffolder.test.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ describe('vcs host scaffolder', () => {
2626
when(promptForVcsHostDetails)
2727
.calledWith(hostPlugins, visibility, decisions)
2828
.mockResolvedValue({[questionNames.REPO_HOST]: chosenHost, [questionNames.REPO_OWNER]: owner});
29-
when(chosenHostScaffolder)
30-
.calledWith({...options, owner}, {prompt: terminalPrompt})
31-
.mockResolvedValue(results);
29+
when(chosenHostScaffolder).calledWith(options, {prompt: terminalPrompt}).mockResolvedValue(results);
3230

33-
expect(await scaffoldVcsHost(hostPlugins, visibility, decisions, options))
34-
.toEqual(results);
31+
expect(await scaffoldVcsHost(hostPlugins, visibility, decisions, options)).toEqual(results);
3532
});
3633

3734
it('should return empty `vcs` results when no matching host is available', async () => {

src/vcs/host/schema.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import joi from 'joi';
22
import {optionsSchemas} from '@form8ion/core';
33

44
export default joi.object().pattern(/^/, optionsSchemas.form8ionPlugin.keys({
5-
prompt: joi.func().required(),
65
public: joi.bool(),
76
private: joi.bool()
87
}));

src/vcs/host/schema.test.js

-10
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ describe('vcs-host plugins schema', () => {
4444
.toThrowError(`"${key}.scaffold" must have an arity of 1`);
4545
});
4646

47-
it('should require a `prompt` property', () => {
48-
expect(() => validateOptions(vcsHostSchema, {[key]: {scaffold: foo => foo}}))
49-
.toThrowError(`"${key}.prompt" is required`);
50-
});
51-
52-
it('should require the `prompt` to be a function', () => {
53-
expect(() => validateOptions(vcsHostSchema, {[key]: {scaffold: foo => foo, prompt: any.word()}}))
54-
.toThrowError(`"${key}.prompt" must be of type function`);
55-
});
56-
5747
it('should require the `public` property to be a boolean', () => {
5848
expect(() => validateOptions(
5949
vcsHostSchema,

test/integration/features/step_definitions/common-steps.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ When(/^the project is scaffolded$/, async function () {
7575
[vcsHost]: {
7676
scaffold: ({projectName, owner}) => ({
7777
vcs: {sshUrl: this.remoteOriginUrl, name: projectName, owner, host: vcsHost}
78-
}),
79-
prompt: () => undefined
78+
})
8079
}
8180
}
8281
}

0 commit comments

Comments
 (0)