Skip to content

Commit da95dbb

Browse files
committed
Added API module for handling new branch addition module
1 parent 032935f commit da95dbb

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

git/gitAddBranchApi.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { exec } = require("child_process");
2+
const util = require("util");
3+
const execPromisified = util.promisify(exec);
4+
5+
const fetchRepopath = require("../global/fetchGitRepoPath");
6+
7+
const gitAddBranchApi = async (repoId, branchName) => {
8+
return await execPromisified(
9+
`cd ${fetchRepopath.getRepoPath(repoId)}; git checkout -b ${branchName}`
10+
)
11+
.then((res) => {
12+
console.log(res);
13+
return "BRANCH_CREATION_SUCCESS";
14+
})
15+
.catch((err) => {
16+
console.log(err);
17+
return "BRANCH_ADD_FAILED";
18+
});
19+
};
20+
21+
module.exports.gitAddBranchApi = gitAddBranchApi;

global/globalAPIHandler.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const {
4343
gitFetchFromRemote,
4444
gitPullFromRemote,
4545
deleteRepo,
46+
addBranch,
4647
} = require("./globalFunctionStore");
4748

4849
app.use(
@@ -130,6 +131,10 @@ app.use(
130131
const { repoId, name, pathName, time } = args;
131132
return await deleteRepo(repoId, name, pathName, time);
132133
},
134+
addBranch: async (args) => {
135+
const { repoId, branchName } = args;
136+
return await addBranch(repoId, branchName)
137+
},
133138
},
134139
})
135140
);

global/globalFunctionStore.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const {
1919
} = require("../git/gitRemoveStagedItems");
2020
const { gitFetchApi, gitPullApi } = require("../git/gitFetchPullApi");
2121
const { deleteRepoApi } = require("../API/deleteRepoApi");
22+
const { gitAddBranchApi } = require("../git/gitAddBranchApi");
2223

2324
module.exports.healthCheckFunction = healthCheckFunction = async (payload) => {
2425
const hcPayload = await healthCheckHandler().then((res) => res);
@@ -227,3 +228,7 @@ module.exports.deleteRepo = deleteRepo = async (
227228
) => {
228229
return await deleteRepoApi(repoId, name, pathName, time);
229230
};
231+
232+
module.exports.addBranch = addBranch = async (repoId, branchName) => {
233+
return await gitAddBranchApi(repoId, branchName);
234+
};

global/gqlGlobalAPISchema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const globalAPISchema = new buildSchema(
100100
settingsDeleteRepo(repoId: String!): String!
101101
removeStagedItem(repoId: String!, item: String!): String!
102102
removeAllStagedItem(repoId: String!): String!
103+
addBranch(repoId: String!, branchName: String!): String!
103104
fetchFromRemote(repoId: String!): gitFetchStatus!
104105
pullFromRemote(repoId: String!): gitPullStatus!
105106
deleteRepo(repoId: String!, name: String!, pathName: String!, time: String!): deleteRepoStatus!

0 commit comments

Comments
 (0)