-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
121 lines (109 loc) · 3.81 KB
/
example.js
File metadata and controls
121 lines (109 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// #### Import
// remark-usage-ignore-next 4
import {resolve} from 'node:path';
import stubbedFs from 'mock-fs';
import {http, HttpResponse} from 'msw';
import {setupServer} from 'msw/node';
import any from '@travi/any';
import {Octokit} from '@octokit/core';
import {lift, promptConstants, scaffold, test} from './lib/index.js';
// remark-usage-ignore-next 17
stubbedFs({node_modules: stubbedFs.load(resolve('node_modules'))});
const server = setupServer();
const organizationName = 'organization-name';
const projectName = 'project-name';
server.use(
http.get('https://api.github.com/user', () => HttpResponse.json({login: any.word()})),
http.get('https://api.github.com/user/orgs', () => HttpResponse.json([
{login: organizationName, id: any.integer()}
])),
http.post('https://api.github.com/orgs/organization-name/repos', () => HttpResponse.json({})),
http.get('https://api.github.com/search/issues', () => HttpResponse.json({items: []})),
http.post(`https://api.github.com/repos/${organizationName}/${projectName}/issues`, () => HttpResponse.json({})),
http.get(`https://api.github.com/orgs/${organizationName}/teams`, () => HttpResponse.json([
{slug: 'maintainers', name: 'maintainers', id: any.integer()}
]))
);
server.listen();
// #### Execute
// remark-usage-ignore-next
/* eslint-disable no-console */
const projectRoot = process.cwd();
const octokitInstance = new Octokit();
const logger = {
info: message => console.error(message),
success: message => console.error(message),
warn: message => console.error(message),
error: message => console.error(message)
};
await scaffold(
{
projectRoot,
projectName: 'project-name',
visibility: any.fromList(['Public', 'Private']),
description: any.sentence()
},
{
prompt: async ({id, questions}) => {
const {questionNames, ids} = promptConstants;
const {
GITHUB_DETAILS: githubDetailsPromptId,
ADMIN_SETTINGS: repositorySettingsPromptId
} = ids;
switch (id) {
case githubDetailsPromptId: {
const {
ORGANIZATION: organizationQuestionName,
ACCOUNT_TYPE: accountTypeQuestionName
} = questionNames[githubDetailsPromptId];
return {
[accountTypeQuestionName]: 'organization',
[organizationQuestionName]: questions
.find(({name}) => name === organizationQuestionName)
.choices
.find(({short}) => 'organization-name' === short).value
};
}
case repositorySettingsPromptId:
return {[questionNames[repositorySettingsPromptId].SETTINGS_MANAGED_AS_CODE]: any.boolean()};
default:
throw new Error(`Unknown prompt with ID: ${id}`);
}
},
octokit: octokitInstance,
logger
}
);
if (await test({projectRoot})) {
await lift(
{
projectRoot,
vcs: {owner: 'organization-name', name: 'project-name'},
results: {
projectDetails: {homepage: any.url()},
tags: any.listOf(any.word),
nextSteps: any.listOf(() => ({summary: any.sentence(), description: any.sentence()}))
}
},
{
octokit: octokitInstance,
logger,
prompt: async ({id, questions}) => {
const {questionNames, ids} = promptConstants;
const expectedPromptId = ids.REQUIRED_CHECK_BYPASS;
if (expectedPromptId === id) {
const {CHECK_BYPASS_TEAM: checkBypassTeamQuestionName} = questionNames[expectedPromptId];
return {
[checkBypassTeamQuestionName]: questions
.find(({name}) => name === checkBypassTeamQuestionName)
.choices
.find(({short}) => 'maintainers' === short).value
};
}
throw new Error(`Unknown prompt with ID: ${id}`);
}
}
);
}
// remark-usage-ignore-next
/* eslint-enable no-console */