@snapcommit/cli 3.8.18 → 3.8.20
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/dist/commands/github-connect.js +91 -39
- package/package.json +1 -1
|
@@ -3,6 +3,39 @@
|
|
|
3
3
|
* GitHub authentication - Auto-fetches OAuth token from SnapCommit account
|
|
4
4
|
* Falls back to manual PAT if OAuth token not available
|
|
5
5
|
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
6
39
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
40
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
41
|
};
|
|
@@ -180,61 +213,80 @@ async function githubConnectCommand(tokenArg) {
|
|
|
180
213
|
console.log(chalk_1.default.cyan(' • "list my open PRs"\n'));
|
|
181
214
|
return;
|
|
182
215
|
}
|
|
183
|
-
// Token not found -
|
|
184
|
-
console.log(chalk_1.default.yellow('\n⚠️ GitHub
|
|
185
|
-
console.log(chalk_1.default.
|
|
216
|
+
// Token not found - initiate GitHub OAuth flow
|
|
217
|
+
console.log(chalk_1.default.yellow('\n⚠️ GitHub not connected yet!\n'));
|
|
218
|
+
console.log(chalk_1.default.white("Let's connect your GitHub account!\n"));
|
|
186
219
|
const authConfig = (0, auth_1.getAuthConfig)();
|
|
187
220
|
if (!authConfig || !authConfig.token) {
|
|
188
221
|
console.log(chalk_1.default.red('❌ You must be logged in first!'));
|
|
189
222
|
console.log(chalk_1.default.gray(' Run: ') + chalk_1.default.cyan('snap login\n'));
|
|
190
223
|
return;
|
|
191
224
|
}
|
|
225
|
+
console.log(chalk_1.default.bold.cyan('🔐 Quick Setup (30 seconds):\n'));
|
|
226
|
+
console.log(chalk_1.default.gray(' 1. A browser window will open'));
|
|
227
|
+
console.log(chalk_1.default.gray(' 2. Authorize SnapCommit to access your GitHub'));
|
|
228
|
+
console.log(chalk_1.default.gray(" 3. Come back here - you'll be connected!\n"));
|
|
229
|
+
console.log(chalk_1.default.gray('This enables:\n'));
|
|
230
|
+
console.log(chalk_1.default.white(' - Create pull requests with natural language'));
|
|
231
|
+
console.log(chalk_1.default.white(' - Check CI/workflow status'));
|
|
232
|
+
console.log(chalk_1.default.white(' - Manage issues and PRs\n'));
|
|
233
|
+
console.log(chalk_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
|
|
234
|
+
console.log(chalk_1.default.cyan('🔄 Getting GitHub OAuth URL...\n'));
|
|
192
235
|
try {
|
|
193
|
-
// Call
|
|
194
|
-
const
|
|
236
|
+
// Call API to get OAuth URL
|
|
237
|
+
const response = await fetch('https://snapcommit.dev/api/github/connect', {
|
|
195
238
|
method: 'POST',
|
|
196
239
|
headers: {
|
|
197
240
|
'Content-Type': 'application/json',
|
|
198
241
|
},
|
|
199
242
|
body: JSON.stringify({ token: authConfig.token }),
|
|
200
243
|
});
|
|
201
|
-
if (
|
|
202
|
-
const
|
|
203
|
-
console.log(chalk_1.default.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
244
|
+
if (!response.ok) {
|
|
245
|
+
const error = await response.json();
|
|
246
|
+
console.log(chalk_1.default.red(`\n❌ Failed to get OAuth URL: ${error.error}\n`));
|
|
247
|
+
console.log(chalk_1.default.gray('Make sure you are logged in with an active subscription.\n'));
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const data = await response.json();
|
|
251
|
+
const oauthUrl = data.oauthUrl;
|
|
252
|
+
console.log(chalk_1.default.cyan('Opening browser for GitHub authorization...\n'));
|
|
253
|
+
// Open browser
|
|
254
|
+
const open = (await Promise.resolve().then(() => __importStar(require('open')))).default;
|
|
255
|
+
await open(oauthUrl);
|
|
256
|
+
console.log(chalk_1.default.green('✅ Browser opened!\n'));
|
|
257
|
+
console.log(chalk_1.default.gray('Waiting for you to authorize...\n'));
|
|
258
|
+
console.log(chalk_1.default.yellow('After authorization, come back here and press ENTER'));
|
|
259
|
+
// Wait for user confirmation
|
|
260
|
+
await askQuestion(chalk_1.default.cyan('\nPress ENTER after authorizing in browser: '));
|
|
261
|
+
console.log(chalk_1.default.cyan('🔄 Fetching your GitHub token...\n'));
|
|
262
|
+
// Wait a bit for the database to update
|
|
263
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
264
|
+
// Try to fetch the token
|
|
265
|
+
const autoConfig2 = await autoFetchGitHubToken();
|
|
266
|
+
if (autoConfig2) {
|
|
267
|
+
saveGitHubToken(autoConfig2);
|
|
268
|
+
console.log(chalk_1.default.green.bold('\n✅ GITHUB CONNECTED! 🎉\n'));
|
|
269
|
+
console.log(chalk_1.default.white(` Connected as: ${chalk_1.default.bold('@' + autoConfig2.username)}\n`));
|
|
270
|
+
console.log(chalk_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
|
|
271
|
+
console.log(chalk_1.default.bold('🚀 You can now use GitHub features!\n'));
|
|
272
|
+
console.log(chalk_1.default.gray(' Try these commands in snap REPL:\n'));
|
|
273
|
+
console.log(chalk_1.default.cyan(' • "create a pull request"'));
|
|
274
|
+
console.log(chalk_1.default.cyan(' • "check CI status"'));
|
|
275
|
+
console.log(chalk_1.default.cyan(' • "list my open PRs"\n'));
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
console.log(chalk_1.default.red('\n❌ Connection failed\n'));
|
|
279
|
+
console.log(chalk_1.default.yellow('Possible reasons:'));
|
|
280
|
+
console.log(chalk_1.default.gray(' • Authorization was cancelled'));
|
|
281
|
+
console.log(chalk_1.default.gray(' • GitHub authorization not completed'));
|
|
282
|
+
console.log(chalk_1.default.gray(' • Network error\n'));
|
|
283
|
+
console.log(chalk_1.default.gray('Try running ') + chalk_1.default.cyan('github connect') + chalk_1.default.gray(' again\n'));
|
|
218
284
|
}
|
|
219
|
-
// Sync failed - user needs to sign up with GitHub
|
|
220
|
-
const error = await syncResponse.json();
|
|
221
|
-
console.log(chalk_1.default.red(`❌ ${error.message || error.error}\n`));
|
|
222
285
|
}
|
|
223
|
-
catch (
|
|
224
|
-
console.log(chalk_1.default.red(
|
|
286
|
+
catch (error) {
|
|
287
|
+
console.log(chalk_1.default.red(`\n❌ ${error.message}\n`));
|
|
288
|
+
console.log(chalk_1.default.gray('Try running ') + chalk_1.default.cyan('github connect') + chalk_1.default.gray(' again\n'));
|
|
225
289
|
}
|
|
226
|
-
// Show signup instructions
|
|
227
|
-
console.log(chalk_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
|
|
228
|
-
console.log(chalk_1.default.white('To use GitHub features, sign up with GitHub on our website.\n'));
|
|
229
|
-
console.log(chalk_1.default.bold.cyan('📝 Quick Setup:\n'));
|
|
230
|
-
console.log(chalk_1.default.gray(' 1. Visit: ') + chalk_1.default.cyan.underline('https://snapcommit.dev'));
|
|
231
|
-
console.log(chalk_1.default.gray(' 2. Click "Get Started"'));
|
|
232
|
-
console.log(chalk_1.default.gray(' 3. Sign up with GitHub'));
|
|
233
|
-
console.log(chalk_1.default.gray(' 4. Come back here and run ') + chalk_1.default.cyan('github connect') + chalk_1.default.gray(' again\n'));
|
|
234
|
-
console.log(chalk_1.default.bold('💡 Why sign up on the website?\n'));
|
|
235
|
-
console.log(chalk_1.default.gray(' • Your GitHub account is automatically connected'));
|
|
236
|
-
console.log(chalk_1.default.gray(' • Secure OAuth flow through Supabase'));
|
|
237
|
-
console.log(chalk_1.default.gray(' • Works seamlessly with the CLI\n'));
|
|
238
290
|
}
|
|
239
291
|
/**
|
|
240
292
|
* GitHub status command
|