greptile 1.0.4 → 1.0.5
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/bin/index.js +52 -13
- package/package.json +1 -1
- package/bin/config.json +0 -5
- package/bin/payload.json +0 -24
- package/bin/session.json +0 -4
package/bin/index.js
CHANGED
|
@@ -26,7 +26,7 @@ let access_token = null;
|
|
|
26
26
|
const { promisify } = require('util');
|
|
27
27
|
const { debug } = require("console");
|
|
28
28
|
const setTimeoutPromise = promisify(setTimeout);
|
|
29
|
-
const debugMode =
|
|
29
|
+
const debugMode = true;
|
|
30
30
|
const payloadFilePath = path.resolve(__dirname, 'payload.json');
|
|
31
31
|
var shell = require('shelljs');
|
|
32
32
|
|
|
@@ -125,13 +125,46 @@ const options = yargs
|
|
|
125
125
|
.command("remove <repository>", "Remove a repository from the session")
|
|
126
126
|
.command("start", "Start Greptile application")
|
|
127
127
|
.command("auth", "Redirect to GitHub authentication")
|
|
128
|
-
.command("addPath","Adds greptie to your Path")
|
|
128
|
+
.command("addPath", "Adds greptie to your Path")
|
|
129
129
|
.demandCommand(1, "Please specify a command.")
|
|
130
130
|
.help(true)
|
|
131
131
|
.argv;
|
|
132
132
|
|
|
133
133
|
// Command execution based on user input
|
|
134
134
|
async function main() {
|
|
135
|
+
if (!fs.existsSync(configPath)) {
|
|
136
|
+
const defaultConfig = {
|
|
137
|
+
github: {
|
|
138
|
+
access_token: null,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2), 'utf-8');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Check if session.json exists, create with default content if not
|
|
145
|
+
if (!fs.existsSync(sessionPath)) {
|
|
146
|
+
const defaultSession = {
|
|
147
|
+
repositories: [],
|
|
148
|
+
};
|
|
149
|
+
fs.writeFileSync(sessionPath, JSON.stringify(defaultSession, null, 2), 'utf-8');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Check if payload.json exists, create with default content if not
|
|
153
|
+
if (!fs.existsSync(payloadFilePath)) {
|
|
154
|
+
const defaultPayload = {
|
|
155
|
+
messages: [],
|
|
156
|
+
repositories: [],
|
|
157
|
+
sessionId: '',
|
|
158
|
+
user: {
|
|
159
|
+
email: '',
|
|
160
|
+
token: {
|
|
161
|
+
github: '',
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
fs.writeFileSync(payloadFilePath, JSON.stringify(defaultPayload, null, 2), 'utf-8');
|
|
166
|
+
}
|
|
167
|
+
|
|
135
168
|
const command = options._[0];
|
|
136
169
|
switch (command) {
|
|
137
170
|
|
|
@@ -225,7 +258,7 @@ async function executeAddCommand(repositoryLink) {
|
|
|
225
258
|
};
|
|
226
259
|
}
|
|
227
260
|
// Add the new repository to the session
|
|
228
|
-
if (!isUrlFormat(repositoryLink)){
|
|
261
|
+
if (!isUrlFormat(repositoryLink)) {
|
|
229
262
|
repositoryLink = `https://github.com/${repositoryLink}`;
|
|
230
263
|
}
|
|
231
264
|
const parsedRepo = parseIdentifier(repositoryLink)
|
|
@@ -263,8 +296,8 @@ async function executeAddCommand(repositoryLink) {
|
|
|
263
296
|
if (repoInfo.failed[0].message && repoInfo.failed[0].message == "Repository not processed by Onboard.") {
|
|
264
297
|
writeRepoToFile(repositoryLink);
|
|
265
298
|
const processRepo = await getRepo(repository);
|
|
266
|
-
if (debugMode){
|
|
267
|
-
|
|
299
|
+
if (debugMode) {
|
|
300
|
+
console.log(processRepo)
|
|
268
301
|
}
|
|
269
302
|
}
|
|
270
303
|
else {
|
|
@@ -326,6 +359,11 @@ function writeRepoToFile(repositoryLink) {
|
|
|
326
359
|
const sessionFile = JSON.stringify(sessionData, null, 2);
|
|
327
360
|
fs.writeFileSync(sessionPath, sessionFile, 'utf-8');
|
|
328
361
|
console.log(`Repository '${repositoryLink}' added to the session.`);
|
|
362
|
+
|
|
363
|
+
// Update payload.json with the new session data
|
|
364
|
+
const payload = createPayload2("", createSessionId());
|
|
365
|
+
writePayloadToFile(payload);
|
|
366
|
+
|
|
329
367
|
} catch (error) {
|
|
330
368
|
console.error('Error writing session data to file:', error);
|
|
331
369
|
}
|
|
@@ -333,6 +371,7 @@ function writeRepoToFile(repositoryLink) {
|
|
|
333
371
|
console.log(`Repository '${repositoryLink}' already exists in the session.`);
|
|
334
372
|
}
|
|
335
373
|
}
|
|
374
|
+
|
|
336
375
|
function executeListCommand() {
|
|
337
376
|
if (!isAuthenticated()) {
|
|
338
377
|
console.error("Error: Please authenticate with GitHub first. Use 'greptile auth' to authenticate.");
|
|
@@ -391,7 +430,7 @@ function executeRemoveCommand(repository) {
|
|
|
391
430
|
};
|
|
392
431
|
}
|
|
393
432
|
|
|
394
|
-
if (!isUrlFormat(repository)){
|
|
433
|
+
if (!isUrlFormat(repository)) {
|
|
395
434
|
repository = `https://github.com/${repository}`;
|
|
396
435
|
}
|
|
397
436
|
|
|
@@ -784,8 +823,8 @@ function hasNoRepositories() {
|
|
|
784
823
|
try {
|
|
785
824
|
const sessionFile = fs.readFileSync(sessionPath, 'utf-8');
|
|
786
825
|
const sessionData = JSON.parse(sessionFile);
|
|
787
|
-
if (debugMode){
|
|
788
|
-
|
|
826
|
+
if (debugMode) {
|
|
827
|
+
console.log(sessionData.repositories.length)
|
|
789
828
|
}
|
|
790
829
|
return sessionData.repositories.length === 0;
|
|
791
830
|
} catch (error) {
|
|
@@ -913,7 +952,7 @@ function serializeRepoKey(repoKey) {
|
|
|
913
952
|
}
|
|
914
953
|
|
|
915
954
|
function addToPath5() {
|
|
916
|
-
dirToAdd = __dirname.replace("/bin","")
|
|
955
|
+
dirToAdd = __dirname.replace("/bin", "")
|
|
917
956
|
exec('export PATH="' + dirToAdd + ':$PATH"',
|
|
918
957
|
(error, stdout, stderr) => {
|
|
919
958
|
// console.log(`stdout: ${stdout}`);
|
|
@@ -921,7 +960,7 @@ function addToPath5() {
|
|
|
921
960
|
if (error !== null) {
|
|
922
961
|
// console.log(`exec error: ${error}`);
|
|
923
962
|
}
|
|
924
|
-
else{
|
|
963
|
+
else {
|
|
925
964
|
// console.log("Sucessfuly added to path")
|
|
926
965
|
}
|
|
927
966
|
});
|
|
@@ -929,7 +968,7 @@ function addToPath5() {
|
|
|
929
968
|
|
|
930
969
|
function addToPath3() {
|
|
931
970
|
// Get the current directory
|
|
932
|
-
const currentDirectory = __dirname.replace("/bin","");
|
|
971
|
+
const currentDirectory = __dirname.replace("/bin", "");
|
|
933
972
|
|
|
934
973
|
// Get the current PATH variable value or use an empty string if it doesn't exist
|
|
935
974
|
const currentPath = process.env.PATH || '';
|
|
@@ -952,7 +991,7 @@ function addToPath3() {
|
|
|
952
991
|
|
|
953
992
|
function addToPath() {
|
|
954
993
|
// Execute the Bash script
|
|
955
|
-
bashFile = path.join(currentDirectory.replace("/bin","") + "/addToPath.sh")
|
|
994
|
+
bashFile = path.join(currentDirectory.replace("/bin", "") + "/addToPath.sh")
|
|
956
995
|
exec(bashFile, (error, stdout, stderr) => {
|
|
957
996
|
if (error) {
|
|
958
997
|
console.error(`Error: ${error.message}`);
|
|
@@ -968,7 +1007,7 @@ function addToPath() {
|
|
|
968
1007
|
|
|
969
1008
|
function addToPath5() {
|
|
970
1009
|
// Get the current directory
|
|
971
|
-
const currentDirectory = __dirname.replace("/bin","");
|
|
1010
|
+
const currentDirectory = __dirname.replace("/bin", "");
|
|
972
1011
|
|
|
973
1012
|
// Get the current PATH variable value or use an empty string if it doesn't exist
|
|
974
1013
|
const currentPath = process.env.PATH || '';
|
package/package.json
CHANGED
package/bin/config.json
DELETED
package/bin/payload.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"messages": [
|
|
3
|
-
{
|
|
4
|
-
"id": "1",
|
|
5
|
-
"role": "user",
|
|
6
|
-
"content": "how does auth work"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
"id": "2",
|
|
10
|
-
"role": "user",
|
|
11
|
-
"content": "The authentication process in the `tabnam-inc/onboardme` repository is managed using NextAuth, a popular authentication solution for Next.js applications. Here's a breakdown of how authentication is implemented and works within this codebase:\n\n### Configuration (`/src/options.ts`)\n- **Providers**: Authentication providers are configured in the `authOptions` object. The codebase includes configurations for GitHub and WorkOS as authentication providers. AzureADProvider is commented out but also included in the configuration.\n- **Session & JWT**: The session management strategy is set to JWT (JSON Web Tokens), indicating that sessions will be handled through JWT tokens.\n- **Callbacks**: The `session` callback is defined to enrich the session object with additional properties like `tokens`, `membership`, `business`, `checkoutSession`, `freeTrialDaysRemaining`, and `authProvider`.\n\n### Authentication API Route (`/src/app/api/auth/[...nextauth]/route.ts`)\n- **Handler**: The main handler for authentication uses the NextAuth function, passing the `authOptions` along with additional configurations and callbacks.\n- **Callbacks**: The JWT callback is particularly important as it handles the logic for registering user logins, updating user information, and managing referral programs. It interacts with AWS DynamoDB to check if a user exists, updates their membership status, and handles referral bonuses.\n- **Referral Program**: The code includes logic for handling referrals, such as giving a free month to the referrer if certain conditions are met.\n- **Token Management**: External tokens (e.g., from Azure) are managed and stored securely. The code includes logic for saving these tokens to the database and redacting sensitive information before storage.\n\n### Client-Side Usage\n- **Menu Component (`/src/components/Menu.tsx`)**: This component shows how the authentication state is used to display user-specific information and options. It includes logic for signing in, signing out, and managing the user's session.\n- **Usage of Hooks**: The codebase uses Next.js hooks like `useSession` to manage and access the authentication state throughout the application.\n\n### Summary\nAuthentication in this codebase is centered around NextAuth, leveraging its flexibility to configure multiple providers and manage sessions via JWT. The custom logic in the API route handler extends the basic functionality to include features like a referral program and secure token management. Client-side components interact with the authentication state to provide a personalized user experience."
|
|
12
|
-
}
|
|
13
|
-
],
|
|
14
|
-
"repositories": [
|
|
15
|
-
{
|
|
16
|
-
"remote": "github",
|
|
17
|
-
"repository": "tabnam-inc/onboardme",
|
|
18
|
-
"branch": "main",
|
|
19
|
-
"name": "tabnam-inc/onboardme",
|
|
20
|
-
"external": false
|
|
21
|
-
}
|
|
22
|
-
],
|
|
23
|
-
"sessionId": "yqjjn6zq4akv41a8dlv6j"
|
|
24
|
-
}
|
package/bin/session.json
DELETED