scai 0.1.78 → 0.1.80
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/ReviewCmd.js +1 -1
- package/dist/config.js +0 -3
- package/dist/github/auth.js +10 -2
- package/dist/github/github.js +2 -25
- package/dist/github/githubAuthCheck.js +1 -1
- package/dist/github/repo.js +39 -6
- package/dist/github/token.js +2 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
|
@@ -363,9 +363,9 @@ export async function promptChunkReviewMenu() {
|
|
|
363
363
|
// Main command to review PR
|
|
364
364
|
export async function reviewPullRequestCmd(branch = 'main', showAll = false) {
|
|
365
365
|
try {
|
|
366
|
+
const { owner, repo } = await getRepoDetails();
|
|
366
367
|
const token = await ensureGitHubAuth();
|
|
367
368
|
const username = await getGitHubUsername(token);
|
|
368
|
-
const { owner, repo } = getRepoDetails();
|
|
369
369
|
const prsWithReviewRequested = await getPullRequestsForReview(token, owner, repo, username, branch, !showAll);
|
|
370
370
|
if (prsWithReviewRequested.length === 0)
|
|
371
371
|
return;
|
package/dist/config.js
CHANGED
|
@@ -97,15 +97,12 @@ export const Config = {
|
|
|
97
97
|
await this.setRepoIndexDir(scaiRepoRoot, absPath); // Set the indexDir for the repo
|
|
98
98
|
// Ensure base folders exist
|
|
99
99
|
fs.mkdirSync(scaiRepoRoot, { recursive: true });
|
|
100
|
-
fs.mkdirSync(path.join(scaiRepoRoot, 'summaries'), { recursive: true });
|
|
101
|
-
fs.mkdirSync(path.join(scaiRepoRoot, 'metadata'), { recursive: true });
|
|
102
100
|
// Init DB if not exists
|
|
103
101
|
const dbPath = path.join(scaiRepoRoot, 'db.sqlite');
|
|
104
102
|
if (!fs.existsSync(dbPath)) {
|
|
105
103
|
console.log(`📦 Database not found. ${chalk.green('Initializing DB')} at ${normalizePath(dbPath)}`);
|
|
106
104
|
getDbForRepo(); // Now DB creation works after config update
|
|
107
105
|
}
|
|
108
|
-
console.log(`✅ Index directory set to: ${normalizePath(absPath)}`);
|
|
109
106
|
},
|
|
110
107
|
/**
|
|
111
108
|
* Set both the scaiRepoRoot for the config and the indexDir (the actual repo root path)
|
package/dist/github/auth.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
1
2
|
import { Config } from '../config.js';
|
|
2
3
|
import { promptForToken } from './token.js';
|
|
3
4
|
export async function ensureGitHubAuth() {
|
|
4
5
|
// First check if the token exists in the config
|
|
5
6
|
let token = Config.getGitHubToken();
|
|
6
7
|
if (token) {
|
|
8
|
+
console.log("🔐 GitHub token found in config.");
|
|
7
9
|
return token; // Token already exists in config, return it
|
|
8
10
|
}
|
|
9
11
|
// Token doesn't exist in config, prompt the user for it
|
|
10
|
-
console.log("🔐 GitHub token not found.");
|
|
12
|
+
console.log(chalk.red("🔐 GitHub token not found."));
|
|
11
13
|
token = await promptForToken();
|
|
14
|
+
// Ensure the token is not empty and has the required format (you can extend this check as needed)
|
|
15
|
+
while (!token || token.trim().length === 0) {
|
|
16
|
+
console.log("❌ Invalid token entered. Please enter a valid GitHub token.");
|
|
17
|
+
token = await promptForToken();
|
|
18
|
+
}
|
|
12
19
|
// Save the token in the config
|
|
13
20
|
Config.setGitHubToken(token.trim());
|
|
14
|
-
|
|
21
|
+
console.log(chalk.green("✅ GitHub token successfully saved."));
|
|
22
|
+
return token.trim(); // Return the trimmed token
|
|
15
23
|
}
|
package/dist/github/github.js
CHANGED
|
@@ -50,7 +50,7 @@ export async function fetchPullRequestDiff(pr, token) {
|
|
|
50
50
|
}
|
|
51
51
|
export async function submitReview(prNumber, body, event, comments) {
|
|
52
52
|
const token = await ensureGitHubAuth();
|
|
53
|
-
const { owner, repo } = getRepoDetails();
|
|
53
|
+
const { owner, repo } = await getRepoDetails();
|
|
54
54
|
const url = `https://api.github.com/repos/${owner}/${repo}/pulls/${prNumber}/reviews`;
|
|
55
55
|
const res = await fetch(url, {
|
|
56
56
|
method: 'POST',
|
|
@@ -102,7 +102,7 @@ export async function submitReview(prNumber, body, event, comments) {
|
|
|
102
102
|
export async function postInlineComment(prNumber, commitId, path, body, line, side = 'RIGHT', reviewId = null // Associate with a review if available
|
|
103
103
|
) {
|
|
104
104
|
const token = await ensureGitHubAuth();
|
|
105
|
-
const { owner, repo } = getRepoDetails();
|
|
105
|
+
const { owner, repo } = await getRepoDetails();
|
|
106
106
|
const url = `https://api.github.com/repos/${owner}/${repo}/pulls/${prNumber}/comments`;
|
|
107
107
|
const res = await fetch(url, {
|
|
108
108
|
method: 'POST',
|
|
@@ -125,26 +125,3 @@ export async function postInlineComment(prNumber, commitId, path, body, line, si
|
|
|
125
125
|
}
|
|
126
126
|
console.log(`💬 Posted inline comment on ${path}:${line}`);
|
|
127
127
|
}
|
|
128
|
-
export async function createReviewForPR(prNumber, body, event = 'COMMENT') {
|
|
129
|
-
const token = await ensureGitHubAuth();
|
|
130
|
-
const { owner, repo } = getRepoDetails();
|
|
131
|
-
const url = `https://api.github.com/repos/${owner}/${repo}/pulls/${prNumber}/reviews`;
|
|
132
|
-
const res = await fetch(url, {
|
|
133
|
-
method: 'POST',
|
|
134
|
-
headers: {
|
|
135
|
-
Authorization: `token ${token}`,
|
|
136
|
-
Accept: 'application/vnd.github.v3+json',
|
|
137
|
-
},
|
|
138
|
-
body: JSON.stringify({
|
|
139
|
-
body,
|
|
140
|
-
event,
|
|
141
|
-
}),
|
|
142
|
-
});
|
|
143
|
-
if (!res.ok) {
|
|
144
|
-
const errorText = await res.text();
|
|
145
|
-
throw new Error(`Failed to create review: ${res.status} ${res.statusText} - ${errorText}`);
|
|
146
|
-
}
|
|
147
|
-
const review = await res.json();
|
|
148
|
-
console.log(`✅ Created review for PR #${prNumber}`);
|
|
149
|
-
return review.id; // Return the review ID to be used for inline comments
|
|
150
|
-
}
|
|
@@ -2,7 +2,7 @@ import { ensureGitHubAuth } from './auth.js';
|
|
|
2
2
|
import { getRepoDetails } from './repo.js';
|
|
3
3
|
export async function validateGitHubTokenAgainstRepo() {
|
|
4
4
|
const token = await ensureGitHubAuth();
|
|
5
|
-
const { owner, repo } = getRepoDetails();
|
|
5
|
+
const { owner, repo } = await getRepoDetails();
|
|
6
6
|
const response = await fetch(`https://api.github.com/repos/${owner}/${repo}`, {
|
|
7
7
|
headers: {
|
|
8
8
|
Authorization: `Bearer ${token}`,
|
package/dist/github/repo.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { execSync } from 'child_process';
|
|
3
3
|
import { Config } from '../config.js';
|
|
4
|
+
import { ensureGitHubAuth } from './auth.js';
|
|
5
|
+
import chalk from 'chalk';
|
|
4
6
|
/**
|
|
5
7
|
* Executes a Git command inside the specified working directory.
|
|
6
8
|
*/
|
|
@@ -41,17 +43,48 @@ function getRepoOwnerAndNameFromIndexDir(indexDir) {
|
|
|
41
43
|
* Get the GitHub repo details, always from the configured indexDir.
|
|
42
44
|
* Prefers Git config, falls back to parsing the path.
|
|
43
45
|
*/
|
|
44
|
-
export function getRepoDetails() {
|
|
45
|
-
|
|
46
|
+
export async function getRepoDetails() {
|
|
47
|
+
let indexDir = path.normalize(Config.getIndexDir()); // Fetch the current indexDir
|
|
48
|
+
const currentDir = path.normalize(process.cwd()); // Get the current working directory
|
|
46
49
|
if (!indexDir) {
|
|
47
|
-
|
|
50
|
+
console.log("❌ indexDir is not configured. Setting up a new index for the current directory...");
|
|
51
|
+
// Automatically set the index directory for the current directory
|
|
52
|
+
await setIndexDirForCurrentDir(currentDir);
|
|
53
|
+
// Now that the indexDir is set, fetch it again
|
|
54
|
+
indexDir = Config.getIndexDir();
|
|
55
|
+
}
|
|
56
|
+
console.log(chalk.yellow(`📦 Resolving GitHub repo info from indexDir: ${indexDir}`));
|
|
57
|
+
// Check if the current directory is the same as the index directory
|
|
58
|
+
if (path.resolve(currentDir) !== path.resolve(indexDir)) {
|
|
59
|
+
console.log(`🚧 Current directory is not the index directory. Setting up new index...`);
|
|
60
|
+
// Use the existing functionality to set up a new index directory
|
|
61
|
+
await setIndexDirForCurrentDir(currentDir);
|
|
62
|
+
// Now update indexDir to the newly set one
|
|
63
|
+
indexDir = Config.getIndexDir(); // Re-fetch the updated indexDir
|
|
48
64
|
}
|
|
49
|
-
|
|
65
|
+
// Ensure the repository authentication is available
|
|
66
|
+
await ensureAuthCredentials();
|
|
67
|
+
// Proceed with the normal flow to fetch the repo details
|
|
50
68
|
try {
|
|
51
|
-
return getRepoOwnerAndNameFromGit(indexDir);
|
|
69
|
+
return getRepoOwnerAndNameFromGit(indexDir); // Try fetching from Git config
|
|
52
70
|
}
|
|
53
71
|
catch {
|
|
54
72
|
console.log("🔁 Falling back to extracting from indexDir path...");
|
|
55
|
-
return getRepoOwnerAndNameFromIndexDir(indexDir);
|
|
73
|
+
return getRepoOwnerAndNameFromIndexDir(indexDir); // Fallback if Git config fails
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async function setIndexDirForCurrentDir(currentDir) {
|
|
77
|
+
console.log(`🔧 Setting up index directory for the current directory: ${currentDir}`);
|
|
78
|
+
// Use the existing scai index set functionality to set the index directory
|
|
79
|
+
await Config.setIndexDir(currentDir);
|
|
80
|
+
// After setting the index, verify the directory is set correctly
|
|
81
|
+
const indexDir = Config.getIndexDir();
|
|
82
|
+
console.log(`✅ Index directory set to: ${indexDir}`);
|
|
83
|
+
}
|
|
84
|
+
async function ensureAuthCredentials() {
|
|
85
|
+
const token = await ensureGitHubAuth();
|
|
86
|
+
if (!token) {
|
|
87
|
+
throw new Error('❌ GitHub authentication token not found. Please authenticate first.');
|
|
56
88
|
}
|
|
89
|
+
console.log('✅ GitHub authentication credentials are valid.');
|
|
57
90
|
}
|
package/dist/github/token.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Utility function to prompt for GitHub token
|
|
2
|
+
import chalk from 'chalk';
|
|
2
3
|
import readline from 'readline';
|
|
3
4
|
export function promptForToken() {
|
|
4
5
|
return new Promise((resolve) => {
|
|
@@ -6,7 +7,7 @@ export function promptForToken() {
|
|
|
6
7
|
input: process.stdin,
|
|
7
8
|
output: process.stdout,
|
|
8
9
|
});
|
|
9
|
-
rl.question(
|
|
10
|
+
rl.question(`\nPaste your GitHub Personal Access Token:\n${chalk.yellow('(press Control + C to exit)')}\n`, (token) => {
|
|
10
11
|
rl.close();
|
|
11
12
|
resolve(token);
|
|
12
13
|
});
|
package/dist/index.js
CHANGED
|
@@ -153,9 +153,9 @@ index
|
|
|
153
153
|
.description('Index supported files in the configured index directory')
|
|
154
154
|
.action(runIndexCommand);
|
|
155
155
|
index
|
|
156
|
-
.command('set
|
|
156
|
+
.command('set [dir]')
|
|
157
157
|
.description('Set and activate index directory')
|
|
158
|
-
.action((dir) => {
|
|
158
|
+
.action((dir = process.cwd()) => {
|
|
159
159
|
Config.setIndexDir(dir);
|
|
160
160
|
Config.show();
|
|
161
161
|
});
|