git ssb

0+

cel / ssb-pull-requests



Tree: 881fe3c322cf12c7c95d10e256c3c81a20fb989a

Files: 881fe3c322cf12c7c95d10e256c3c81a20fb989a / index.js

1822 bytesRaw
1var pull = require('pull-stream')
2var paramap = require('pull-paramap')
3var asyncMemo = require('asyncmemo')
4var Issues = require('ssb-issues')
5var ssbGit = require('ssb-git-repo')
6
7function readNext(fn) {
8 var next
9 return function (end, cb) {
10 if (next) return next(end, cb)
11 fn(function (err, _next) {
12 if (err) return cb(err)
13 next = _next
14 next(null, cb)
15 })
16 }
17}
18
19module.exports = {
20 name: 'pull-requests',
21 version: '1.0.0',
22 manifest: {
23 get: 'async',
24 list: 'source'
25 },
26 schemas: require('./lib/schemas'),
27 init: function (sbot) {
28
29 var issues = Issues.init(sbot)
30 var getMsg = asyncMemo(sbot.get)
31 var getRepo = asyncMemo(function (id, cb) {
32 getMsg(id, function (err, msg) {
33 if (err) return cb(err)
34 ssbGit.getRepo(sbot, {key: id, value: msg}, {live: true}, cb)
35 })
36 })
37
38 var getPullReq = asyncMemo(function (id, cb) {
39 issues.get(id, function (err, issue) {
40 if (err) return cb(err)
41 var c = issue.msg.value.content
42 issue.baseRepo = c.repo
43 issue.baseBranch = c.branch
44 issue.headRepo = c.head_repo
45 issue.headBranch = c.head_branch
46 cb(null, issue)
47 })
48 })
49
50 function listPullReqs(opts) {
51 opts = opts || {}
52 opts.type = 'pull-request'
53 return pull(
54 sbot.messagesByType(opts),
55 pull.filter(function (msg) {
56 return (!opts.repo || opts.repo == msg.value.content.repo)
57 && (!opts.author || opts.author == msg.value.author)
58 }),
59 paramap(function (msg, cb) {
60 getPullReq(msg.key, cb)
61 }, 8),
62 pull.filter(opts.open != null && function (pr) {
63 return pr.open == opts.open
64 })
65 )
66 }
67
68 return {
69 get: getPullReq,
70 list: listPullReqs
71 }
72 }
73}
74

Built with git-ssb-web