Skip to content

Commit 52f7166

Browse files
authored
Merge to master for v1.1.4 release
Pull request for merging v1.1.4 changes to master
2 parents 65b35db + 976e7d0 commit 52f7166

File tree

4,553 files changed

+14717
-72901
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,553 files changed

+14717
-72901
lines changed

API/addRepoApi.js

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ const path = require("path");
33
const util = require("util");
44
const execPromisified = util.promisify(exec);
55
const fs = require("fs");
6-
7-
function getEnvData() {
8-
const envFileData = fs.readFileSync(
9-
path.join(__dirname, "..", "env_config.json")
10-
);
11-
12-
const envContent = envFileData.toString();
13-
let envData = JSON.parse(envContent)[0];
14-
15-
return {
16-
DATABASE_FILE: envData.databaseFile,
17-
GITCONVEX_PORT: envData.port,
18-
};
19-
}
6+
const { getEnvData } = require("../utils/getEnvData");
7+
const { gitCommitLogToDb } = require("../utils/sqliteDbAccess");
8+
9+
/**
10+
* @param {String} repoName - Name of the repository
11+
* @param {String} repoPath - Path were the repo is residing or where it should be cloned / initialized
12+
* @param {boolean} initCheck - Switch to check if user has selected repo init option
13+
* @param {boolean} cloneCheck - Switch to check if user has selected repo cloning option
14+
* @param {String} cloneUrl - The If cloning switch is true, then this holds the URL of the remote repo
15+
* @returns {Object} - created a new entry in the data file and retusn the status
16+
*/
2017

2118
async function addRepoHandler(
2219
repoName,
@@ -35,44 +32,58 @@ async function addRepoHandler(
3532
}
3633

3734
function successResponse() {
35+
gitCommitLogToDb();
3836
return {
3937
message: "REPO_DATA_UPDATED",
4038
repoId: id,
4139
};
4240
}
4341

4442
if (cloneCheck) {
45-
const cloneStatus = await execPromisified(
46-
`git clone "${cloneUrl}" "./${repoName}"`,
47-
{
48-
cwd: repoPath,
49-
windowsHide: true,
43+
try {
44+
if (cloneUrl.match(/[^a-zA-Z0-9-_.~@#$%:/]/gi)) {
45+
throw new Error("Invalid clone URL string!");
46+
}
47+
48+
if (repoName.match(/[^a-zA-Z0-9-_.\\s]/gi)) {
49+
throw new Error("Invalid repo name string!");
5050
}
51-
)
52-
.then(({ stdout, stderr }) => {
53-
console.log(stdout);
54-
console.log(stderr);
55-
if (stdout || stderr) {
51+
52+
const cloneStatus = await execPromisified(
53+
`git clone "${cloneUrl}" "./${repoName}"`,
54+
{
55+
cwd: repoPath,
56+
windowsHide: true,
57+
}
58+
)
59+
.then(({ stdout, stderr }) => {
5660
console.log(stdout);
57-
return true;
58-
} else {
61+
console.log(stderr);
62+
if (stdout || stderr) {
63+
console.log(stdout);
64+
return true;
65+
} else {
66+
return false;
67+
}
68+
})
69+
.catch((err) => {
70+
console.log(err);
5971
return false;
60-
}
61-
})
62-
.catch((err) => {
63-
console.log(err);
64-
return false;
65-
});
72+
});
6673

67-
console.log("CLONE STAT : ", cloneStatus);
74+
console.log("CLONE STAT : ", cloneStatus);
6875

69-
if (cloneStatus) {
70-
if (repoPath.includes("\\")) {
71-
repoPath = repoPath + "\\" + repoName;
76+
if (cloneStatus) {
77+
if (repoPath.includes("\\")) {
78+
repoPath = repoPath + "\\" + repoName;
79+
} else {
80+
repoPath = repoPath + "/" + repoName;
81+
}
7282
} else {
73-
repoPath = repoPath + "/" + repoName;
83+
return errorResponse();
7484
}
75-
} else {
85+
} catch (err) {
86+
console.log(err);
7687
return errorResponse();
7788
}
7889
}

API/commitLogSearchApi.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const sqlite = require("sqlite3").verbose();
2+
const path = require("path");
3+
const db = new sqlite.Database(
4+
path.join(__dirname, "..", "/database/commitLogs.sqlite")
5+
);
6+
const { gitCommitLogSearchHandler } = require("../git/gitCommitLogSearchApi");
7+
8+
async function gitCommitLogDbSerchApi(repoId, searchCategory, searchKey) {
9+
let searchQuery = "";
10+
11+
switch (searchCategory) {
12+
case "hash":
13+
searchQuery = `SELECT * FROM commitLog_${repoId} WHERE hash LIKE "${searchKey}%" LIMIT 10`;
14+
break;
15+
case "message":
16+
searchQuery = `SELECT * FROM commitLog_${repoId} WHERE commit_message LIKE "%${searchKey}%" LIMIT 10`;
17+
break;
18+
case "user":
19+
searchQuery = `SELECT * FROM commitLog_${repoId} WHERE author LIKE "%${searchKey}%" LIMIT 10`;
20+
break;
21+
default:
22+
searchQuery = `SELECT * FROM commitLog_${repoId} WHERE commit_message LIKE "%${searchKey}%" LIMIT 10`;
23+
break;
24+
}
25+
26+
return new Promise((resolve, reject) => {
27+
db.all(searchQuery, [], async (err, rows) => {
28+
if (err) {
29+
console.log(err);
30+
reject("Database fetch error");
31+
}
32+
if (rows) {
33+
const hashArray = rows.map((row) => {
34+
return row.hash;
35+
});
36+
const commits = await gitCommitLogSearchHandler(repoId, hashArray)
37+
.then(async (res) => {
38+
console.log(await res.commits);
39+
return Promise.all(res.commits).then((commit) => {
40+
return commit;
41+
});
42+
})
43+
.catch((err) => {
44+
console.log(err);
45+
return [];
46+
});
47+
resolve(commits);
48+
}
49+
});
50+
});
51+
}
52+
53+
module.exports.gitCommitLogDbSerchApi = gitCommitLogDbSerchApi;

API/deleteRepoApi.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
const fs = require("fs");
22
const path = require("path");
3+
const { getEnvData } = require("../utils/getEnvData");
34

4-
function getEnvData() {
5-
const envFileData = fs.readFileSync(
6-
path.join(__dirname, "..", "env_config.json")
7-
);
5+
/**
6+
* @param {String} repoId - ID of the repo stored in the data file
7+
*/
88

9-
const envContent = envFileData.toString();
10-
let envData = JSON.parse(envContent)[0];
119

12-
return {
13-
DATABASE_FILE: envData.databaseFile,
14-
GITCONVEX_PORT: envData.port,
15-
};
16-
}
17-
18-
async function deleteRepoApi(repoId) {
10+
async function deleteRepoApi(repoId) {
1911
const dataStoreFile = getEnvData().DATABASE_FILE;
2012

2113
return await fs.promises

API/fetchRepoApi.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
const fs = require("fs");
22
const path = require("path");
3+
const { getEnvData } = require("../utils/getEnvData");
34

4-
function getEnvData() {
5-
const envFileData = fs.readFileSync(
6-
path.join(__dirname, "..", "env_config.json")
7-
);
8-
9-
const envContent = envFileData.toString();
10-
let envData = JSON.parse(envContent)[0];
11-
12-
return {
13-
DATABASE_FILE: envData.databaseFile,
14-
GITCONVEX_PORT: envData.port,
15-
};
16-
}
5+
/**
6+
* @returns {Object} - details about all the repos stored in the data file
7+
*/
178

189
async function fetchRepoHandler() {
1910
var repoDSContent = fs.readFileSync(getEnvData().DATABASE_FILE);

API/healthcheckApi.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ const util = require("util");
33
const execPromise = util.promisify(exec);
44
const os = require("os");
55

6+
/**
7+
* @returns {Object} - Version of the required software and the platform on which the app is running
8+
*/
9+
610
async function healthCheckHandler() {
711
let healthCheckResults = {
812
osCheck: "",
@@ -23,6 +27,11 @@ async function healthCheckHandler() {
2327
return { ...healthCheckResults };
2428
}
2529

30+
/**
31+
* @param {String} param
32+
* @returns {Object} - Executes the shell command and returns the results
33+
*/
34+
2635
async function checkStatus(param) {
2736
var commandString = "";
2837

@@ -34,7 +43,7 @@ async function checkStatus(param) {
3443
commandString = `node --version`;
3544
break;
3645
default:
37-
commandString = `echo 'NO_COMMAND'`;
46+
commandString = ` `;
3847
}
3948

4049
return await execPromise(commandString, { windowsHide: true }).then((res) => {

API/settingsApi.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
const fs = require("fs");
22
const path = require("path");
3+
const { getEnvData } = require("../utils/getEnvData");
34

4-
function getEnvData() {
5-
const envFileData = fs.readFileSync(
6-
path.join(__dirname, "..", "env_config.json")
7-
);
8-
9-
const envContent = envFileData.toString();
10-
let envData = JSON.parse(envContent)[0];
11-
12-
return {
13-
DATABASE_FILE: envData.databaseFile,
14-
GITCONVEX_PORT: envData.port,
15-
};
16-
}
5+
/**
6+
* @returns {Object} - Path where the Data file is stored
7+
*/
178

189
const fetchDatabaseFile = async () => {
1910
const dbPath = getEnvData().DATABASE_FILE || "NO_DATABASE_FILE";
@@ -23,6 +14,10 @@ const fetchDatabaseFile = async () => {
2314
};
2415
};
2516

17+
/**
18+
* @returns {Array} - The array containing the list of all repos stored in the data file
19+
*/
20+
2621
const fetchRepoDetails = async () => {
2722
return await fs.promises
2823
.readFile(getEnvData().DATABASE_FILE)
@@ -57,6 +52,11 @@ const fetchRepoDetails = async () => {
5752
});
5853
};
5954

55+
/**
56+
* @param {String} newFileName - A new JSON file for storing repo information
57+
* @returns {String} - updates the data file in config file and returns the status as string
58+
*/
59+
6060
const updateDbFile = async (newFileName) => {
6161
console.log("FILE NAME : ", newFileName);
6262

@@ -95,6 +95,11 @@ const getPortDetails = async () => {
9595
return { settingsPortDetails: Number(getEnvData().GITCONVEX_PORT) };
9696
};
9797

98+
/**
99+
* @param {number} newPort - new port number for running gitconvex
100+
* @returns {String} - status string for updating the port
101+
*/
102+
98103
const updatePortDetails = async (newPort) => {
99104
if (!isNaN(newPort)) {
100105
const envContent = fs

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
> Use any of the below options to get gitconvex for your system
1515
16-
[![gitconvex npm package](https://img.shields.io/static/v1?label=gitconvex&message=v1.1.3&color=red&style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@itassistors/gitconvex)
17-
[![github release](https://img.shields.io/static/v1?label=gitconvex&message=v1.1.3&color=green&style=for-the-badge&logo=github)](https://github.com/neel1996/gitconvex-package/releases)
18-
[![docker image](https://img.shields.io/static/v1?label=gitconvex&message=v1.1.3&color=blue&style=for-the-badge&logo=docker)](https://hub.docker.com/repository/docker/itassistors/gitconvex)
16+
[![gitconvex npm package](https://img.shields.io/static/v1?label=gitconvex&message=v1.1.4&color=red&style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@itassistors/gitconvex)
17+
[![github release](https://img.shields.io/static/v1?label=gitconvex&message=v1.1.4&color=green&style=for-the-badge&logo=github)](https://github.com/neel1996/gitconvex-package/releases)
18+
[![docker image](https://img.shields.io/static/v1?label=gitconvex&message=v1.1.4&color=blue&style=for-the-badge&logo=docker)](https://hub.docker.com/repository/docker/itassistors/gitconvex)
1919
[![License](https://img.shields.io/static/v1?label=LICENSE&message=Apache-2.0&color=yellow&style=for-the-badge)](LICENSE)
2020

2121
- **Option - 1** Cloning repo from **github**
@@ -91,3 +91,4 @@ Refer the detailed [Documentation](DOCUMENTATION.md) for how to setup and use th
9191
# License
9292

9393
See [LICENSE ](LICENSE) info for more
94+

0 commit comments

Comments
 (0)