Skip to content

Commit d89cac4

Browse files
committed
added a default case to commit log search API
1 parent ce28695 commit d89cac4

File tree

6 files changed

+59
-21
lines changed

6 files changed

+59
-21
lines changed

API/commitLogSearchApi.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ async function gitCommitLogDbSerchApi(repoId, searchCategory, searchKey) {
1818
case "user":
1919
searchQuery = `SELECT * FROM commitLog_${repoId} WHERE author LIKE "%${searchKey}%" LIMIT 10`;
2020
break;
21+
default:
22+
searchQuery = `SELECT * FROM commitLog_${repoId} WHERE commit_message LIKE "%${searchKey}%" LIMIT 10`;
23+
break;
2124
}
2225

2326
return new Promise((resolve, reject) => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"graphiql": "^0.17.5",
4141
"graphql": "^14.6.0",
4242
"sqlite3": "^5.0.0",
43-
"forever-monitor": "^3.0.1"
43+
"chokidar": "^3.4.2"
4444
},
4545
"devDependencies": {
4646
"@types/jest": "^26.0.7",

prettier.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
trailingComma: "es5",
3+
tabWidth: 4,
4+
semi: true,
5+
singleQuote: true,
6+
};

server.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const express = require("express");
55
const path = require("path");
66
const fs = require("fs");
77

8-
const { commitLogCrawler } = require("./utils/foreverProcess");
8+
const { gitCommitLogToDb } = require("./utils/sqliteDbAccess");
9+
const { gitRepoListener } = require("./utils/repoChangeListener");
910
const app = globalAPI;
1011
const log = console.log;
1112
var envConfigFilename = "env_config.json";
@@ -76,7 +77,11 @@ function writeConfigFile(insertFlag = false, envData = {}) {
7677

7778
if (insertFlag) {
7879
log("INFO: Inserting new data to config file");
79-
configData = [{ ...envData }];
80+
configData = [
81+
{
82+
...envData,
83+
},
84+
];
8085
} else {
8186
log(
8287
"INFO: Creating config file with default config -> " +
@@ -116,6 +121,21 @@ globalAPI.listen(getEnvData().GITCONVEX_PORT || 9001, async (err) => {
116121

117122
var DATABASE_FILE = getEnvData().DATABASE_FILE;
118123

124+
if (!fs.existsSync(DATABASE_FILE)) {
125+
log("INFO: Database directory is missing");
126+
await fs.promises
127+
.mkdir(path.join(__dirname, ".", "/database"))
128+
.then(async () => {
129+
log(
130+
"INFO: Created database directory\nINFO: Setting up new data file in database directory"
131+
);
132+
await dataFileCreator();
133+
})
134+
.catch((err) => {
135+
log("ERROR: database directory creation failed!");
136+
});
137+
}
138+
119139
await fs.promises
120140
.access(DATABASE_FILE)
121141
.then(() => {
@@ -145,24 +165,10 @@ globalAPI.listen(getEnvData().GITCONVEX_PORT || 9001, async (err) => {
145165
);
146166

147167
await dataFileCreator();
148-
149-
if (!fs.existsSync(DATABASE_FILE)) {
150-
log("INFO: Database directory is missing");
151-
await fs.promises
152-
.mkdir(path.join(__dirname, ".", "/database"))
153-
.then(async () => {
154-
log(
155-
"INFO: Created database directory\nINFO: Setting up new data file in database directory"
156-
);
157-
await dataFileCreator();
158-
})
159-
.catch((err) => {
160-
log("ERROR: database directory creation failed!");
161-
});
162-
}
163168
});
164169

165-
commitLogCrawler();
170+
gitCommitLogToDb();
171+
gitRepoListener();
166172

167173
log(
168174
`\n## Gitconvex is running on port ${getEnvData().GITCONVEX_PORT}

utils/repoChangeListener.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const chokidar = require("chokidar");
2+
const { fetchRepoHandler } = require("../API/fetchRepoApi");
3+
const { gitCommitLogToDb } = require("./sqliteDbAccess");
4+
5+
async function gitRepoListener() {
6+
console.log(
7+
"INFO: Repo path listener initiated. All changes in the configured repos will be tracked till gitconvex is stopped"
8+
);
9+
const { repoPath } = await fetchRepoHandler();
10+
11+
repoPath.push(__dirname);
12+
13+
if (repoPath) {
14+
repoPath.forEach((repo) => {
15+
chokidar
16+
.watch(repo, { interval: 1500, usePolling: true })
17+
.on("change", (path, stats) => {
18+
console.log("INFO: change noticed in ", path);
19+
gitCommitLogToDb();
20+
});
21+
});
22+
}
23+
}
24+
25+
module.exports.gitRepoListener = gitRepoListener;

utils/sqliteDbAccess.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,4 @@ async function inserToDbHandler(commitArray, db, repoId) {
157157
});
158158
}
159159

160-
gitCommitLogToDb();
161-
162160
module.exports.gitCommitLogToDb = gitCommitLogToDb;

0 commit comments

Comments
 (0)