Skip to content
Open
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
13 changes: 13 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Code challenge by Eric Freed Nov 15, 2021

In response to the user story:

"As the engineering manager, I want to be able to visit a web page to view who has contributed the most to our application's repository in the past month, so that I may better plan the upcoming sprint."

## Instructions to run

- This assumes you have Node installed. If unsure, run `npm -v` and if you see a version number, you are good to go.
- Using the console, navigate to the /source/frontend folder using `cd source/frontend`
- Run `npm install && npm start`
- Your browser will automatically open to `http://localhost:3000` with the report loaded

10 changes: 10 additions & 0 deletions source/backend/detail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
$url = 'https://github.com/nodejs/node/pulse_committer_data/monthly';

header('Content-Type: application/json');

echo file_get_contents($url, false, stream_context_create([
'http' => [
'header' => 'accept: application/json'
]
]));
5 changes: 5 additions & 0 deletions source/backend/summary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
$url = 'https://github.com/nodejs/node/pulse_diffstat_summary?period=monthly';

// Display sentences on their own line
echo preg_replace('/\.\s/i', ".\n<br>", file_get_contents($url) );
23 changes: 23 additions & 0 deletions source/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
16,323 changes: 16,323 additions & 0 deletions source/frontend/package-lock.json

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions source/frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "my-react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.0.1"
},
"scripts": {
"start": "npm-run-all --parallel start-frontend start-backend",
"start-backend": "cd ../backend && php -S 127.0.0.1:8080",
"start-frontend": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"http-proxy-middleware": "^2.0.1",
"npm-run-all": "^4.1.5"
}
}
Binary file added source/frontend/public/favicon.ico
Binary file not shown.
43 changes: 43 additions & 0 deletions source/frontend/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
3 changes: 3 additions & 0 deletions source/frontend/public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
56 changes: 56 additions & 0 deletions source/frontend/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

body {
background-color: #282c34;
color: white;
}

h1, .summary {
text-align: center;
}

h1 {
margin: 0;
padding: 0.67em 0;
color: rgb(118,131,144);
letter-spacing: 1px;
border-bottom: 2px solid black;
font-style: italic;
}

.summary .color-fg-muted, .summary .color-fg-muted a {
color: rgb(118,131,144);
}
.summary .color-fg-muted a {
text-decoration: none;
}
.summary .color-fg-default {
color: white;
}
.summary .color-fg-success {
color: rgb(87,171,90);
}
.summary .color-fg-danger {
color: rgb(229,83,75);
}

.contributors img {
height: 60px;
width: 60px;
float: left;
clear: left;
margin: 5px 20px;
}
.contributors .summary-bar {
height: 70px;
line-height: 70px;
position: relative;
}

.contributors .summary-bar .background-bar {
position: absolute;
top: 5px;
bottom: 5px;
left: 90px;
background-color: rgb(77,56,47);
z-index: -1;
}
51 changes: 51 additions & 0 deletions source/frontend/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { useState, useEffect } from 'react';
import './App.css';

function App() {
const [summary, setSummary] = useState("loading...");
const [contributors, setContributors] = useState();
const [errors, setErrors] = useState([]);
const longestBarPct = 85;

useEffect(() => {
fetch("api/summary.php")
.then(res => res.text()).then(setSummary)
.catch(err => setErrors([...errors,err]))
fetch("api/detail.php")
.then(res => res.json()).then(setContributors)
.catch(err => setErrors([...errors,err]))
}, [errors])

return (
<div className="App">
<h1>This month's github activity</h1>
<h2 className="summary" dangerouslySetInnerHTML={{__html: summary}}></h2>
{errors.length ?
<div className="errors">
{errors.map((error, index) => (
<div key={index}>
{ JSON.stringify(error) }
</div>
))}
</div>
:null}
{contributors ?
<div className="contributors">
{contributors.map((contributor, index) => (
<div key={index}>
<img src={contributor.gravatar} alt="User's Avatar" />
<div className="summary-bar">
<div className="background-bar"
style={{width:`${contributor.commits * longestBarPct / contributors[0].commits}%`}} />
<strong>{contributor.name}</strong> authored <strong>{contributor.commits}</strong>
{` commit${contributor.commits===1 ? '' : 's'}`}
</div>
</div>
))}
</div>
:null}
</div>
);
}

export default App;
4 changes: 4 additions & 0 deletions source/frontend/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
html, body {
margin: 0;
height: 100%;
}
17 changes: 17 additions & 0 deletions source/frontend/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
13 changes: 13 additions & 0 deletions source/frontend/src/reportWebVitals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};

export default reportWebVitals;
13 changes: 13 additions & 0 deletions source/frontend/src/setupProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const {createProxyMiddleware} = require('http-proxy-middleware');

module.exports = app => {
app.use(
createProxyMiddleware('/api/', {
target: 'http://localhost:8080',
secure: false,
pathRewrite: {
'^/api/': '/'
},
}),
);
};
5 changes: 5 additions & 0 deletions source/frontend/src/setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';