@snapcommit/cli 3.7.0 → 3.8.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/dist/commands/github-connect.js +70 -7
- package/dist/repl.js +3 -3
- package/package.json +1 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* No OAuth complexity, instant setup!
|
|
3
|
+
* GitHub authentication - Auto-fetches OAuth token from SnapCommit account
|
|
4
|
+
* Falls back to manual PAT if OAuth token not available
|
|
6
5
|
*/
|
|
7
6
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
7
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -21,6 +20,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
21
20
|
const os_1 = __importDefault(require("os"));
|
|
22
21
|
const readline_1 = __importDefault(require("readline"));
|
|
23
22
|
const rest_1 = require("@octokit/rest");
|
|
23
|
+
const auth_1 = require("../lib/auth");
|
|
24
24
|
const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.snapcommit');
|
|
25
25
|
const GITHUB_TOKEN_FILE = path_1.default.join(CONFIG_DIR, 'github.json');
|
|
26
26
|
/**
|
|
@@ -44,6 +44,50 @@ function askQuestion(query) {
|
|
|
44
44
|
resolve(ans);
|
|
45
45
|
}));
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Try to auto-fetch GitHub OAuth token from SnapCommit account
|
|
49
|
+
*/
|
|
50
|
+
async function autoFetchGitHubToken() {
|
|
51
|
+
try {
|
|
52
|
+
const authConfig = (0, auth_1.getAuthConfig)();
|
|
53
|
+
if (!authConfig || !authConfig.token) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
// Call SnapCommit API to get GitHub OAuth token
|
|
57
|
+
const response = await fetch('https://snapcommit.dev/api/github/token', {
|
|
58
|
+
method: 'GET',
|
|
59
|
+
headers: {
|
|
60
|
+
'Authorization': `Bearer ${authConfig.token}`,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
// OAuth token not available, user needs manual setup
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const data = await response.json();
|
|
68
|
+
if (!data || typeof data !== 'object' || !('token' in data) || !('username' in data)) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const githubData = data;
|
|
72
|
+
if (!githubData.token || !githubData.username) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
// Verify token works by fetching user info
|
|
76
|
+
const octokit = new rest_1.Octokit({ auth: githubData.token });
|
|
77
|
+
const { data: user } = await octokit.users.getAuthenticated();
|
|
78
|
+
const config = {
|
|
79
|
+
token: githubData.token,
|
|
80
|
+
username: user.login,
|
|
81
|
+
userId: user.id,
|
|
82
|
+
connectedAt: new Date().toISOString(),
|
|
83
|
+
};
|
|
84
|
+
return config;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
// Silent fail - fall back to manual setup
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
47
91
|
/**
|
|
48
92
|
* Verify GitHub token and get user info
|
|
49
93
|
*/
|
|
@@ -117,16 +161,35 @@ function clearGitHubToken() {
|
|
|
117
161
|
*/
|
|
118
162
|
async function githubConnectCommand(tokenArg) {
|
|
119
163
|
console.log(chalk_1.default.bold.cyan('\n╔════════════════════════════════════════╗'));
|
|
120
|
-
console.log(chalk_1.default.bold.cyan('║ 🐙 Connect GitHub CLI
|
|
164
|
+
console.log(chalk_1.default.bold.cyan('║ 🐙 Connect GitHub CLI ║'));
|
|
121
165
|
console.log(chalk_1.default.bold.cyan('╚════════════════════════════════════════╝\n'));
|
|
122
|
-
console.log(chalk_1.default.
|
|
123
|
-
|
|
166
|
+
console.log(chalk_1.default.gray('Checking for GitHub OAuth token from your SnapCommit account...\n'));
|
|
167
|
+
// Try to auto-fetch GitHub OAuth token first
|
|
168
|
+
const autoConfig = await autoFetchGitHubToken();
|
|
169
|
+
if (autoConfig) {
|
|
170
|
+
// Success! Auto-connected via OAuth
|
|
171
|
+
saveGitHubToken(autoConfig);
|
|
172
|
+
console.log(chalk_1.default.green.bold('✅ GITHUB AUTO-CONNECTED! 🎉\n'));
|
|
173
|
+
console.log(chalk_1.default.white(` Connected as: ${chalk_1.default.bold('@' + autoConfig.username)}`));
|
|
174
|
+
console.log(chalk_1.default.gray(` Using OAuth token from snapcommit.dev\n`));
|
|
175
|
+
console.log(chalk_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
|
|
176
|
+
console.log(chalk_1.default.bold('🚀 You can now use GitHub features!\n'));
|
|
177
|
+
console.log(chalk_1.default.gray(' Try these commands in snap REPL:\n'));
|
|
178
|
+
console.log(chalk_1.default.cyan(' • "create a pull request"'));
|
|
179
|
+
console.log(chalk_1.default.cyan(' • "check CI status"'));
|
|
180
|
+
console.log(chalk_1.default.cyan(' • "list my open PRs"\n'));
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
// Auto-fetch failed, fall back to manual PAT setup
|
|
184
|
+
console.log(chalk_1.default.yellow('⚠️ Could not auto-connect GitHub (OAuth token not available)\n'));
|
|
185
|
+
console.log(chalk_1.default.gray('No problem! You can manually connect with a Personal Access Token:\n'));
|
|
186
|
+
console.log(chalk_1.default.white('This CLI token enables GitHub features in your terminal:\n'));
|
|
124
187
|
console.log(chalk_1.default.white(' • Create pull requests'));
|
|
125
188
|
console.log(chalk_1.default.white(' • Check CI/workflow status'));
|
|
126
189
|
console.log(chalk_1.default.white(' • Manage issues and PRs'));
|
|
127
190
|
console.log(chalk_1.default.white(' • All with natural language!\n'));
|
|
128
191
|
console.log(chalk_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
|
|
129
|
-
console.log(chalk_1.default.bold.white('
|
|
192
|
+
console.log(chalk_1.default.bold.white('Manual Setup (2 minutes):\n'));
|
|
130
193
|
console.log(chalk_1.default.gray(' 1. Go to: ') + chalk_1.default.cyan('https://github.com/settings/tokens'));
|
|
131
194
|
console.log(chalk_1.default.gray(' 2. Click "Generate new token (classic)"'));
|
|
132
195
|
console.log(chalk_1.default.gray(' 3. Name: ') + chalk_1.default.white('"SnapCommit CLI"'));
|
package/dist/repl.js
CHANGED
|
@@ -95,9 +95,9 @@ async function startREPL() {
|
|
|
95
95
|
console.log(chalk_1.default.yellow.bold('┌─────────────────────────────────────────┐'));
|
|
96
96
|
console.log(chalk_1.default.yellow.bold('│ 🐙 GITHUB FEATURES (OPTIONAL) │'));
|
|
97
97
|
console.log(chalk_1.default.yellow.bold('└─────────────────────────────────────────┘\n'));
|
|
98
|
-
console.log(chalk_1.default.
|
|
99
|
-
console.log(chalk_1.default.gray('
|
|
100
|
-
console.log(chalk_1.default.gray(' This creates a CLI token for
|
|
98
|
+
console.log(chalk_1.default.gray(' Want to use GitHub features? (create PRs, check CI, etc.)\n'));
|
|
99
|
+
console.log(chalk_1.default.gray(' Run: ') + chalk_1.default.cyan('snap github connect'));
|
|
100
|
+
console.log(chalk_1.default.gray(' This creates a CLI token for GitHub API access.\n'));
|
|
101
101
|
}
|
|
102
102
|
console.log(chalk_1.default.gray('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
|
|
103
103
|
console.log(chalk_1.default.bold.yellow('🎯 Try it now! Type what you want to do:\n'));
|