Skip to content

Commit f9b4f4e

Browse files
committed
tms
1 parent 310ecea commit f9b4f4e

File tree

5 files changed

+114
-87
lines changed

5 files changed

+114
-87
lines changed

docker/stage/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
FROM nodezoo-shared
2+
FROM nodezoo-shared:1
33

44
ADD app /app/
55

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ build :
33
mkdir -p app/srv
44
cp -r ../../github.js app
55
cp -r ../../srv/*.js app/srv
6-
docker build -t nodezoo-github .
6+
docker build -t nodezoo-github:1 .
7+
docker build -t nodezoo-github-prod:1 -f Dockerfile-prod .
78

89
clean :
910
rm *~

github.js

Lines changed: 48 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -18,107 +18,70 @@ module.exports = function github ( options ){
1818

1919
seneca.add( 'role:github,cmd:get', cmd_get )
2020
seneca.add( 'role:github,cmd:query', cmd_query )
21-
seneca.add( 'role:github,cmd:parse', cmd_parse )
2221

2322

23+
function cmd_get( msg, reply ) {
24+
this
25+
.make$('github')
26+
.load$( msg.name, function (err, mod) {
27+
if( err ) return reply(err)
2428

25-
function cmd_get( args, done ) {
26-
var seneca = this
27-
var github_ent = seneca.make$('github')
28-
29-
var github_name = args.name
30-
31-
github_ent.load$( github_name, function(err,github_mod){
32-
if( err ) return done(err);
29+
if( mod ) {
30+
return reply(mod)
31+
}
3332

34-
if( github_mod ) {
35-
return done(null,github_mod);
36-
}
37-
else if( args.giturl ) {
38-
seneca.act(
39-
'role:github,cmd:parse',
40-
{name:github_name,giturl:args.giturl},
33+
var m = /[\/:]([^\/:]+?)[\/:]([^\/]+?)(\.git)*$/.exec(msg.giturl)
34+
if (!m) return reply()
4135

42-
function(err,out){
43-
if( err ) return done(err);
4436

45-
seneca.act(
46-
'role:github,cmd:query',
47-
{name:github_name,owner:out.owner,repo:out.repo},
48-
done)
49-
})
50-
}
51-
else return done();
52-
})
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+
})
5347
}
5448

5549

56-
function cmd_query( args, done ) {
50+
function cmd_query( msg, reply ) {
5751
var seneca = this
58-
var github_ent = seneca.make$('github')
59-
60-
var github_name = args.name
61-
var owner = args.owner
62-
var repo = args.repo
63-
64-
65-
/*
66-
gitapi.authenticate({
67-
type: "basic",
68-
username: options.token,
69-
password: 'x-oauth-basic'
70-
})
71-
*/
7252

7353
gitapi.repos.get(
74-
{
75-
owner: owner,
76-
repo: repo
77-
},
54+
{ owner: msg.owner, repo: msg.repo },
7855
function (err, out) {
79-
if( err ) return done(err);
80-
81-
var repo = out.data
82-
83-
var data
84-
if( repo ) {
85-
data = {
86-
owner: args.owner,
87-
repo: args.repo,
88-
stars: repo.stargazers_count,
89-
watches: repo.subscribers_count,
90-
forks: repo.forks_count,
91-
last: repo.pushed_at
92-
}
93-
94-
github_ent.load$(github_name, function(err,github_mod){
95-
if( err ) return done(err);
96-
97-
if( github_mod ) {
98-
return github_mod.data$(data).save$(done);
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)
9976
}
10077
else {
101-
data.id$ = github_name
102-
github_ent.make$(data).save$(done);
78+
data.id$ = msg.name
79+
seneca
80+
.make$('github')
81+
.data$(data)
82+
.save$(reply)
10383
}
10484
})
105-
}
106-
else return done()
107-
108-
}
109-
)
85+
})
11086
}
111-
112-
113-
function cmd_parse( args, done ) {
114-
var seneca = this
115-
116-
var m = /[\/:]([^\/:]+?)[\/:]([^\/]+?)(\.git)*$/.exec(args.giturl)
117-
if( m ) {
118-
return done( null, { owner:m[1], repo:m[2] })
119-
}
120-
else return done();
121-
}
122-
123-
12487
}

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)