generated from agiledev-students-fall2023/generic-project-repository
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
e0d3a46
commit 2eb5ee1
Showing
23 changed files
with
493 additions
and
473 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,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 | ||
); | ||
} | ||
} |
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,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); |
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
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
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,72 +1,87 @@ | ||
import {useState, useEffect} from 'react'; | ||
import {useParams} from 'react-router-dom'; | ||
import { useState, useEffect } from "react"; | ||
import { useParams } from "react-router-dom"; | ||
import { useAuthContext } from "./AuthProvider.js"; | ||
import axios from 'axios'; | ||
import '../css/Comments.css'; | ||
import CommentPostForm from './CommentPostForm.js'; | ||
import CommentPost from './CommentPost.js'; | ||
|
||
import axios from "axios"; | ||
import "../css/Comments.css"; | ||
import CommentPostForm from "./CommentPostForm.js"; | ||
import CommentPost from "./CommentPost.js"; | ||
|
||
function Comment() { | ||
const username = useAuthContext().user; | ||
const [comments, setComments] = useState(''); | ||
const {songArtist, songTitle} = useParams(); | ||
const [comments, setComments] = useState(""); | ||
const { songArtist, songTitle } = useParams(); | ||
const [showForm, setShowForm] = useState(true); | ||
const addCommentToList = comment => { | ||
const newComments = [comment, ...comments] | ||
setComments(newComments) | ||
} | ||
const addCommentToList = (comment) => { | ||
const newComments = [comment, ...comments]; | ||
setComments(newComments); | ||
}; | ||
|
||
useEffect(() => { | ||
axios | ||
.get(`http://localhost:3000/comments/${songArtist}/${songTitle}/${username}`) | ||
.then(response => { | ||
.get( | ||
`http://localhost:3000/comments/${songArtist}/${songTitle}/${username}` | ||
) | ||
.then((response) => { | ||
const comments = response.data; | ||
console.log(comments); | ||
setComments(comments); | ||
}) | ||
.catch(err => { | ||
console.log("Error fetching data:", err) | ||
}) | ||
}, [songArtist, songTitle, username]) | ||
.catch((err) => { | ||
console.log("Error fetching data:", err); | ||
}); | ||
}, [songArtist, songTitle, username]); | ||
|
||
useEffect(() => { | ||
console.log(comments); | ||
comments.localeCompare((comment) => { | ||
if (comment.username === username) { | ||
setShowForm(false) | ||
setShowForm(false); | ||
} | ||
}) | ||
}, [comments]) | ||
}); | ||
}, [comments]); | ||
|
||
if (comments) { | ||
return ( | ||
<div className="Comment"> | ||
{showForm && | ||
<> | ||
<h3>Add Comment:</h3> | ||
<CommentPostForm setShowForm={setShowForm} addCommentToList={addCommentToList} songArtist={songArtist} songTitle={songTitle} username={username}/> | ||
</> | ||
} | ||
<h3>Other comments:</h3> | ||
if (comments) { | ||
return ( | ||
<div className="Comment"> | ||
{showForm && ( | ||
<> | ||
<h3>Add Comment:</h3> | ||
<CommentPostForm | ||
setShowForm={setShowForm} | ||
addCommentToList={addCommentToList} | ||
songArtist={songArtist} | ||
songTitle={songTitle} | ||
username={username} | ||
/> | ||
</> | ||
)} | ||
<h3>Other comments:</h3> | ||
{comments.map((comment, i) => ( | ||
<CommentPost key={i} comment={comment} songArtist={songArtist} songTitle={songTitle} username={username}/> | ||
<CommentPost | ||
key={i} | ||
comment={comment} | ||
songArtist={songArtist} | ||
songTitle={songTitle} | ||
username={username} | ||
/> | ||
))} | ||
</div> | ||
); | ||
} | ||
else { | ||
return ( | ||
<div className="Comment"> | ||
{showForm && | ||
<> | ||
<CommentPostForm setShowForm={setShowForm} addCommentToList={addCommentToList} songArtist={songArtist} songTitle={songTitle} username={username}/> | ||
</> | ||
} | ||
</div> | ||
); | ||
</div> | ||
); | ||
} else { | ||
return ( | ||
<div className="Comment"> | ||
{showForm && ( | ||
<> | ||
<CommentPostForm | ||
setShowForm={setShowForm} | ||
addCommentToList={addCommentToList} | ||
songArtist={songArtist} | ||
songTitle={songTitle} | ||
username={username} | ||
/> | ||
</> | ||
)} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
}; | ||
|
||
export default Comment; | ||
export default Comment; |
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,52 +1,55 @@ | ||
import { useState } from 'react' | ||
import axios from 'axios' | ||
import { useState } from "react"; | ||
import axios from "axios"; | ||
import { useAuthContext } from "./AuthProvider.js"; | ||
|
||
const CommentPostForm = ({setShowForm, addCommentToList, songArtist, songTitle}) => { | ||
const username = useAuthContext().user | ||
const CommentPostForm = ({ | ||
setShowForm, | ||
addCommentToList, | ||
songArtist, | ||
songTitle, | ||
}) => { | ||
const username = useAuthContext().user; | ||
// create a state variable for each form field | ||
const [comment, setComment] = useState('') | ||
|
||
const submitForm = e => { | ||
e.preventDefault() // prevent normal browser submit behavior | ||
console.log("username", username) | ||
console.log("comment", comment) | ||
|
||
const [comment, setComment] = useState(""); | ||
|
||
const submitForm = (e) => { | ||
e.preventDefault(); // prevent normal browser submit behavior | ||
// send data to server... getting server host name from .env environment variables file to make it easy to swap server hosts in one place | ||
axios | ||
.post(`http://localhost:3000/comment/${songArtist}/${songTitle}/${username}/save`, { | ||
username: username, | ||
comment: comment, | ||
}) | ||
.then(response => { | ||
addCommentToList(response.data) | ||
}) | ||
.catch(err => { | ||
console.log("Error posting data:", err) | ||
.post( | ||
`http://localhost:3000/comment/${songArtist}/${songTitle}/${username}/save`, | ||
{ | ||
username: username, | ||
comment: comment, | ||
} | ||
) | ||
.then((response) => { | ||
addCommentToList(response.data); | ||
}) | ||
.catch((err) => { | ||
console.log("Error posting data:", err); | ||
}); | ||
|
||
// clear form | ||
setShowForm(false) | ||
} | ||
setShowForm(false); | ||
}; | ||
|
||
return ( | ||
<form className="CommentForm" onSubmit={submitForm}> | ||
<label for="comment">Add Comment: </label> | ||
<textarea | ||
id="song-comment" | ||
value={comment} | ||
name="song-comment" | ||
onChange={(e) => setComment(e.target.value)} | ||
placeholder="Enter a comment" | ||
rows="10" | ||
/> | ||
<div class="button"> | ||
<input type="submit" disabled={!comment} value="Enter"/> | ||
</div> | ||
<textarea | ||
id="song-comment" | ||
value={comment} | ||
name="song-comment" | ||
onChange={(e) => setComment(e.target.value)} | ||
placeholder="Enter a comment" | ||
rows="10" | ||
/> | ||
<div class="button"> | ||
<input type="submit" disabled={!comment} value="Enter" /> | ||
</div> | ||
</form> | ||
) | ||
} | ||
); | ||
}; | ||
|
||
export default CommentPostForm; | ||
|
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
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
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