diff --git a/package.json b/package.json new file mode 100644 index 0000000..a77a7cf --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/source/app.js b/source/app.js new file mode 100644 index 0000000..6e13ec7 --- /dev/null +++ b/source/app.js @@ -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'); diff --git a/source/public/css.css b/source/public/css.css new file mode 100644 index 0000000..c7ed2cb --- /dev/null +++ b/source/public/css.css @@ -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; +} \ No newline at end of file diff --git a/source/views/commits.html b/source/views/commits.html new file mode 100644 index 0000000..29fc519 --- /dev/null +++ b/source/views/commits.html @@ -0,0 +1,35 @@ + + + + <% include 'head' %> + + + <% include 'nav' %> + + + + + + + + + + + + + <% if @commits?.length : %> + <% for commit in @commits : %> + class="light" <% end %>> + + + + + <% end %> + <% else : %> +

Commit is empty

+ <% end %> + + +
shaauthorcommitter
<%- commit.sha.substr -6 %><%- commit.commit.author.name %><%- commit.commit.committer.name %>
+ + \ No newline at end of file diff --git a/source/views/contributors.html b/source/views/contributors.html new file mode 100644 index 0000000..14bb027 --- /dev/null +++ b/source/views/contributors.html @@ -0,0 +1,19 @@ + + + + <% include 'head' %> + + + <% include 'nav' %> + <% if @contributors?.length : %> + <% for contributor in @contributors : %> +
+ <%- contributor.login %> + <%- contributor.login %> +
+ <% end %> + <% else : %> +

Commit is empty

+ <% end %> + + \ No newline at end of file diff --git a/source/views/head.html b/source/views/head.html new file mode 100644 index 0000000..8f7d385 --- /dev/null +++ b/source/views/head.html @@ -0,0 +1,3 @@ + +<%- @title %> + \ No newline at end of file diff --git a/source/views/nav.html b/source/views/nav.html new file mode 100644 index 0000000..c75bef0 --- /dev/null +++ b/source/views/nav.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..066aab9 --- /dev/null +++ b/test/test.js @@ -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); +});