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

removed console.logs #160

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 57 additions & 33 deletions automations/Code.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,80 @@
const getConfig = () => {
// global settings
return {
defaultChartSheetName: 'Sprint 1 - Team Plots',
logsSheetName: 'GitHub Logs',
logsSheetFields: ['repository', 'event', 'id', 'username', 'email', 'date', 'message', 'num_files', 'num_additions', 'num_deletions']
}
}
defaultChartSheetName: "Sprint 1 - Team Plots",
logsSheetName: "GitHub Logs",
logsSheetFields: [
"repository",
"event",
"id",
"username",
"email",
"date",
"message",
"num_files",
"num_additions",
"num_deletions",
],
};
};

const getSheet = () => {
const config = getConfig()
const ss = SpreadsheetApp.getActiveSpreadsheet() // container spreadsheet
let sheet = ss.getSheetByName(config.logsSheetName) // specific worksheet
const config = getConfig();
const ss = SpreadsheetApp.getActiveSpreadsheet(); // container spreadsheet
let sheet = ss.getSheetByName(config.logsSheetName); // specific worksheet
if (sheet == null) {
// create worksheet if none
sheet = ss.insertSheet(config.logsSheetName)
sheet.appendRow(config.logsSheetFields) // heading row
sheet = ss.insertSheet(config.logsSheetName);
sheet.appendRow(config.logsSheetFields); // heading row
}
return sheet
}
return sheet;
};

function doGet(e) {
// get the sheet name with the charts from the query string
const config = getConfig()
// we expect a `sheet` query string in the request
const sheetName = (e.parameter["sheet"]) ? decodeURIComponent(e.parameter["sheet"]) : config.defaultChartSheetName
Logger.log(`Loading charts from sheet: ${sheetName}`)
charts = getCharts(sheetName)
const content = generateHtml(sheetName, charts)
return HtmlService.createHtmlOutput(content)
const config = getConfig();
// we expect a `sheet` query string in the request
const sheetName = e.parameter["sheet"]
? decodeURIComponent(e.parameter["sheet"])
: config.defaultChartSheetName;
Logger.log(`Loading charts from sheet: ${sheetName}`);
charts = getCharts(sheetName);
const content = generateHtml(sheetName, charts);
return HtmlService.createHtmlOutput(content);
}

function doPost(e) {
console.log("Incoming post request")
console.log(JSON.stringify(e, null, 2))
const sheet = getSheet()
const sheet = getSheet();
const res = {
type: 'post',
e: e
}
type: "post",
e: e,
};
const commit_data = JSON.parse(e.postData.contents); // should be an array of objects
if (Array.isArray(commit_data)) {
for (let i=0; i<commit_data.length; i++) {
for (let i = 0; i < commit_data.length; i++) {
// log this commit!
const commit = commit_data[i]
console.log(JSON.stringify(commit, null, 2))
const commit = commit_data[i];
// append data array to sheet as new row
const row = [commit['repository_url'], commit['event_type'], commit['id'], commit['author_name'], commit['author_email'], commit['date'], commit['message'], commit['files'], commit['additions'], commit['deletions']]
const row = [
commit["repository_url"],
commit["event_type"],
commit["id"],
commit["author_name"],
commit["author_email"],
commit["date"],
commit["message"],
commit["files"],
commit["additions"],
commit["deletions"],
];
sheet.appendRow(row);
}
return ContentService.createTextOutput(commit_data).setMimeType(ContentService.MimeType.JSON)
}
else {
return ContentService.createTextOutput(typeof(commit_data)).setMimeType(ContentService.MimeType.TEXT)
return ContentService.createTextOutput(commit_data).setMimeType(
ContentService.MimeType.JSON
);
} else {
return ContentService.createTextOutput(typeof commit_data).setMimeType(
ContentService.MimeType.TEXT
);
}
}
42 changes: 20 additions & 22 deletions back-end/config/jwt-config.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
const mongoose = require("mongoose")
const ObjectId = mongoose.Types.ObjectId
const User = require("../models/user")
const mongoose = require("mongoose");
const ObjectId = mongoose.Types.ObjectId;
const User = require("../models/user");

const passportJWT = require("passport-jwt")
const ExtractJwt = passportJWT.ExtractJwt
const JwtStrategy = passportJWT.Strategy
const passportJWT = require("passport-jwt");
const ExtractJwt = passportJWT.ExtractJwt;
const JwtStrategy = passportJWT.Strategy;

// set up some JWT authentication options for passport
let jwtOptions = {
jwtFromRequest: ExtractJwt.fromAuthHeaderWithScheme("jwt"), // look for the Authorization request header
secretOrKey: process.env.JWT_SECRET, // an arbitrary string used during encryption - see the .env file
}
// console.log(jwtOptions) // debug to make sure the secret from the .env file is loaded correctly

};
// define the method that is used by passport to verify the contents (i.e. the payload) of the JWT token
const jwtVerifyToken = async function (jwt_payload, next) {
console.log("JWT payload received", jwt_payload) // debugging
console.log("JWT payload received", jwt_payload); // debugging

// check if the token has expired
const expirationDate = new Date(jwt_payload.exp * 1000) // convert from seconds to milliseconds
const expirationDate = new Date(jwt_payload.exp * 1000); // convert from seconds to milliseconds
if (expirationDate < new Date()) {
// the token has expired
return next(null, false, { message: "JWT token has expired." })
return next(null, false, { message: "JWT token has expired." });
}

// try to find a matching user in our database

// find this user in the database
const userId = new ObjectId(jwt_payload.id) // convert the string id to an ObjectId
const user = await User.findOne({ _id: userId }).exec()
const userId = new ObjectId(jwt_payload.id); // convert the string id to an ObjectId
const user = await User.findOne({ _id: userId }).exec();
if (user) {
// we found the user... keep going
next(null, user)
next(null, user);
} else {
// we didn't find the user... fail!
next(null, false, { message: "User not found" })
next(null, false, { message: "User not found" });
}
}
};

// passport can work with many authentication systems... here we are setting some middleware code for using JWT that we'll pass to passport to use
const jwtStrategy = jwtOptions => {
const strategy = new JwtStrategy(jwtOptions, jwtVerifyToken)
return strategy
}
const jwtStrategy = (jwtOptions) => {
const strategy = new JwtStrategy(jwtOptions, jwtVerifyToken);
return strategy;
};

module.exports = jwtStrategy(jwtOptions, jwtVerifyToken)
module.exports = jwtStrategy(jwtOptions, jwtVerifyToken);
4 changes: 1 addition & 3 deletions back-end/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ require("dotenv").config();
const connect_db = async () => {
try {
const mongoURL = process.env.MONGODB_URI;
await mongoose.connect(mongoURL, {
});
console.log("Connected to database.");
await mongoose.connect(mongoURL, {});
} catch (error) {
console.error("Error connecting to database: ", error);
process.exit(1);
Expand Down
Loading