Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tests #73

Merged
merged 15 commits into from
Jan 31, 2024
29 changes: 29 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/javascript-node
{
"name": "Node.js",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/javascript-node:1-20-bullseye",
"customizations": {
"vscode": {
"extensions": [
"esbenp.prettier-vscode"
]
}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = {
plugins: ['import'],
rules: {
// enable additional rules
quotes: ['error', 'single'],
quotes: ['error', 'single', { "avoidEscape": true }],
semi: ['error', 'always'],

// disable rules from base configurations
Expand All @@ -15,7 +15,7 @@ module.exports = {
'func-names': 'off',
'consistent-return': 'off',
'prefer-arrow-callback': 'off',
'arrow-parens': 'as-needed',
'arrow-parens': 'off',
// Windows friendly -- does not show errors on every line of every file
'no-unused-vars': 1,
'linebreak-style': 0
Expand Down
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Ci
on: [push, pull_request]
on: [pull_request, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "16"
node-version: "20"
- run: npm ci
- run: npm test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ test/files/environment/projects
.secrets

user
auth
auth
.env*
21 changes: 21 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "lf",
"insertPragma": false,
"singleAttributePerLine": false,
"bracketSameLine": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false,
"embeddedLanguageFormatting": "auto",
"parser": "babel"
}
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"enterPartnerName": "Enter the GitHub username of your partner (you can ask them to type it)"}
},
"userAgent": "opspark"
}
}
35 changes: 21 additions & 14 deletions controller/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ const util = require('util');
const prompt = require('inquirer').prompt;
const mkdirp = require('mkdirp');
const fsJson = require('fs-json')();
const octonode = require('octonode');
const rp = require('request-promise');

const exec = require('child_process').exec;

const env = require('./env');
const config = require('../config.json');
const janitor = require('./janitor');
const {
createGithubToken,
deleteGithubToken,
Expand Down Expand Up @@ -95,6 +93,12 @@ function promptForUserInfo() {

module.exports.promptForUserInfo = promptForUserInfo;

/**
*
* @param {object} auth
* @param {string} auth.token GitHub Personal Access Token
* @returns {Promise<{token: string}>}
*/
function writeAuth(auth) {
deleteAuth();
console.log(clc.yellow('Writing auth. . .'));
Expand Down Expand Up @@ -137,8 +141,10 @@ function writeUser(auth) {
const { id, message } = JSON.parse(stdout);
if (err) {
rej(err);
return;
} else if (message) {
rej(message);
return;
}
ensureApplicationDirectory();
fsJson.saveSync(userFilePath, {
Expand Down Expand Up @@ -291,17 +297,14 @@ function grabLocalAuthToken() {

module.exports.grabLocalAuthToken = grabLocalAuthToken;

function deauthorizeUser() {
return new Promise(function (res, rej) {
promptForUserInfo()
// .then(deleteAuth)
.then(deleteUserInfo)
.then(() => {
console.log(clc.blue('Successfully logged out!'));
res(true);
})
.catch(err => rej(`${err}`.red));
});
async function deauthorizeUser() {
try {
deleteUserInfo();
console.log(clc.blue('Successfully logged out!'));
return true;
} catch (error) {
return Promise.reject(clc.red(`${error}`));
}
}

module.exports.deauthorizeUser = deauthorizeUser;
Expand Down Expand Up @@ -336,6 +339,10 @@ function deleteUser() {

module.exports.deleteUser = deleteUser;

// TODO: Should be async
/**
* Deletes the auth and user files.
*/
function deleteUserInfo() {
console.log(clc.red('Deleting files. . .'));
deleteAuth();
Expand Down
6 changes: 3 additions & 3 deletions controller/greenlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const clc = require('cli-color');
const rp = require('request-promise');

const github = require('./github');
const { devGreenlightHost, isDevMode } = require('../dev-config');

// TODO: Switch URI for live version
const LOCALHOST = 'http://localhost:3000';
const GREENLIGHT = 'https://greenlight.operationspark.org';
const URI = GREENLIGHT;
// TODO: Switch URI for live version
const URI = isDevMode ? devGreenlightHost : GREENLIGHT;

module.exports.URI = URI;

Expand Down
13 changes: 9 additions & 4 deletions controller/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports.execAsync = function execAsync(cmd) {
return new Promise((res, rej) => {
exec(cmd, (err, stdout, stderr) => {
if (err) return rej(err);
return res(stdout, stderr);
return res({ stdout, stderr });
});
});
};
Expand All @@ -27,7 +27,12 @@ module.exports.createGithubToken = function (username, password, note) {
return `curl -u "${username}:${password}" -d '{"scopes":["public_repo", "repo", "gist"],"note":"${note}","note_url":"https://www.npmjs.com/package/opspark"}' https://api.github.com/authorizations`;
};

module.exports.deleteGithubToken = function (username, password, userAgent, authID) {
module.exports.deleteGithubToken = function (
username,
password,
userAgent,
authID
) {
return `curl -X "DELETE" -u "${username}:${password}" -A "${userAgent}" -H "Accept: application/json" https://api.github.com/authorizations/${authID}`;
};

Expand Down Expand Up @@ -63,11 +68,11 @@ module.exports.readGistHelper = function (url) {
return `curl ${url}`;
};

module.exports.installProjectDependenciesCmd = function(directory) {
module.exports.installProjectDependenciesCmd = function (directory) {
return `npm install --prefix ${directory} --loglevel=error`;
};

module.exports.removeProjectTestsCmd = function(directory) {
module.exports.removeProjectTestsCmd = function (directory) {
return `rm -rf ${directory}/test`;
};

Expand Down
2 changes: 1 addition & 1 deletion controller/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = function () {
.catch(janitor.error(clc.red('Failure installing project')))
.then(projects.initializeProject)
.catch(janitor.error(clc.red('Failure initializing')))
.then(res => console.log(`Successfully installed ${res.name}!`.blue))
.then(res => console.log(clc.blue(`Successfully installed ${res.name}!`)))
.catch(err => {
console.error(err);
});
Expand Down
8 changes: 4 additions & 4 deletions controller/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function selectProject({ session, projectAction }) {
],
function (response) {
if (response.project === cancelOption) {
console.log(`${action} cancelled, bye bye!`.green);
console.log(clc.green(`${action} cancelled, bye bye!`));
process.exitCode = 0;
process.exit();
}
Expand Down Expand Up @@ -126,7 +126,7 @@ function installProject(project) {
const projectName = changeCase.paramCase(project.name);
const projectDirectory = `${projectsDirectory}/${projectName}`;
if (ensureProjectDirectory(projectDirectory)) {
rej(`${project.name} already installed!`.red);
rej(clc.red(`${project.name} already installed!`));
}
console.log(
clc.yellow('Installing project %s, please wait...'),
Expand All @@ -152,9 +152,9 @@ function uninstallProject(project) {
{
type: 'confirm',
name: 'delete',
message:
message: clc.bgRed(
`Are you sure you want to delete ${project.name}? This cannot be undone.`
.bgRed
)
},
function (confirm) {
if (confirm.delete) {
Expand Down
3 changes: 1 addition & 2 deletions controller/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const clc = require('cli-color');
const _ = require('lodash');
const inquirer = require('inquirer');
const { waterfall } = require('async');
const changeCase = require('change-case');

const projects = require('./projects');

Expand Down Expand Up @@ -34,7 +33,7 @@ function selectSession(sessions) {
],
function (response) {
if (response.class === cancelOption) {
console.log(`${projects.action} cancelled, bye bye!`.green);
console.log(clc.green(`${projects.action} cancelled, bye bye!`));
process.exitCode = 0;
process.exit();
}
Expand Down
4 changes: 2 additions & 2 deletions controller/shelve.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const sessions = require('./sessions');

module.exports = function () {
console.log(clc.blue('Beginning shelve process!'));
projects.action = 'shelve';
projects.action = () => 'shelve';
github
.getCredentials()
.catch(janitor.error(clc.red('Failure getting credentials')))
Expand All @@ -20,7 +20,7 @@ module.exports = function () {
.then(projects.shelveProject)
.catch(janitor.error(clc.red('Failure shelving project')))
.then(path =>
console.log(clc.blue('Project now available at'), `${path}!`.yellow)
console.log(clc.blue('Project now available at'), clc.yellow(`${path}!`))
)
.catch(err => {
console.error(err);
Expand Down
2 changes: 1 addition & 1 deletion controller/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module.exports.createGist = createGist;
function ensureGistExists({ project, gist, tries }) {
return new Promise(function (res, rej) {
if (tries < 4) {
console.log(`Ensuring gist exists. . . Attempt ${tries}`.yellow);
console.log(clc.yellow(`Ensuring gist exists. . . Attempt ${tries}`));
const cmd = readGistHelper(gist.files['grade.txt'].raw_url);
exec(cmd, function (err, stdout, stderr) {
if (err) {
Expand Down
Loading