This repository has been archived by the owner on Nov 21, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added react-scripts * Move Tailwind * Setup base pages * Added me page * Move Footer & GithubCorner to React, update .env * More styling, GithubCorner, reminder and footer are now showing * Fixed fonts * Update not found page * Reorganised pages, began working on username form * Finished TimeMessage * Finished UsernameForm * Began simplifying api * Further simplified API * Further simplified API * API now works too * Setup pr list file structure * Began working on PR list * Finished PR list * Fix spaces * Remove handlebars templates * Removed old public folder * Spacing fixes, better error handling * Fix share buttons * Remove unused dependencies * Styling and spacing fixes * Replace eslint with prettier, use 2 spaces * Use REACT_APP_HOSTNAME * Updated README and start commands * Fix env files * Allow react to built and the web app run from a single server * Add build folder to .gitignore, fix missing space & use arrow function * Updated .env.example * Update start script ready for deploy * Update Dockerfile and README
- Loading branch information
1 parent
7d2017d
commit 7d66365
Showing
75 changed files
with
8,214 additions
and
2,299 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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -17,3 +17,4 @@ Thumbs.db | |
# Compiled js | ||
public/js/main-compiled.js | ||
public/js/main-compiled.js.map | ||
build/ |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
singleQuote: true | ||
tabWidth: 2 | ||
printWidth: 80 |
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 |
---|---|---|
|
@@ -16,4 +16,4 @@ COPY --chown=octocat:octocat . /app | |
|
||
EXPOSE 5000 | ||
|
||
ENTRYPOINT ["node", "index.js"] | ||
ENTRYPOINT ["yarn", "start"] |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
const statusCodes = { | ||
notUser: 400 | ||
}; | ||
|
||
const errorDescriptions = { | ||
notUser: 'Username must belong to a user account.' | ||
}; | ||
|
||
const getStatusCode = error => statusCodes[error] || 400; | ||
|
||
const getErrorDescription = error => | ||
errorDescriptions[error] || | ||
"Couldn't find any data or we hit an error, err try again?"; | ||
|
||
module.exports.getStatusCode = getStatusCode; | ||
module.exports.getErrorDescription = getErrorDescription; |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const getNextPage = (response, github, pullRequestData) => | ||
new Promise((resolve, reject) => { | ||
github.getNextPage(response, (err, res) => { | ||
if (err) { | ||
return reject(); | ||
} | ||
|
||
const newPullRequestData = pullRequestData.concat(res.data.items); | ||
|
||
if (github.hasNextPage(res)) { | ||
getNextPage(res, github, newPullRequestData).then(pullRequestData => | ||
resolve(pullRequestData) | ||
); | ||
return; | ||
} | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
console.log(`Found ${pullRequestData.length} pull requests.`); | ||
} | ||
resolve(newPullRequestData); | ||
}); | ||
}); | ||
|
||
module.exports = getNextPage; |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const moment = require('moment'); | ||
const logCallsRemaining = require('../logCallsRemaining'); | ||
const loadPrs = require('./loadPrs'); | ||
|
||
const findPrs = (github, username) => { | ||
return loadPrs(github, username) | ||
.then(pullRequestData => | ||
_.map(pullRequestData, event => { | ||
const repo = event.pull_request.html_url.substring( | ||
0, | ||
event.pull_request.html_url.search('/pull/') | ||
); | ||
|
||
const hacktoberFestLabels = _.some( | ||
event.labels, | ||
label => label.name.toLowerCase() === 'hacktoberfest' | ||
); | ||
|
||
return { | ||
has_hacktoberfest_label: hacktoberFestLabels, | ||
number: event.number, | ||
open: event.state === 'open', | ||
repo_name: repo.replace('https://github.com/', ''), | ||
title: event.title, | ||
url: event.html_url, | ||
created_at: moment(event.created_at).format('MMMM Do YYYY'), | ||
user: { | ||
login: event.user.login, | ||
url: event.user.html_url | ||
} | ||
}; | ||
}) | ||
) | ||
.then(prs => { | ||
const checkMergeStatus = _.map(prs, pr => { | ||
const repoDetails = pr.repo_name.split('/'); | ||
const pullDetails = { | ||
owner: repoDetails[0], | ||
repo: repoDetails[1], | ||
number: pr.number | ||
}; | ||
|
||
return github.pullRequests | ||
.checkMerged(pullDetails) | ||
.then(logCallsRemaining) | ||
.then(res => res.meta.status === '204 No Content') | ||
.catch(err => { | ||
// 404 means there wasn't a merge | ||
if (err.code === 404) { | ||
return false; | ||
} | ||
|
||
throw err; | ||
}); | ||
}); | ||
|
||
return Promise.all(checkMergeStatus).then(mergeStatus => | ||
_.zipWith(prs, mergeStatus, (pr, merged) => _.assign(pr, { merged })) | ||
); | ||
}); | ||
}; | ||
|
||
module.exports = findPrs; |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
|
||
const getNextPage = require('./getNextPage'); | ||
|
||
const buildQuery = (username, searchYear) => | ||
`-label:invalid+created:${searchYear}-09-30T00:00:00-12:00..${searchYear}-10-31T23:59:59-12:00+type:pr+is:public+author:${username}`; | ||
|
||
const loadPrs = (github, username) => | ||
new Promise((resolve, reject) => { | ||
const today = new Date(); | ||
const currentMonth = today.getMonth(); | ||
const currentYear = today.getFullYear(); | ||
const searchYear = currentMonth < 9 ? currentYear - 1 : currentYear; | ||
|
||
github.search.issues( | ||
{ | ||
q: buildQuery(username, searchYear), | ||
// 30 is the default but this makes it clearer/allows it to be tweaked | ||
per_page: 100 | ||
}, | ||
(err, res) => { | ||
if (err) { | ||
return reject(); | ||
} | ||
|
||
const pullRequestData = res.data.items; | ||
if (github.hasNextPage(res)) { | ||
getNextPage(res, github, pullRequestData).then(pullRequestData => | ||
resolve(pullRequestData) | ||
); | ||
return; | ||
} | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
console.log(`Found ${pullRequestData.length} pull requests.`); | ||
} | ||
resolve(pullRequestData); | ||
} | ||
); | ||
}); | ||
|
||
module.exports = loadPrs; |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
const logCallsRemaining = require('./logCallsRemaining'); | ||
const findPrs = require('./findPrs'); | ||
const { getStatusCode, getErrorDescription } = require('./errors'); | ||
|
||
/** | ||
* GET / | ||
*/ | ||
exports.index = (req, res) => { | ||
const github = req.app.get('github'); | ||
const username = req.query.username; | ||
|
||
if (!username) { | ||
return res.status(400).json({ | ||
error_description: 'No username provided!' | ||
}); | ||
} | ||
|
||
Promise.all([ | ||
findPrs(github, username), | ||
github.users.getForUser({ username }).then(logCallsRemaining) | ||
]) | ||
.then(([prs, user]) => { | ||
if (user.data.type !== 'User') { | ||
return Promise.reject('notUser'); | ||
} | ||
|
||
const data = { | ||
prs, | ||
username, | ||
userImage: user.data.avatar_url | ||
}; | ||
|
||
res.json(data); | ||
}) | ||
.catch(err => { | ||
console.log('Error: ' + err); | ||
|
||
const statusCode = getStatusCode(err); | ||
const errorDescription = getErrorDescription(err); | ||
|
||
res.status(statusCode).json({ | ||
error_description: errorDescription | ||
}); | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
const logCallsRemaining = res => { | ||
const callsRemaining = res.meta['x-ratelimit-remaining']; | ||
|
||
if (process.env.NODE_ENV !== 'production' || callsRemaining < 100) { | ||
console.log(`API calls remaining: ${callsRemaining}`); | ||
} | ||
|
||
return res; | ||
}; | ||
|
||
module.exports = logCallsRemaining; |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
const cors = require('cors'); | ||
const dotenv = require('dotenv'); | ||
const setupGithubApi = require('./setupHelpers/setupGithubApi'); | ||
const setupErrorHandling = require('./setupHelpers/setupErrorHandling'); | ||
const PrController = require('./controllers/pr'); | ||
const path = require('path'); | ||
|
||
const start = () => { | ||
// Load environment variables from .env file | ||
dotenv.load(); | ||
|
||
const app = express(); | ||
|
||
const githubApi = setupGithubApi(); | ||
|
||
const port = process.env.PORT || 5000; | ||
|
||
app.set('port', port); | ||
app.set('github', githubApi); | ||
|
||
setupErrorHandling(app); | ||
|
||
app.use(express.static(path.join(__dirname, '../build'))); | ||
|
||
app.use(bodyParser.json()); | ||
|
||
const corsOptions = { | ||
origin: process.env.REACT_APP_HOSTNAME | ||
}; | ||
|
||
app.use(cors(corsOptions)); | ||
|
||
app.get('/prs', PrController.index); | ||
|
||
app.get('/*', (req, res) => { | ||
res.sendFile(path.join(__dirname, '../build', 'index.html')); | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log(`Express server listening on port ${port}`); | ||
}); | ||
}; | ||
|
||
module.exports = start; |
Oops, something went wrong.