Skip to content

Commit b1e1a33

Browse files
committed
Git clone feature addition and fix for commit log quote bug
1 parent d5bfe2e commit b1e1a33

File tree

6 files changed

+84
-32
lines changed

6 files changed

+84
-32
lines changed

API/addRepoApi.js

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,69 @@ function getEnvData() {
1818
};
1919
}
2020

21-
async function addRepoHandler(repoName, repoPath, initCheck) {
21+
async function addRepoHandler(
22+
repoName,
23+
repoPath,
24+
initCheck,
25+
cloneCheck,
26+
cloneUrl
27+
) {
2228
const timeStamp = new Date().toUTCString();
2329
const id = new Date().getTime();
2430

25-
var repoObject = {
26-
id,
27-
timeStamp,
28-
repoName,
29-
repoPath,
30-
};
31-
3231
function errorResponse() {
3332
return {
34-
addRepo: {
35-
message: "REPO_WRITE_FAILED",
36-
},
33+
message: "REPO_WRITE_FAILED",
3734
};
3835
}
3936

4037
function successResponse() {
4138
return {
42-
addRepo: {
43-
message: "REPO_DATA_UPDATED",
44-
repoId: id,
45-
},
39+
message: "REPO_DATA_UPDATED",
40+
repoId: id,
4641
};
4742
}
4843

44+
if (cloneCheck) {
45+
const cloneStatus = await execPromisified(`git clone "${cloneUrl}"`, {
46+
cwd: repoPath,
47+
windowsHide: true,
48+
})
49+
.then(({ stdout, stderr }) => {
50+
console.log(stdout);
51+
console.log(stderr);
52+
if (stdout || stderr) {
53+
console.log(stdout);
54+
return true;
55+
} else {
56+
return false;
57+
}
58+
})
59+
.catch((err) => {
60+
console.log(err);
61+
return false;
62+
});
63+
64+
console.log("CLONE STAT : ", cloneStatus);
65+
66+
if (cloneStatus) {
67+
if (repoPath.includes("\\")) {
68+
repoPath = repoPath + "\\" + repoName;
69+
} else {
70+
repoPath = repoPath + "/" + repoName;
71+
}
72+
} else {
73+
return errorResponse();
74+
}
75+
}
76+
77+
const repoObject = {
78+
id,
79+
timeStamp,
80+
repoName,
81+
repoPath,
82+
};
83+
4984
const dataStoreFile = getEnvData().DATABASE_FILE;
5085

5186
let fileData = fs.readFileSync(dataStoreFile);

git/gitCommitChangesAPI.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ const fetchRepopath = require("../global/fetchGitRepoPath");
66

77
const gitCommitChangesApi = async (repoId, commitMessage) => {
88
commitMessage = commitMessage.split("||").join("\n");
9+
commitMessage = commitMessage.replace(/"/gi, '\\"');
910

1011
return await execPromisified(`git commit -m "${commitMessage}"`, {
1112
cwd: fetchRepopath.getRepoPath(repoId),
1213
windowsHide: true,
1314
})
1415
.then(({ stdout, stderr }) => {
16+
console.log(stdout, stderr);
1517
if (!stderr) {
1618
return "COMMIT_DONE";
1719
} else {
1820
return "COMMIT_FAILED";
1921
}
2022
})
2123
.catch((err) => {
24+
console.log(err);
2225
return "COMMIT_FAILED";
2326
});
2427
};

global/globalAPIHandler.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ app.use(cors());
66
const {
77
HEALTH_CHECK,
88
FETCH_REPO,
9-
ADD_REPO,
109
REPO_DETAILS,
1110
REPO_TRACKED_DIFF,
1211
REPO_FILE_DIFF,
@@ -76,8 +75,6 @@ app.use(
7675
return healthCheckFunction();
7776
case FETCH_REPO:
7877
return fetchRepoFunction();
79-
case ADD_REPO:
80-
return addRepoFunction(parsedPayload);
8178
case REPO_DETAILS:
8279
return repoDetailsFunction(parsedPayload);
8380
case REPO_TRACKED_DIFF:
@@ -102,6 +99,16 @@ app.use(
10299
return { message: "Query Termination" };
103100
}
104101
},
102+
addRepo: async (args) => {
103+
const { repoName, repoPath, initSwitch, cloneSwitch, cloneUrl } = args;
104+
return await addRepoFunction(
105+
repoName,
106+
repoPath,
107+
initSwitch,
108+
cloneSwitch,
109+
cloneUrl
110+
);
111+
},
105112
setBranch: async (args) => {
106113
const { repoId, branch } = args;
107114
console.log(args);

global/globalFunctionStore.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,21 @@ module.exports.fetchRepoFunction = fetchRepoFunction = async (payload) => {
6060
};
6161
};
6262

63-
module.exports.addRepoFunction = addRepoFunction = async (parsedPayload) => {
64-
const { repoName, repoPath, initCheck } = JSON.parse(parsedPayload);
65-
63+
module.exports.addRepoFunction = addRepoFunction = async (
64+
repoName,
65+
repoPath,
66+
initCheck,
67+
cloneCheck,
68+
cloneUrl
69+
) => {
6670
if (repoName && repoPath) {
67-
console.log(parsedPayload);
68-
69-
return await addRepoHandler(repoName, repoPath, initCheck);
71+
return await addRepoHandler(
72+
repoName,
73+
repoPath,
74+
initCheck,
75+
cloneCheck,
76+
cloneUrl
77+
);
7078
} else {
7179
return {
7280
message: "REPO_WRITE_FAILURE",

global/globalRouteStore.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module.exports.HEALTH_CHECK = "HEALTH_CHECK";
22
module.exports.FETCH_REPO = "FETCH_REPO";
3-
module.exports.ADD_REPO = "ADD_REPO";
43
module.exports.COMMIT_LOGS = "COMMIT_LOGS";
54
module.exports.COMMIT_FILES = "COMMIT_FILES";
65
module.exports.REPO_DETAILS = "REPO_DETAILS";

global/gqlGlobalAPISchema.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const globalAPISchema = new buildSchema(
99
type GitConvexResults{
1010
healthCheck: healthCheckResults!
1111
fetchRepo: fetchRepoResults!
12-
addRepo: addRepoResults!
1312
gitRepoStatus: gitRepoStatusResults!
1413
gitChanges: gitChangeResults!
1514
gitFileLineChanges: gitFileLineChangeResults!
@@ -33,12 +32,7 @@ const globalAPISchema = new buildSchema(
3332
repoPath: [String]
3433
repoName: [String]
3534
}
36-
37-
type addRepoResults{
38-
message: String
39-
repoId: String
40-
}
41-
35+
4236
type gitCommits{
4337
hash: String,
4438
author: String,
@@ -101,6 +95,7 @@ const globalAPISchema = new buildSchema(
10195
}
10296
10397
type GitConvexMutation{
98+
addRepo(repoName: String!, repoPath: String!, initSwitch: Boolean!, cloneSwitch: Boolean!, cloneUrl: String): addRepoStatus!
10499
setBranch(repoId: String!, branch: String!): String!
105100
stageItem(repoId: String!, item: String!): String!
106101
stageAllItems(repoId: String): String!
@@ -120,6 +115,11 @@ const globalAPISchema = new buildSchema(
120115
deleteBranch(repoId: String!, branchName: String!, forceFlag: Boolean!): deleteBranchStatus!
121116
}
122117
118+
type addRepoStatus{
119+
message: String!,
120+
repoId: String
121+
}
122+
123123
type gitFetchStatus{
124124
status: String!
125125
fetchedItems: [String]

0 commit comments

Comments
 (0)