@posthog/wizard 1.3.1 β 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/bin.js +1 -1
- package/dist/bin.js.map +1 -1
- package/dist/src/astro/astro-wizard.d.ts +2 -0
- package/dist/src/astro/astro-wizard.js +86 -0
- package/dist/src/astro/astro-wizard.js.map +1 -0
- package/dist/src/astro/docs.d.ts +4 -0
- package/dist/src/astro/docs.js +101 -0
- package/dist/src/astro/docs.js.map +1 -0
- package/dist/src/lib/config.d.ts +12 -1
- package/dist/src/lib/config.js +15 -0
- package/dist/src/lib/config.js.map +1 -1
- package/dist/src/lib/constants.d.ts +2 -1
- package/dist/src/lib/constants.js +3 -0
- package/dist/src/lib/constants.js.map +1 -1
- package/dist/src/lib/messages.d.ts +1 -2
- package/dist/src/lib/messages.js +2 -3
- package/dist/src/lib/messages.js.map +1 -1
- package/dist/src/nextjs/docs.js +8 -14
- package/dist/src/nextjs/docs.js.map +1 -1
- package/dist/src/nextjs/nextjs-wizard.js +0 -6
- package/dist/src/nextjs/nextjs-wizard.js.map +1 -1
- package/dist/src/react/docs.js +1 -0
- package/dist/src/react/docs.js.map +1 -1
- package/dist/src/run.js +5 -0
- package/dist/src/run.js.map +1 -1
- package/dist/src/steps/index.d.ts +0 -1
- package/dist/src/steps/index.js +0 -1
- package/dist/src/steps/index.js.map +1 -1
- package/dist/src/utils/rules/astro-rules.md +44 -0
- package/package.json +1 -1
- package/dist/src/steps/__tests__/create-pr.test.d.ts +0 -1
- package/dist/src/steps/__tests__/create-pr.test.js +0 -193
- package/dist/src/steps/__tests__/create-pr.test.js.map +0 -1
- package/dist/src/steps/create-pr.d.ts +0 -27
- package/dist/src/steps/create-pr.js +0 -305
- package/dist/src/steps/create-pr.js.map +0 -1
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.PR_CONFIG = void 0;
|
|
40
|
-
exports.execGitCommand = execGitCommand;
|
|
41
|
-
exports.getCurrentBranch = getCurrentBranch;
|
|
42
|
-
exports.checkGitHubAuth = checkGitHubAuth;
|
|
43
|
-
exports.checkBranchExists = checkBranchExists;
|
|
44
|
-
exports.createBranch = createBranch;
|
|
45
|
-
exports.stageChanges = stageChanges;
|
|
46
|
-
exports.checkForEnvFiles = checkForEnvFiles;
|
|
47
|
-
exports.commitChanges = commitChanges;
|
|
48
|
-
exports.pushBranch = pushBranch;
|
|
49
|
-
exports.createGitHubPR = createGitHubPR;
|
|
50
|
-
exports.createPRStep = createPRStep;
|
|
51
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
52
|
-
const constants_1 = require("../lib/constants");
|
|
53
|
-
const telemetry_1 = require("../telemetry");
|
|
54
|
-
const analytics_1 = require("../utils/analytics");
|
|
55
|
-
const clack_1 = __importDefault(require("../utils/clack"));
|
|
56
|
-
const clack_utils_1 = require("../utils/clack-utils");
|
|
57
|
-
const childProcess = __importStar(require("node:child_process"));
|
|
58
|
-
const messages_1 = require("../lib/messages");
|
|
59
|
-
exports.PR_CONFIG = {
|
|
60
|
-
defaultBranchName: 'posthog-integration',
|
|
61
|
-
defaultTitle: 'feat: add PostHog integration',
|
|
62
|
-
};
|
|
63
|
-
async function execGitCommand(command, cwd) {
|
|
64
|
-
return new Promise((resolve) => {
|
|
65
|
-
childProcess.exec(command, { cwd }, (err, stdout, stderr) => {
|
|
66
|
-
if (err) {
|
|
67
|
-
resolve({ success: false, error: stderr || err.message });
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
resolve({ success: true, data: stdout.trim() });
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
async function getCurrentBranch(installDir) {
|
|
76
|
-
return execGitCommand('git rev-parse --abbrev-ref HEAD', installDir);
|
|
77
|
-
}
|
|
78
|
-
async function checkGitHubAuth(installDir) {
|
|
79
|
-
return execGitCommand('gh auth status', installDir);
|
|
80
|
-
}
|
|
81
|
-
async function checkBranchExists(branch, installDir) {
|
|
82
|
-
const result = await execGitCommand(`git rev-parse --verify ${branch}`, installDir);
|
|
83
|
-
// If the command fails, the branch does not exist
|
|
84
|
-
if (!result.success) {
|
|
85
|
-
return { success: true, data: true };
|
|
86
|
-
}
|
|
87
|
-
// If the command succeeds, the branch exists
|
|
88
|
-
return { success: false, data: false };
|
|
89
|
-
}
|
|
90
|
-
async function createBranch(branch, installDir) {
|
|
91
|
-
return execGitCommand(`git checkout -b ${branch}`, installDir);
|
|
92
|
-
}
|
|
93
|
-
async function stageChanges(installDir) {
|
|
94
|
-
return execGitCommand('git add .', installDir);
|
|
95
|
-
}
|
|
96
|
-
async function checkForEnvFiles(installDir) {
|
|
97
|
-
const result = await execGitCommand('git diff --cached --name-only', installDir);
|
|
98
|
-
if (!result.success) {
|
|
99
|
-
return { success: false, error: result.error };
|
|
100
|
-
}
|
|
101
|
-
const files = result.data
|
|
102
|
-
? result.data
|
|
103
|
-
.split('\n')
|
|
104
|
-
.map((f) => f.trim())
|
|
105
|
-
.filter(Boolean)
|
|
106
|
-
: [];
|
|
107
|
-
const hasEnv = files.some((f) => f.startsWith('.env'));
|
|
108
|
-
return { success: true, data: hasEnv };
|
|
109
|
-
}
|
|
110
|
-
async function commitChanges(message, installDir) {
|
|
111
|
-
return execGitCommand(`git commit -m "${message}"`, installDir);
|
|
112
|
-
}
|
|
113
|
-
async function pushBranch(branch, installDir) {
|
|
114
|
-
return execGitCommand(`git push -u origin ${branch}`, installDir);
|
|
115
|
-
}
|
|
116
|
-
async function createGitHubPR(baseBranch, newBranch, title, body, installDir) {
|
|
117
|
-
return execGitCommand(`gh pr create --base ${baseBranch} --head ${newBranch} --title "${title}" --body "${body}"`, installDir);
|
|
118
|
-
}
|
|
119
|
-
async function createPRStep({ installDir, integration, addedEditorRules, }) {
|
|
120
|
-
return (0, telemetry_1.traceStep)('create-pr', async () => {
|
|
121
|
-
if (!(0, clack_utils_1.isInGitRepo)()) {
|
|
122
|
-
clack_1.default.log.warn('Not in a git repository. Cannot create a pull request.');
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
// Get current branch
|
|
126
|
-
const currentBranchResult = await getCurrentBranch(installDir);
|
|
127
|
-
if (!currentBranchResult.success || !currentBranchResult.data) {
|
|
128
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
129
|
-
action: 'skipping pr creation',
|
|
130
|
-
reason: 'failed to get current branch',
|
|
131
|
-
error: currentBranchResult.error,
|
|
132
|
-
integration,
|
|
133
|
-
});
|
|
134
|
-
if (constants_1.DEBUG) {
|
|
135
|
-
clack_1.default.log.error(currentBranchResult.error ?? 'Failed to get current branch');
|
|
136
|
-
}
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const baseBranch = currentBranchResult.data;
|
|
140
|
-
if (!['main', 'master'].includes(baseBranch)) {
|
|
141
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
142
|
-
action: 'skipping pr creation',
|
|
143
|
-
reason: 'not on main or master',
|
|
144
|
-
base_branch: baseBranch,
|
|
145
|
-
integration,
|
|
146
|
-
});
|
|
147
|
-
if (constants_1.DEBUG) {
|
|
148
|
-
clack_1.default.log.error(`Not on main or master. Skipping PR creation.`);
|
|
149
|
-
}
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
// Check GitHub auth
|
|
153
|
-
const authResult = await checkGitHubAuth(installDir);
|
|
154
|
-
if (!authResult.success) {
|
|
155
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
156
|
-
action: 'skipping pr creation',
|
|
157
|
-
reason: 'not logged into github',
|
|
158
|
-
integration,
|
|
159
|
-
});
|
|
160
|
-
if (constants_1.DEBUG) {
|
|
161
|
-
clack_1.default.log.error(authResult.error ?? 'Failed to check github auth');
|
|
162
|
-
}
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const newBranch = exports.PR_CONFIG.defaultBranchName;
|
|
166
|
-
// Check if branch exists
|
|
167
|
-
const branchExistsResult = await checkBranchExists(newBranch, installDir);
|
|
168
|
-
if (!branchExistsResult.success) {
|
|
169
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
170
|
-
action: 'skipping pr creation',
|
|
171
|
-
reason: 'branch already exists',
|
|
172
|
-
error: branchExistsResult.error,
|
|
173
|
-
integration,
|
|
174
|
-
});
|
|
175
|
-
if (constants_1.DEBUG) {
|
|
176
|
-
clack_1.default.log.error(branchExistsResult.error ?? 'Failed to check branch exists');
|
|
177
|
-
}
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
const prTitle = exports.PR_CONFIG.defaultTitle;
|
|
181
|
-
const prDescription = (0, messages_1.getPRDescription)({
|
|
182
|
-
integration,
|
|
183
|
-
addedEditorRules,
|
|
184
|
-
});
|
|
185
|
-
const createPR = await (0, clack_utils_1.abortIfCancelled)(clack_1.default.select({
|
|
186
|
-
message: 'Would you like to create a PR automatically?',
|
|
187
|
-
initialValue: true,
|
|
188
|
-
options: [
|
|
189
|
-
{
|
|
190
|
-
value: true,
|
|
191
|
-
label: 'Yes',
|
|
192
|
-
hint: 'We will create a PR for you',
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
value: false,
|
|
196
|
-
label: 'No',
|
|
197
|
-
hint: 'You can create a PR manually later',
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
}), integration);
|
|
201
|
-
if (!createPR) {
|
|
202
|
-
clack_1.default.log.info('Skipping PR creation');
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
// Create branch
|
|
206
|
-
const createBranchResult = await createBranch(newBranch, installDir);
|
|
207
|
-
if (!createBranchResult.success) {
|
|
208
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
209
|
-
action: 'aborting pr creation',
|
|
210
|
-
reason: 'failed to create branch',
|
|
211
|
-
error: createBranchResult.error,
|
|
212
|
-
integration,
|
|
213
|
-
});
|
|
214
|
-
clack_1.default.log.warn('Failed to create branch. Aborting PR creation πΆββ‘οΈ');
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
// Stage changes
|
|
218
|
-
const stageResult = await stageChanges(installDir);
|
|
219
|
-
if (!stageResult.success) {
|
|
220
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
221
|
-
action: 'aborting pr creation',
|
|
222
|
-
reason: 'failed to stage changes',
|
|
223
|
-
error: stageResult.error,
|
|
224
|
-
integration,
|
|
225
|
-
});
|
|
226
|
-
clack_1.default.log.warn('Failed to stage changes. Aborting PR creation πΆββ‘οΈ');
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
// Check for env files
|
|
230
|
-
const envCheckResult = await checkForEnvFiles(installDir);
|
|
231
|
-
if (!envCheckResult.success) {
|
|
232
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
233
|
-
action: 'aborting pr creation',
|
|
234
|
-
reason: 'failed to check for env files in staged changes',
|
|
235
|
-
error: envCheckResult.error,
|
|
236
|
-
integration,
|
|
237
|
-
});
|
|
238
|
-
clack_1.default.log.warn('Failed to check for .env files. Aborting PR creation πΆββ‘οΈ');
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
if (envCheckResult.data) {
|
|
242
|
-
clack_1.default.log.warn('Found .env files in staged changes. Aborting PR creation to prevent exposing sensitive data π');
|
|
243
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
244
|
-
action: 'aborting pr creation',
|
|
245
|
-
reason: 'env files detected in staged changes',
|
|
246
|
-
integration,
|
|
247
|
-
});
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
// Commit changes
|
|
251
|
-
const commitSpinner = clack_1.default.spinner();
|
|
252
|
-
commitSpinner.start('Committing changes...');
|
|
253
|
-
const commitResult = await commitChanges(prTitle, installDir);
|
|
254
|
-
if (!commitResult.success) {
|
|
255
|
-
commitSpinner.stop('Failed to commit changes. Aborting PR creation πΆββ‘οΈ');
|
|
256
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
257
|
-
action: 'aborting pr creation',
|
|
258
|
-
reason: 'failed to commit changes',
|
|
259
|
-
error: commitResult.error,
|
|
260
|
-
integration,
|
|
261
|
-
});
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
commitSpinner.stop('Changes committed successfully.');
|
|
265
|
-
// Push branch
|
|
266
|
-
const pushSpinner = clack_1.default.spinner();
|
|
267
|
-
pushSpinner.start('Pushing branch to remote...');
|
|
268
|
-
const pushResult = await pushBranch(newBranch, installDir);
|
|
269
|
-
if (!pushResult.success) {
|
|
270
|
-
pushSpinner.stop('Failed to push branch. Aborting PR creation πΆββ‘οΈ');
|
|
271
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
272
|
-
action: 'aborting pr creation',
|
|
273
|
-
reason: 'failed to push branch',
|
|
274
|
-
error: pushResult.error,
|
|
275
|
-
integration,
|
|
276
|
-
});
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
pushSpinner.stop('Branch pushed successfully.');
|
|
280
|
-
// Create PR
|
|
281
|
-
const prSpinner = clack_1.default.spinner();
|
|
282
|
-
prSpinner.start(`Creating a PR on branch '${newBranch}' with base '${baseBranch}'...`);
|
|
283
|
-
const prResult = await createGitHubPR(baseBranch, newBranch, prTitle, prDescription, installDir);
|
|
284
|
-
if (!prResult.success || !prResult.data) {
|
|
285
|
-
prSpinner.stop(`Failed to create PR on branch '${newBranch}'. Aborting PR creation πΆββ‘οΈ`);
|
|
286
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
287
|
-
action: 'aborting pr creation',
|
|
288
|
-
reason: 'failed to create pr',
|
|
289
|
-
error: prResult.error,
|
|
290
|
-
integration,
|
|
291
|
-
});
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
const prUrl = prResult.data;
|
|
295
|
-
prSpinner.stop(`Successfully created PR! π You can review it here: ${chalk_1.default.cyan(prUrl)}`);
|
|
296
|
-
analytics_1.analytics.capture('wizard interaction', {
|
|
297
|
-
action: 'pr created',
|
|
298
|
-
branch: newBranch,
|
|
299
|
-
base_branch: baseBranch,
|
|
300
|
-
integration,
|
|
301
|
-
});
|
|
302
|
-
return prUrl;
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
//# sourceMappingURL=create-pr.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-pr.js","sourceRoot":"","sources":["../../../src/steps/create-pr.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,wCAaC;AAED,4CAIC;AAED,0CAIC;AAED,8CAcC;AAED,oCAKC;AAED,oCAIC;AAED,4CAkBC;AAED,sCAKC;AAED,gCAKC;AAED,wCAWC;AAQD,oCAiPC;AAlXD,kDAA0B;AAC1B,gDAA2D;AAC3D,4CAAyC;AACzC,kDAA+C;AAC/C,2DAAmC;AACnC,sDAAqE;AACrE,iEAAmD;AACnD,8CAAmD;AAEtC,QAAA,SAAS,GAAG;IACvB,iBAAiB,EAAE,qBAAqB;IACxC,YAAY,EAAE,+BAA+B;CACrC,CAAC;AAQJ,KAAK,UAAU,cAAc,CAClC,OAAe,EACf,GAAW;IAEX,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YAC1D,IAAI,GAAG,EAAE,CAAC;gBACR,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;YAC5D,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAEM,KAAK,UAAU,gBAAgB,CACpC,UAAkB;IAElB,OAAO,cAAc,C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,CACX,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxC,SAAS,CAAC,IAAI,CACZ,kCAAkC,SAAS,+BAA+B,CAC3E,CAAC;YACF,qBAAS,CAAC,OAAO,CAAC,oBAAoB,EAAE;gBACtC,MAAM,EAAE,sBAAsB;gBAC9B,MAAM,EAAE,qBAAqB;gBAC7B,KAAK,EAAE,QAAQ,CAAC,KAAK;gBACrB,WAAW;aACZ,CAAC,CAAC;YACH,OAAO;QACT,CAAC;QAED,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC;QAC5B,SAAS,CAAC,IAAI,CACZ,uDAAuD,eAAK,CAAC,IAAI,CAC/D,KAAK,CACN,EAAE,CACJ,CAAC;QAEF,qBAAS,CAAC,OAAO,CAAC,oBAAoB,EAAE;YACtC,MAAM,EAAE,YAAY;YACpB,MAAM,EAAE,SAAS;YACjB,WAAW,EAAE,UAAU;YACvB,WAAW;SACZ,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import chalk from 'chalk';\nimport { DEBUG, type Integration } from '../lib/constants';\nimport { traceStep } from '../telemetry';\nimport { analytics } from '../utils/analytics';\nimport clack from '../utils/clack';\nimport { abortIfCancelled, isInGitRepo } from '../utils/clack-utils';\nimport * as childProcess from 'node:child_process';\nimport { getPRDescription } from '../lib/messages';\n\nexport const PR_CONFIG = {\n defaultBranchName: 'posthog-integration',\n defaultTitle: 'feat: add PostHog integration',\n} as const;\n\ninterface GitCommandResult<T> {\n success: boolean;\n data?: T;\n error?: string;\n}\n\nexport async function execGitCommand(\n command: string,\n cwd: string,\n): Promise<GitCommandResult<string>> {\n return new Promise((resolve) => {\n childProcess.exec(command, { cwd }, (err, stdout, stderr) => {\n if (err) {\n resolve({ success: false, error: stderr || err.message });\n } else {\n resolve({ success: true, data: stdout.trim() });\n }\n });\n });\n}\n\nexport async function getCurrentBranch(\n installDir: string,\n): Promise<GitCommandResult<string>> {\n return execGitCommand('git rev-parse --abbrev-ref HEAD', installDir);\n}\n\nexport async function checkGitHubAuth(\n installDir: string,\n): Promise<GitCommandResult<string>> {\n return execGitCommand('gh auth status', installDir);\n}\n\nexport async function checkBranchExists(\n branch: string,\n installDir: string,\n): Promise<GitCommandResult<boolean>> {\n const result = await execGitCommand(\n `git rev-parse --verify ${branch}`,\n installDir,\n );\n // If the command fails, the branch does not exist\n if (!result.success) {\n return { success: true, data: true };\n }\n // If the command succeeds, the branch exists\n return { success: false, data: false };\n}\n\nexport async function createBranch(\n branch: string,\n installDir: string,\n): Promise<GitCommandResult<string>> {\n return execGitCommand(`git checkout -b ${branch}`, installDir);\n}\n\nexport async function stageChanges(\n installDir: string,\n): Promise<GitCommandResult<string>> {\n return execGitCommand('git add .', installDir);\n}\n\nexport async function checkForEnvFiles(\n installDir: string,\n): Promise<GitCommandResult<boolean>> {\n const result = await execGitCommand(\n 'git diff --cached --name-only',\n installDir,\n );\n if (!result.success) {\n return { success: false, error: result.error };\n }\n const files = result.data\n ? result.data\n .split('\\n')\n .map((f) => f.trim())\n .filter(Boolean)\n : [];\n const hasEnv = files.some((f) => f.startsWith('.env'));\n return { success: true, data: hasEnv };\n}\n\nexport async function commitChanges(\n message: string,\n installDir: string,\n): Promise<GitCommandResult<string>> {\n return execGitCommand(`git commit -m \"${message}\"`, installDir);\n}\n\nexport async function pushBranch(\n branch: string,\n installDir: string,\n): Promise<GitCommandResult<string>> {\n return execGitCommand(`git push -u origin ${branch}`, installDir);\n}\n\nexport async function createGitHubPR(\n baseBranch: string,\n newBranch: string,\n title: string,\n body: string,\n installDir: string,\n): Promise<GitCommandResult<string>> {\n return execGitCommand(\n `gh pr create --base ${baseBranch} --head ${newBranch} --title \"${title}\" --body \"${body}\"`,\n installDir,\n );\n}\n\ninterface CreatePRStepOptions {\n installDir: string;\n integration: Integration;\n addedEditorRules: boolean;\n}\n\nexport async function createPRStep({\n installDir,\n integration,\n addedEditorRules,\n}: CreatePRStepOptions): Promise<string | undefined> {\n return traceStep('create-pr', async () => {\n if (!isInGitRepo()) {\n clack.log.warn('Not in a git repository. Cannot create a pull request.');\n return;\n }\n\n // Get current branch\n const currentBranchResult = await getCurrentBranch(installDir);\n if (!currentBranchResult.success || !currentBranchResult.data) {\n analytics.capture('wizard interaction', {\n action: 'skipping pr creation',\n reason: 'failed to get current branch',\n error: currentBranchResult.error,\n integration,\n });\n\n if (DEBUG) {\n clack.log.error(\n currentBranchResult.error ?? 'Failed to get current branch',\n );\n }\n\n return;\n }\n const baseBranch = currentBranchResult.data;\n\n if (!['main', 'master'].includes(baseBranch)) {\n analytics.capture('wizard interaction', {\n action: 'skipping pr creation',\n reason: 'not on main or master',\n base_branch: baseBranch,\n integration,\n });\n\n if (DEBUG) {\n clack.log.error(`Not on main or master. Skipping PR creation.`);\n }\n return;\n }\n\n // Check GitHub auth\n const authResult = await checkGitHubAuth(installDir);\n if (!authResult.success) {\n analytics.capture('wizard interaction', {\n action: 'skipping pr creation',\n reason: 'not logged into github',\n integration,\n });\n\n if (DEBUG) {\n clack.log.error(authResult.error ?? 'Failed to check github auth');\n }\n\n return;\n }\n\n const newBranch = PR_CONFIG.defaultBranchName;\n\n // Check if branch exists\n const branchExistsResult = await checkBranchExists(newBranch, installDir);\n if (!branchExistsResult.success) {\n analytics.capture('wizard interaction', {\n action: 'skipping pr creation',\n reason: 'branch already exists',\n error: branchExistsResult.error,\n integration,\n });\n\n if (DEBUG) {\n clack.log.error(\n branchExistsResult.error ?? 'Failed to check branch exists',\n );\n }\n\n return;\n }\n\n const prTitle = PR_CONFIG.defaultTitle;\n const prDescription = getPRDescription({\n integration,\n addedEditorRules,\n });\n\n const createPR = await abortIfCancelled(\n clack.select({\n message: 'Would you like to create a PR automatically?',\n initialValue: true,\n options: [\n {\n value: true,\n label: 'Yes',\n hint: 'We will create a PR for you',\n },\n {\n value: false,\n label: 'No',\n hint: 'You can create a PR manually later',\n },\n ],\n }),\n integration,\n );\n\n if (!createPR) {\n clack.log.info('Skipping PR creation');\n return;\n }\n\n // Create branch\n const createBranchResult = await createBranch(newBranch, installDir);\n if (!createBranchResult.success) {\n analytics.capture('wizard interaction', {\n action: 'aborting pr creation',\n reason: 'failed to create branch',\n error: createBranchResult.error,\n integration,\n });\n clack.log.warn('Failed to create branch. Aborting PR creation πΆββ‘οΈ');\n return;\n }\n\n // Stage changes\n const stageResult = await stageChanges(installDir);\n if (!stageResult.success) {\n analytics.capture('wizard interaction', {\n action: 'aborting pr creation',\n reason: 'failed to stage changes',\n error: stageResult.error,\n integration,\n });\n clack.log.warn('Failed to stage changes. Aborting PR creation πΆββ‘οΈ');\n return;\n }\n\n // Check for env files\n const envCheckResult = await checkForEnvFiles(installDir);\n if (!envCheckResult.success) {\n analytics.capture('wizard interaction', {\n action: 'aborting pr creation',\n reason: 'failed to check for env files in staged changes',\n error: envCheckResult.error,\n integration,\n });\n clack.log.warn(\n 'Failed to check for .env files. Aborting PR creation πΆββ‘οΈ',\n );\n return;\n }\n\n if (envCheckResult.data) {\n clack.log.warn(\n 'Found .env files in staged changes. Aborting PR creation to prevent exposing sensitive data π',\n );\n analytics.capture('wizard interaction', {\n action: 'aborting pr creation',\n reason: 'env files detected in staged changes',\n integration,\n });\n return;\n }\n\n // Commit changes\n const commitSpinner = clack.spinner();\n commitSpinner.start('Committing changes...');\n const commitResult = await commitChanges(prTitle, installDir);\n if (!commitResult.success) {\n commitSpinner.stop(\n 'Failed to commit changes. Aborting PR creation πΆββ‘οΈ',\n );\n analytics.capture('wizard interaction', {\n action: 'aborting pr creation',\n reason: 'failed to commit changes',\n error: commitResult.error,\n integration,\n });\n return;\n }\n commitSpinner.stop('Changes committed successfully.');\n\n // Push branch\n const pushSpinner = clack.spinner();\n pushSpinner.start('Pushing branch to remote...');\n const pushResult = await pushBranch(newBranch, installDir);\n if (!pushResult.success) {\n pushSpinner.stop('Failed to push branch. Aborting PR creation πΆββ‘οΈ');\n analytics.capture('wizard interaction', {\n action: 'aborting pr creation',\n reason: 'failed to push branch',\n error: pushResult.error,\n integration,\n });\n return;\n }\n pushSpinner.stop('Branch pushed successfully.');\n\n // Create PR\n const prSpinner = clack.spinner();\n prSpinner.start(\n `Creating a PR on branch '${newBranch}' with base '${baseBranch}'...`,\n );\n const prResult = await createGitHubPR(\n baseBranch,\n newBranch,\n prTitle,\n prDescription,\n installDir,\n );\n if (!prResult.success || !prResult.data) {\n prSpinner.stop(\n `Failed to create PR on branch '${newBranch}'. Aborting PR creation πΆββ‘οΈ`,\n );\n analytics.capture('wizard interaction', {\n action: 'aborting pr creation',\n reason: 'failed to create pr',\n error: prResult.error,\n integration,\n });\n return;\n }\n\n const prUrl = prResult.data;\n prSpinner.stop(\n `Successfully created PR! π You can review it here: ${chalk.cyan(\n prUrl,\n )}`,\n );\n\n analytics.capture('wizard interaction', {\n action: 'pr created',\n branch: newBranch,\n base_branch: baseBranch,\n integration,\n });\n\n return prUrl;\n });\n}\n"]}
|