Files: 33cec11948ed393892f4983430f2302067606560 / modules / git.js
2369 bytesRaw
1 | var h = require('hyperscript') |
2 | var pull = require('pull-stream') |
3 | |
4 | var plugs = require('../plugs') |
5 | var message_link = plugs.first(exports.message_link = []) |
6 | var sbot_links = plugs.first(exports.sbot_links = []) |
7 | |
8 | function getIssueState(id, cb) { |
9 | pull( |
10 | sbot_links({dest: id, rel: 'issues', values: true}), |
11 | pull.map(function (msg) { |
12 | var issues = msg.value.content.issues |
13 | if (!Array.isArray(issues)) return |
14 | return issues.filter(function (issue) { |
15 | return issue.link === id |
16 | }).map(function (issue) { |
17 | return { |
18 | ts: msg.value.timestamp, |
19 | open: issue.open, |
20 | merged: issue.merged, |
21 | } |
22 | }) |
23 | }), |
24 | pull.flatten(), |
25 | pull.collect(function (err, updates) { |
26 | if (err) return cb(err) |
27 | var open = true, merged = false |
28 | updates.sort(function (a, b) { |
29 | return b.ts - a.ts |
30 | }).forEach(function (update) { |
31 | if (update.open != null) |
32 | open = update.open |
33 | if (update.merged != null) |
34 | merged = update.merged |
35 | }) |
36 | cb(null, open ? 'open' : merged ? 'merged' : 'closed') |
37 | }) |
38 | ) |
39 | } |
40 | |
41 | exports.message_content = function (msg, sbot) { |
42 | var c = msg.value.content |
43 | |
44 | if(c.type === 'git-repo') { |
45 | return h('p', 'git repo') |
46 | } |
47 | |
48 | if(c.type === 'git-update') { |
49 | return h('p', |
50 | 'git-pushed to ', |
51 | message_link(c.repo), |
52 | c.refs ? h('ul', Object.keys(c.refs).map(function (ref) { |
53 | var rev = c.refs[ref] |
54 | var shortName = ref.replace(/^refs\/(heads|tags)\//, '') |
55 | return h('li', |
56 | shortName + ': ', |
57 | rev ? h('code', rev) : h('em', 'deleted')) |
58 | })) : null, |
59 | Array.isArray(c.issues) ? c.issues.map(function (issue) { |
60 | if (issue.merged === true) |
61 | return ['Merged ', message_link(issue.link), ' in ', |
62 | h('code', issue.object), ' ', h('q', issue.label)] |
63 | if (issue.open === false) |
64 | return ['Closed ', message_link(issue.link), ' in ', |
65 | h('code', issue.object), ' ', h('q', issue.label)] |
66 | }) : null |
67 | ) |
68 | } |
69 | } |
70 | |
71 | exports.message_meta = function (msg, sbot) { |
72 | var type = msg.value.content.type |
73 | if (type == 'issue' || type == 'pull-request') { |
74 | var el = h('em', '...') |
75 | getIssueState(msg.key, function (err, state) { |
76 | if (err) return console.error(err) |
77 | el.textContent = state |
78 | }) |
79 | return el |
80 | } |
81 | } |
82 |
Built with git-ssb-web