git ssb

0+

cel / ssb-pull-requests



Tree: 30f7bd681ac5b899c8aa17d0072e9f39107cccaa

Files: 30f7bd681ac5b899c8aa17d0072e9f39107cccaa / index.js

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

Built with git-ssb-web