Skip to content

Commit

Permalink
Merge 447add5 into 0d6e62c
Browse files Browse the repository at this point in the history
  • Loading branch information
nishant-jain-94 committed Feb 21, 2018
2 parents 0d6e62c + 447add5 commit 77503cd
Show file tree
Hide file tree
Showing 45 changed files with 4,988 additions and 237 deletions.
11 changes: 9 additions & 2 deletions .eslintrc.json
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"
}
}
11 changes: 11 additions & 0 deletions .travis.yml
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Coderoom
# Coderoom [![Build Status](https://travis-ci.org/nishant-jain-94/coderoom.svg?branch=master)](https://travis-ci.org/nishant-jain-94/coderoom) [![Coverage Status](https://coveralls.io/repos/github/nishant-jain-94/coderoom/badge.svg?branch=master)](https://coveralls.io/github/nishant-jain-94/coderoom?branch=master)

A Review Utility Tool for Gitlab which facilitates in code reviewing easily.

## Install

```
sudo npm install -g coderoom
sudo npm install -g coderoom-gitlab
```

## Command Line Usage
Expand Down
21 changes: 10 additions & 11 deletions bin/coderoom.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/usr/bin/env node

/**
* Main CLI which is used to run the reviewer.
* @author Nishant Jain
* @fileOverview Main CLI which is used to run the reviewer.
*/

/* eslint no-console:off */
/* eslint global-require:off */

const R = require('ramda');
const usage = require('../lib/cli-usage.js');
const configInitializer = require('../lib/config/config-initializer');
const configInitializer = require('../lib/config/config-initializer.fp');

const arg = process.argv[process.argv.length - 1];

Expand All @@ -18,22 +17,22 @@ switch (arg) {
configInitializer.initializeConfig();
break;
case 'members': {
const members = require('../lib/members');
members.load().then(membersOfGroup => console.log(membersOfGroup));
const { getCadets } = require('../lib/members.fp');
R.call(R.composeP(console.log, getCadets));
break;
}
case 'clone': {
const clone = require('../lib/clone');
clone.cloneAllAssignments();
const { clone } = require('../lib/clone.fp');
R.call(clone);
break;
}
case 'generate-insights': {
const insights = require('../lib/insights');
insights.generateInsightsAsHTML();
const insights = require('../lib/insights.fp');
insights.generateInsightsAsPDF();
break;
}
case 'open-issue': {
const issueOpener = require('../lib/open-issue');
const issueOpener = require('../lib/open-issues.fp');
issueOpener.openIssues();
break;
}
Expand Down
35 changes: 27 additions & 8 deletions lib/cli-usage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/**
* @fileOverview Usage Guide for Classroom
* @author Nishant Jain
*/

const getUsage = require('command-line-usage');

/**
* Describes the command usage guide
*/
const sections = [
{
header: 'Coderoom',
Expand All @@ -13,13 +15,30 @@ const sections = [
{
header: 'Command List',
content: [
{ name: 'help', summary: 'Displays a usage guide' },
{ name: 'version', summary: 'Displays the version of the review utility' },
{ name: 'initialize', summary: 'Initialize the repository with runtime configuration for the review utility' },
{ name: 'clone', summary: 'Clones all the assignments in the local submissions folder' },
{ name: 'members', summary: 'Lists all the members under review in the coderoom' },
{ name: 'open-issue', summary: 'Opens the issue on the repository, when executed inside a submission' },
{ name: 'generate-insights', summary: 'Generates coderoom insights' },
{
name: 'help',
summary: 'Displays a usage guide',
},
{
name: 'initialize',
summary: 'Initialize the repository with runtime configuration for the review utility',
},
{
name: 'clone',
summary: 'Clones all the assignments in the local submissions folder',
},
{
name: 'members',
summary: 'Lists all the members under review in the coderoom',
},
{
name: 'open-issue',
summary: 'Opens the issue on the repository, when executed inside a submission',
},
{
name: 'generate-insights',
summary: 'Generates coderoom insights',
},
],
},
];
Expand Down
184 changes: 184 additions & 0 deletions lib/clone.fp.js
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,
},
};
2 changes: 2 additions & 0 deletions lib/config/.reviewrc.global
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REVIEWERS_NAME: 'Nishant Jain'
'https://gitlab-cts.stackroute.in/': VBJ1D55fncUyy1xMMsWT

0 comments on commit 77503cd

Please sign in to comment.