Skip to content

Commit 729f70b

Browse files
committed
github
1 parent 704c1c7 commit 729f70b

5 files changed

Lines changed: 90 additions & 57 deletions

File tree

.dockerignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

Dockerfile

Lines changed: 0 additions & 18 deletions
This file was deleted.

github.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1-
/* Copyright (c) 2014-2015 Richard Rodger, MIT License */
2-
/* jshint node:true, asi:true, eqnull:true */
3-
"use strict";
1+
/* Copyright (c) 2014-2017 Richard Rodger and other contributors, MIT License */
42

53

6-
var GitHubAPI = require('github')
4+
var Github = require('github')
75

8-
var gitapi = new GitHubAPI({
9-
version: "3.0.0"
10-
})
116

127

13-
14-
module.exports = function github( options ){
8+
module.exports = function github ( options ){
159
var seneca = this
1610

1711
options = seneca.util.deepextend({
1812
token: 'GITHUB_TOKEN'
1913
},options)
2014

2115

16+
var gitapi = new Github()
17+
2218

2319
seneca.add( 'role:github,cmd:get', cmd_get )
2420
seneca.add( 'role:github,cmd:query', cmd_query )
@@ -48,7 +44,7 @@ module.exports = function github( options ){
4844

4945
seneca.act(
5046
'role:github,cmd:query',
51-
{name:github_name,user:out.user,repo:out.repo},
47+
{name:github_name,owner:out.owner,repo:out.repo},
5248
done)
5349
})
5450
}
@@ -62,27 +58,32 @@ module.exports = function github( options ){
6258
var github_ent = seneca.make$('github')
6359

6460
var github_name = args.name
65-
var user = args.user
61+
var owner = args.owner
6662
var repo = args.repo
6763

64+
65+
/*
6866
gitapi.authenticate({
6967
type: "basic",
7068
username: options.token,
7169
password: 'x-oauth-basic'
7270
})
71+
*/
7372

7473
gitapi.repos.get(
7574
{
76-
user: user,
75+
owner: owner,
7776
repo: repo
7877
},
79-
function(err,repo){
78+
function (err, out) {
8079
if( err ) return done(err);
8180

81+
var repo = out.data
82+
8283
var data
8384
if( repo ) {
8485
data = {
85-
user: args.user,
86+
owner: args.owner,
8687
repo: args.repo,
8788
stars: repo.stargazers_count,
8889
watches: repo.subscribers_count,
@@ -114,7 +115,7 @@ module.exports = function github( options ){
114115

115116
var m = /[\/:]([^\/:]+?)[\/:]([^\/]+?)(\.git)*$/.exec(args.giturl)
116117
if( m ) {
117-
return done( null, { user:m[1], repo:m[2] })
118+
return done( null, { owner:m[1], repo:m[2] })
118119
}
119120
else return done();
120121
}

package.json

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
{
22
"name": "nodezoo-github",
3-
"version": "5.0.0",
4-
"description": "nodezoo.com micro-service handling github meta data",
3+
"version": "1.0.0-tms-dev",
4+
"description": "nodezoo-github",
55
"main": "github.js",
66
"keywords": [
77
"nodezoo",
88
"seneca",
99
"github",
1010
"microservice"
1111
],
12-
"author": "Richard Rodger (richard.rodger@nearform.com)",
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)",
1320
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/nodezoo/nodezoo-github/issues"
23+
},
24+
"homepage": "https://github.com/nodezoo/nodezoo-github",
25+
1426
"dependencies": {
15-
"github": "^0.2.2",
16-
"seneca-redis-transport": "^0.3.0",
17-
"seneca-level-store": "^0.2.3",
18-
"seneca": "https://github.com/senecajs/seneca",
19-
"seneca-msgstats": "https://github.com/rjrodger/seneca-msgstats",
20-
"seneca-mesh": "https://github.com/rjrodger/seneca-mesh",
21-
"seneca-balance-client": "https://github.com/rjrodger/seneca-balance-client"
27+
"github": "9.2.0",
28+
"seneca": "3.3.0",
29+
"seneca-entity": "2.0.0",
30+
"seneca-jsonfile-store": "1.0.0",
31+
"seneca-redis-transport": "0.3.0",
32+
"seneca-repl": "1.0.0"
33+
},
34+
"devDependencies": {
35+
"code": "4.0.0",
36+
"lab": "13.0.1"
2237
}
2338
}

srv/github-dev.js

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
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
16

2-
var HOST = process.env.HOST || 'localhost'
37
var TOKEN = process.env.TOKEN || 'NO_TOKEN'
48

5-
require('seneca')()
69

7-
.use('redis-transport')
8-
.use('level-store')
10+
var Seneca = require('seneca')
11+
12+
13+
Seneca({tag: 'github'})
14+
.test('print')
915

10-
.use('../github.js',{token:TOKEN})
16+
.use('entity')
17+
.use('jsonfile-store', {folder: __dirname+'/data'})
1118

12-
.add('role:info,req:part',function(args,done){
19+
.use('..',{token:TOKEN})
20+
21+
.add('role:info,need:part',function(args,done){
1322
done()
1423

1524
this.act(
@@ -21,8 +30,8 @@ require('seneca')()
2130

2231
if( mod ) {
2332
return this.act(
24-
'role:info,res:part,part:github',
25-
{name:args.name,data:mod.data$()})
33+
'role:info,collect:part,part:github',
34+
{name:args.name,data:this.util.clean(mod.data$())})
2635
}
2736

2837
this.act(
@@ -38,16 +47,43 @@ require('seneca')()
3847
if( err ) return;
3948

4049
if( mod ) {
41-
this.act('role:info,res:part,part:github',
42-
{name:args.name,data:mod.data$()})
50+
this.act('role:info,collect:part,part:github',
51+
{name:args.name,data:this.util.clean(mod.data$())})
4352
}
4453
})
4554
}
4655
})
4756
})
4857
})
4958

50-
.use( 'mesh',
51-
{auto:true, pins:['role:github','role:info,req:part'], model:'publish'} )
5259

53-
.repl(33004)
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+
}

0 commit comments

Comments
 (0)