Skip to content

Commit

Permalink
More modifications to improve quality
Browse files Browse the repository at this point in the history
  • Loading branch information
mukkachaitanya committed Oct 31, 2018
1 parent 6db57af commit 417c17c
Show file tree
Hide file tree
Showing 17 changed files with 1,106 additions and 119 deletions.
7 changes: 3 additions & 4 deletions .buddyrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"detectObjects": false,
"enforceConst": false,
"ignore": [0, 1, 2, 3],
"reporter": "detailed"
"detectObjects": true,
"enforceConst": true,
"reporter": "detailed"
}
1 change: 1 addition & 0 deletions .eslintrc → .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"rules": {
"max-lines-per-function" : ["error", 30],
"no-plusplus" : ["error", { "allowForLoopAfterthoughts": true }],
"no-console" : ["off"],
"no-unused-vars": [
"error",
{
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
.nyc_output/
coverage/
coverage.lcov
module-depencency.svg
12 changes: 12 additions & 0 deletions .madgerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"fontSize": "10px",
"backgroundColor" : "#ffffff",
"nodeColor": "#000000",
"edgeColor" : "#000000",
"noDependencyColor" : "#7f7f7f",
"graphVizOptions": {
"G": {
"rankdir": "LR"
}
}
}
6 changes: 4 additions & 2 deletions lib/cli/output/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ const sendError = (error) => {
};

const handleResponse = (status) => {
if (status.code === 200) {
const httpOK = 200;
const httpFailure = 4;
if (status.code === httpOK) {
sendSuccessWelcome(status.name);
} else if (status.code === 4) {
} else if (status.code === httpFailure) {
sendError('\nPlease check your network connection');
} else {
sendError('\nInvalid Username or Password');
Expand Down
3 changes: 2 additions & 1 deletion lib/model/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const getRequestArray = (evalOptions) => {
return [idNo, lab, commitHash, lang];
};

const socketEventHandler = (event, socket, data, callback) => {
/* eslint-disable max-lines-per-function */
const socketEventHandler = (event, socket, data, callback) => {
let response;
switch (event) {
case 'invalid':
Expand Down
7 changes: 5 additions & 2 deletions lib/model/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const fetchPrivateToken = async (host, username, password) => {
};

logger.moduleLog('debug', 'Init Model', `POST request to ${options.uri}`);
console.log(options.uri);

const response = await requestPromise(options).json();
return {
Expand All @@ -30,20 +31,22 @@ const updateCredentials = (credentials, privateToken) => {
};

const authenticate = async (credentials) => {
const httpOK = 200;
const httpFailure = 4;
try {
const { privateToken, name } = await fetchPrivateToken(preferenceManager.getPreference({ name: 'cliPrefs' }).gitlab.host, credentials.username, credentials.password);
logger.moduleLog('debug', 'Init Model', `Authenticated ${name}.`);
updateCredentials(credentials, privateToken);
return {
code: 200,
code: httpOK,
name,
};
} catch (e) {
logger.moduleLog('error', 'Init Model', `${e}`);
if (!e.statusCode) {
logger.moduleLog('error', 'Init Model', 'Error code = 4');
return {
code: 4,
code: httpFailure,
};
}
return {
Expand Down
101 changes: 44 additions & 57 deletions lib/utils/preference-manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint no-use-before-define: "warn" */
const Preferences = require('preferences');
const _ = require('lodash');
const path = require('path');
Expand Down Expand Up @@ -32,51 +31,66 @@ const deleteCredentials = () => {
gitLabPrefs.storedTime = -1;
};

const storeGitlabPrefs = (values) => {
_.assign(gitLabPrefs, values);

gitLabPrefs.storedTime = Date.now();
};

const assignValidtor = (objValue, srcValue) => (srcValue || objValue);

const storeLoggerPrefs = (values) => {
const modValues = values;
const { blacklist } = modValues.logger;
if (blacklist && blacklist.keyword) {
if (_.isArray(blacklist.keyword)) {
_.assign(cliPrefs, {
logger: {
blacklist: blacklist.keyword,
},
});
} else {
cliPrefs.logger.blacklist.push(blacklist.keyword);
}
}

modValues.logger = _.omit(modValues.logger, 'blacklist');
_.assignWith(cliPrefs.logger, modValues.logger, assignValidtor);
};

const setDefaultGitlabHost = () => {
setPreference({
name: 'cliPrefs',
values: {
gitlab: {
host: defaultGitlab.host,
},
_.assign(cliPrefs, {
gitlab: {
host: defaultGitlab.host,
},
});
};

const setDefaultLanguage = () => {
setPreference({
name: 'cliPrefs',
values: {
submission: {
language: defaultLang,
},
_.assign(cliPrefs, {
submission: {
language: defaultLang,
},
});
};

const setDefaultMainServer = () => {
setPreference({
name: 'cliPrefs',
values: {
main_server: {
host: defaultMainServer.host,
port: defaultMainServer.port,
},
_.assign(cliPrefs, {
main_server: {
host: defaultMainServer.host,
port: defaultMainServer.port,
},
});
};

const setDefaultLogger = () => {
setPreference({
name: 'loggerPrefs',
values: {
logger: {
maxSize: defaultLogger.maxSize,
logDirectory: defaultLogger.logDirectory,
logLocation: defaultLogger.logLocation,
blacklist: {
keyword: defaultLogger.blacklist,
},
storeLoggerPrefs({
logger: {
maxSize: defaultLogger.maxSize,
logDirectory: defaultLogger.logDirectory,
logLocation: defaultLogger.logLocation,
blacklist: {
keyword: defaultLogger.blacklist,
},
},
});
Expand All @@ -97,33 +111,6 @@ const setDefaultPreferences = () => {
}
};

const storeGitlabPrefs = (values) => {
_.assign(gitLabPrefs, values);

gitLabPrefs.storedTime = Date.now();
};

const assignValidtor = (objValue, srcValue) => (srcValue || objValue);

const storeLoggerPrefs = (values) => {
const modValues = values;
const { blacklist } = modValues.logger;
if (blacklist && blacklist.keyword) {
if (_.isArray(blacklist.keyword)) {
_.assign(cliPrefs, {
logger: {
blacklist: blacklist.keyword,
},
});
} else {
cliPrefs.logger.blacklist.push(blacklist.keyword);
}
}

modValues.logger = _.omit(modValues.logger, 'blacklist');
_.assignWith(cliPrefs.logger, modValues.logger, assignValidtor);
};

const getPreference = (options) => {
switch (options.name) {
case 'gitLabPrefs':
Expand Down
Loading

0 comments on commit 417c17c

Please sign in to comment.