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

commit #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "exam",
"version": "1.0.0",
"description": "exam project",
"main": "./source/app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "jiajiangxu",
"license": "ISC",
"dependencies": {
"ect": "^0.5.9",
"express": "^4.12.4",
"octonode": "^0.6.17"
}
}
59 changes: 59 additions & 0 deletions source/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// express
var express = require('express');
var app = express();

// ect
var ect = require('ect')({
watch: true,
root: __dirname + '/views',
ext: '.html'
});

// octonode
var github = require('octonode');

// constant
var PORT = 80;
var REPO = 'joyent/node';

// create ghrepo object
var client = github.client();
var ghrepo = client.repo(REPO);

// initialize app
app.engine('html', ect.render);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');

// middleware
app.use('/public', express.static(__dirname + '/public'));

// //
app.get('/', function (req, res) {
ghrepo.commits(function (err, commits) {
if (err) {
console.log(err);
return;
}
res.render('commits', {title: 'commits', commits: commits});
});
});

// get author
app.get('/authors', function (req, res) {
ghrepo.contributors(function (err, contributors) {
if (err) {
console.log(err);
return;
}
res.render('contributors', {title: 'authors', contributors: contributors});
});
});

app.get('*', function (req, res) {
res.send('404');
})

app.listen(PORT);

console.log('server started at port 80');
27 changes: 27 additions & 0 deletions source/public/css.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
table{
border-collapse:collapse;
}

table td{
border:1px solid #000;
background:#ccc;
padding:3px 10px;
}

.light{
color:#e6f1f6;
}

.nav a{
padding:0 10px;
}

.author{
margin:10px;
}

.author img{
width:45px;
border-radius:4px;
vertical-align:middle;
}
35 changes: 35 additions & 0 deletions source/views/commits.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<% include 'head' %>
</head>
<body>
<% include 'nav' %>
<table>
<!-- thead -->
<thead>
<tr>
<th>sha</th>
<th>author</th>
<th>committer</th>
</tr>
</thead>
<!-- ./thead -->
<!-- tbody -->
<tbody>
<% if @commits?.length : %>
<% for commit in @commits : %>
<tr <% if 0 <= parseInt(commit.sha.substr -1) and parseInt(commit.sha.substr -1) <=9 : %> class="light" <% end %>>
<td><%- commit.sha.substr -6 %></td>
<td><%- commit.commit.author.name %></td>
<td><%- commit.commit.committer.name %></td>
</tr>
<% end %>
<% else : %>
<p>Commit is empty</p>
<% end %>
</tbody>
<!-- ./tbody -->
</table>
</body>
</html>
19 changes: 19 additions & 0 deletions source/views/contributors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<% include 'head' %>
</head>
<body>
<% include 'nav' %>
<% if @contributors?.length : %>
<% for contributor in @contributors : %>
<div class="author">
<img src="<%- contributor.avatar_url %>" alt="<%- contributor.login %>">
<span><%- contributor.login %></span>
</div>
<% end %>
<% else : %>
<p>Commit is empty</p>
<% end %>
</body>
</html>
3 changes: 3 additions & 0 deletions source/views/head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<meta charset="UTF-8">
<title><%- @title %></title>
<link rel="stylesheet" href="/public/css.css">
1 change: 1 addition & 0 deletions source/views/nav.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="nav"><a href="/">all commits</a><a href="/authors">authors</a></div>
12 changes: 12 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var assert = require('assert');
var github = require('octonode');
var client = github.client();
var ghrepo = client.repo('joyent/node');

ghrepo.commits(function (err, commits) {
var lastAlpha = parseInt(commits[2].sha.substr(-1));
var lightColor = !isNaN(lastAlpha) && typeof(lastAlpha) === 'number';


assert.strictEqual(0 <= lastAlpha && lastAlpha <= 9, lightColor);
});