Skip to content

Commit f8a0d78

Browse files
committed
v1.0.0
2 parents fcb20a7 + 8bedeef commit f8a0d78

File tree

12 files changed

+490
-5
lines changed

12 files changed

+490
-5
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ MANIFEST-*
3636

3737
srv/data*
3838

39-
.ignore*
39+
.ignore*
40+
41+
42+
docker/stage/app

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
sudo: required
12
language: node_js
2-
sudo: false
3+
dist: trusty
34

45
node_js:
5-
- "4"
6-
- "5"
7-
6+
- '4'
7+
- '6'
8+
- '8'

docker/stage/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
FROM nodezoo-shared:1
3+
4+
ADD app /app/
5+
6+
CMD ["node", "/app/srv/github-stage.js"]
7+
8+
9+
10+
11+

docker/stage/Dockerfile-prod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
FROM nodezoo-github:1
3+
4+
CMD ["node", "/app/srv/github-prod.js"]
5+
6+
7+
8+
9+

docker/stage/Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
build :
2+
mkdir -p app/data
3+
mkdir -p app/srv
4+
cp -r ../../github.js app
5+
cp -r ../../srv/*.js app/srv
6+
docker build -t nodezoo-github:1 .
7+
docker build -t nodezoo-github-prod:1 -f Dockerfile-prod .
8+
9+
clean :
10+
rm *~
11+
12+
.PHONY : build clean

github.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* Copyright (c) 2014-2017 Richard Rodger and other contributors, MIT License */
2+
3+
4+
var Github = require('github')
5+
6+
7+
8+
module.exports = function github ( options ){
9+
var seneca = this
10+
11+
options = seneca.util.deepextend({
12+
token: 'GITHUB_TOKEN'
13+
},options)
14+
15+
16+
var gitapi = new Github()
17+
18+
19+
seneca.add( 'role:github,cmd:get', cmd_get )
20+
seneca.add( 'role:github,cmd:query', cmd_query )
21+
22+
23+
function cmd_get( msg, reply ) {
24+
this
25+
.make$('github')
26+
.load$( msg.name, function (err, mod) {
27+
if( err ) return reply(err)
28+
29+
if( mod ) {
30+
return reply(mod)
31+
}
32+
33+
var m = /[\/:]([^\/:]+?)[\/:]([^\/]+?)(\.git)*$/.exec(msg.giturl)
34+
if (!m) return reply()
35+
36+
37+
this.act(
38+
{
39+
role: 'github',
40+
cmd: 'query',
41+
name: msg.name,
42+
owner: m[1],
43+
repo: m[2]
44+
},
45+
reply)
46+
})
47+
}
48+
49+
50+
function cmd_query( msg, reply ) {
51+
var seneca = this
52+
53+
gitapi.repos.get(
54+
{ owner: msg.owner, repo: msg.repo },
55+
function (err, out) {
56+
if (err) return reply(err)
57+
58+
var data = {
59+
owner: msg.owner,
60+
repo: msg.repo,
61+
stars: out.data.stargazers_count,
62+
watches: out.data.subscribers_count,
63+
forks: out.data.forks_count,
64+
last: out.data.pushed_at
65+
}
66+
67+
seneca
68+
.make$('github')
69+
.load$(msg.name, function (err, mod) {
70+
if (err) return reply(err)
71+
72+
if (mod) {
73+
return mod
74+
.data$(data)
75+
.save$(reply)
76+
}
77+
else {
78+
data.id$ = msg.name
79+
seneca
80+
.make$('github')
81+
.data$(data)
82+
.save$(reply)
83+
}
84+
})
85+
})
86+
}
87+
}

package.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "nodezoo-github",
3+
"version": "1.0.0",
4+
"description": "nodezoo-github",
5+
"main": "github.js",
6+
"keywords": [
7+
"nodezoo",
8+
"seneca",
9+
"github",
10+
"microservice"
11+
],
12+
"scripts": {
13+
"test": "lab -P test"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/nodezoo/nodezoo-github.git"
18+
},
19+
"author": "Richard Rodger (http://richardrodger.com)",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/nodezoo/nodezoo-github/issues"
23+
},
24+
"homepage": "https://github.com/nodezoo/nodezoo-github",
25+
26+
"dependencies": {
27+
"github": "9.2.0",
28+
"seneca": "3.4.2",
29+
"seneca-balance-client": "0.6.1",
30+
"seneca-monitor": "0.1.0",
31+
"seneca-mesh": "0.11.0",
32+
"seneca-entity": "2.0.2",
33+
"seneca-jsonfile-store": "1.0.0",
34+
"seneca-redis-transport": "0.3.0",
35+
"seneca-repl": "1.1.2"
36+
},
37+
"devDependencies": {
38+
"code": "4.1.x",
39+
"lab": "14.0.x"
40+
}
41+
}

srv/github-dev-mesh.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Copyright (c) 2014-2017 Richard Rodger and other contributors, MIT License */
2+
3+
var Seneca = require('seneca')
4+
5+
Seneca({tag: 'github'})
6+
.test()
7+
.use('monitor')
8+
9+
.use('entity')
10+
.use('jsonfile-store', {folder: __dirname+'/../data'})
11+
12+
.use('../github.js')
13+
14+
.use('mesh', {
15+
listen: [
16+
{pin: 'role:github'},
17+
{pin: 'role:info,need:part', model:'observe'}
18+
]
19+
})
20+
21+
.add('role:info,need:part', function (msg, reply) {
22+
reply()
23+
24+
this.act(
25+
'role:github,cmd:get', {name:msg.name},
26+
function (err, mod) {
27+
if (err) return
28+
29+
if (mod) {
30+
return this.act('role:info,collect:part,part:github',
31+
{name:msg.name,data:this.util.clean(mod.data$())})
32+
}
33+
34+
this.act(
35+
'role:npm,cmd:get', {name:msg.name},
36+
function (err, mod) {
37+
if (err) return
38+
39+
if (mod) {
40+
this.act(
41+
'role:github,cmd:get', {name:msg.name, giturl:mod.giturl},
42+
function( err, mod ){
43+
if( err ) return
44+
45+
if( mod ) {
46+
this.act('role:info,collect:part,part:github',
47+
{name:msg.name,data:this.util.clean(mod.data$())})
48+
}
49+
})
50+
}
51+
})
52+
})
53+
})
54+

srv/github-dev.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* Copyright (c) 2014-2017 Richard Rodger and other contributors, MIT License */
2+
3+
var MOCK_NPM = JSON.parse(process.env.MOCK_NPM || 'false')
4+
var MOCK_INFO = JSON.parse(process.env.MOCK_INFO || 'false')
5+
var MOCK = MOCK_NPM || MOCK_INFO
6+
7+
var TOKEN = process.env.TOKEN || 'NO_TOKEN'
8+
9+
10+
var Seneca = require('seneca')
11+
12+
13+
Seneca({tag: 'github'})
14+
.test('print')
15+
16+
.use('entity')
17+
.use('jsonfile-store', {folder: __dirname+'/data'})
18+
19+
.use('..',{token:TOKEN})
20+
21+
.add('role:info,need:part',function(args,done){
22+
done()
23+
24+
this.act(
25+
'role:github,cmd:get',
26+
{name:args.name},
27+
28+
function(err,mod){
29+
if( err ) return;
30+
31+
if( mod ) {
32+
return this.act(
33+
'role:info,collect:part,part:github',
34+
{name:args.name,data:this.util.clean(mod.data$())})
35+
}
36+
37+
this.act(
38+
'role:npm,cmd:get', {name:args.name},
39+
function(err,mod){
40+
if( err ) return;
41+
42+
if( mod ) {
43+
this.act(
44+
'role:github,cmd:get',
45+
{name:args.name,giturl:mod.giturl},
46+
function( err, mod ){
47+
if( err ) return;
48+
49+
if( mod ) {
50+
this.act('role:info,collect:part,part:github',
51+
{name:args.name,data:this.util.clean(mod.data$())})
52+
}
53+
})
54+
}
55+
})
56+
})
57+
})
58+
59+
60+
.use('seneca-repl', {port:10050})
61+
62+
.listen(9050)
63+
64+
.client({pin:'role:info', port:9030})
65+
.client({pin:'role:npm', port:9040})
66+
67+
68+
// Run mock services that this service depends on.
69+
if (MOCK) {
70+
var mock = Seneca({tag:'mock'})
71+
.test('print')
72+
.use('entity')
73+
74+
if (MOCK_NPM) {
75+
mock
76+
.listen(9040)
77+
.add('role:npm', function (msg, reply) {
78+
reply({"entity$":{"name":"npm"},"name":"jsonic","version":"0.2.2","giturl":"git://github.com/rjrodger/jsonic.git","desc":"JSON parser that isn't strict","readme":"","id":"jsonic"})
79+
})
80+
}
81+
82+
if (MOCK_INFO) {
83+
mock
84+
.listen(9030)
85+
.add('role:info', function (msg, reply) {
86+
reply()
87+
})
88+
}
89+
}

srv/github-prod.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Copyright (c) 2014-2017 Richard Rodger and other contributors, MIT License */
2+
3+
var BASES = process.env.BASES.split(',')
4+
5+
var Seneca = require('seneca')
6+
7+
Seneca({tag: 'github'})
8+
.use('entity')
9+
.use('jsonfile-store', {folder: __dirname+'/../data'})
10+
11+
.use('../github.js')
12+
13+
.add('role:info,need:part', function (msg, reply) {
14+
reply()
15+
16+
this.act(
17+
'role:github,cmd:get', {name:msg.name},
18+
function (err, mod) {
19+
if (err) return
20+
21+
if (mod) {
22+
return this.act('role:info,collect:part,part:github',
23+
{name:msg.name,data:this.util.clean(mod.data$())})
24+
}
25+
26+
this.act(
27+
'role:npm,cmd:get', {name:msg.name},
28+
function (err, mod) {
29+
if (err) return
30+
31+
if (mod) {
32+
this.act(
33+
'role:github,cmd:get', {name:msg.name, giturl:mod.giturl},
34+
function( err, mod ){
35+
if( err ) return
36+
37+
if( mod ) {
38+
this.act('role:info,collect:part,part:github',
39+
{name:msg.name,data:this.util.clean(mod.data$())})
40+
}
41+
})
42+
}
43+
})
44+
})
45+
})
46+
47+
.use('mesh', {
48+
listen: [
49+
{pin: 'role:github'},
50+
{pin: 'role:info,need:part', model:'observe'}
51+
],
52+
bases: BASES,
53+
host: '@eth0',
54+
})

0 commit comments

Comments
 (0)