-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
4,988 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
{ | ||
"extends": "airbnb-base" | ||
} | ||
"extends": "airbnb-base", | ||
"env": { | ||
"mocha": true, | ||
"node": true | ||
}, | ||
"rules": { | ||
"no-underscore-dangle": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: node_js | ||
notifications: | ||
slack: theselftalk:EHiDWYYgq34Y172TrHTqA16W | ||
node_js: | ||
- stable | ||
install: | ||
- npm install | ||
script: | ||
- npm test | ||
after_success: | ||
- npm run coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
/** | ||
* @fileOverview Clones the Submissions of the cadets | ||
*/ | ||
const R = require('ramda'); | ||
const shell = require('shelljs'); | ||
const Progress = require('cli-progress'); | ||
const { getCadets } = require('./members.fp'); | ||
const { getConfig } = require('./config/config-file.fp'); | ||
const log = require('../logger')('coderoom:clone'); | ||
|
||
/** | ||
* A progress bar to show the status of completion | ||
*/ | ||
const progressBar = new Progress.Bar( | ||
{ | ||
stopOnComplete: true, | ||
format: 'Cloning Assignments [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}', | ||
}, | ||
Progress.Presets.shades_classic, | ||
); | ||
|
||
/** | ||
* Gets a Gitlab Url from the config | ||
* and trims the protocol substring | ||
* @param {String} url | ||
*/ | ||
const getUrlWithNoProtocol = R.compose( | ||
R.replace(/^https?:\/\//i, ''), | ||
R.slice(0, -1), | ||
R.prop('GITLAB_URL'), | ||
getConfig, | ||
); | ||
|
||
/** | ||
* Builds a git clone command for a given url, | ||
* assignment and a member. This function is | ||
* curried so that it can be partially | ||
* applied. | ||
* @param {String} url | ||
* @param {String} assignment | ||
* @param {String} member | ||
*/ | ||
const buildCloneCmd = | ||
R.curry((url, assignment, member) => | ||
`git clone git@${url}:${member}/${assignment}.git ${member}`); | ||
|
||
/** | ||
* Builds a clone command for a given assignment and member | ||
* over GitlabUrl fetched from the config | ||
* @param {String} assignment | ||
* @param {String} member | ||
*/ | ||
const buildCloneCmdWithGitlabUrl = R.call(buildCloneCmd, R.call(getUrlWithNoProtocol)); | ||
|
||
/** | ||
* Gets the name of the Assignment from the config. | ||
*/ | ||
const getAssignment = R.compose(R.prop('ASSIGNMENT'), getConfig); | ||
|
||
/** | ||
* Build a clone command for a given member | ||
* over the GitlabUrl and Assignment from the config | ||
* @param {String} Member | ||
*/ | ||
const buildCloneCmdWithGitlabUrlOverAssignment = R.call( | ||
buildCloneCmdWithGitlabUrl, | ||
R.call(getAssignment), | ||
); | ||
|
||
/** | ||
* Deletes All the directories(repos) in the current working directory. | ||
*/ | ||
const deleteExistingRepos = () => shell.rm('-Rf', '*/'); | ||
|
||
|
||
/** | ||
* Initializes the Progress Bar to the total length of the members. | ||
* And starts at 0. | ||
* @param {*} members | ||
*/ | ||
const startProgressBar = members => progressBar.start(members.length, 0); | ||
|
||
/** | ||
* Updates the progress bar incrementally | ||
*/ | ||
const incrementProgressBar = () => progressBar.increment(); | ||
|
||
/** | ||
* Promisfies the exec command on shelljs | ||
* @param {*} options | ||
* @param {*} command | ||
*/ | ||
const promisifiedShellExecCmd = (options, command) => new Promise((resolve, reject) => { | ||
shell.exec(command, options, (code, stdout, stderr) => { | ||
if (!code) { | ||
resolve(code); | ||
} else { | ||
const error = { | ||
command, | ||
message: R.replace(/(\r\n|\n|\r)/gm, '', stderr), | ||
}; | ||
reject(error); | ||
} | ||
}); | ||
}).catch(err => log.error(err)); | ||
|
||
/** | ||
* Curries the exec function of the shelljs library by reversing | ||
* the order of the variables. | ||
* @param {object} options | ||
* @param {string} command | ||
*/ | ||
const curriedExecCommand = R.curry(promisifiedShellExecCmd); | ||
|
||
/** | ||
* Given a member it clones the assignment in the current working directory | ||
* @param {String} username | ||
*/ | ||
const cloneRepo = R.compose( | ||
R.composeP(incrementProgressBar, curriedExecCommand({ silent: true, async: true })), | ||
buildCloneCmdWithGitlabUrlOverAssignment, | ||
); | ||
|
||
/** | ||
* Clones all the assignments of the cadets | ||
* in the current working directory | ||
* @param {Array} Members | ||
*/ | ||
const cloneAllAssignments = R.compose( | ||
R.map(cloneRepo), | ||
R.flatten, | ||
R.takeLast(1), | ||
R.juxt([startProgressBar, R.identity]), | ||
R.pluck('username'), | ||
); | ||
|
||
/** | ||
* Checks if git is installed | ||
*/ | ||
const checkIfGitExists = () => !shell.which('git').code; | ||
|
||
/** | ||
* On calling this method it throws an error that Git doesn't exists. | ||
*/ | ||
const throwGitDoesntExists = () => { | ||
throw Error("package 'git' could not be found. Coderoom depends on 'GIT'"); | ||
}; | ||
|
||
/** | ||
* An entry point to clone all Assignments | ||
*/ | ||
const clone = R.ifElse( | ||
checkIfGitExists, | ||
R.compose( | ||
R.composeP( | ||
Promise.all.bind(Promise), | ||
cloneAllAssignments, | ||
getCadets, | ||
), | ||
deleteExistingRepos, | ||
), | ||
throwGitDoesntExists, | ||
); | ||
|
||
module.exports = { | ||
clone, | ||
__private__: { | ||
progressBar, | ||
cloneRepo, | ||
getAssignment, | ||
buildCloneCmd, | ||
startProgressBar, | ||
checkIfGitExists, | ||
curriedExecCommand, | ||
deleteExistingRepos, | ||
cloneAllAssignments, | ||
getUrlWithNoProtocol, | ||
throwGitDoesntExists, | ||
incrementProgressBar, | ||
promisifiedShellExecCmd, | ||
buildCloneCmdWithGitlabUrl, | ||
buildCloneCmdWithGitlabUrlOverAssignment, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
REVIEWERS_NAME: 'Nishant Jain' | ||
'https://gitlab-cts.stackroute.in/': VBJ1D55fncUyy1xMMsWT |
Oops, something went wrong.