git ssb

0+

ev / microbay



forked from Dominic / patchbay

Commit 33cec11948ed393892f4983430f2302067606560

Render git repos, updates, and issues

Charles Lehner committed on 7/22/2016, 12:30:47 AM
Parent: d7fb1beb9f31e8ab0941912ef07d1b4a1eda6fc5

Files changed

modules/index.jschanged
modules/git.jsadded
modules/index.jsView
@@ -10,8 +10,9 @@
1010 "crypto.js": require('./crypto.js'),
1111 "feed.js": require('./feed.js'),
1212 "file-input.js": require('./file-input.js'),
1313 "follow.js": require('./follow.js'),
14+ "git.js": require('./git.js'),
1415 "invite.js": require('./invite.js'),
1516 "like.js": require('./like.js'),
1617 "markdown.js": require('./markdown.js'),
1718 "message-confirm.js": require('./message-confirm.js'),
modules/git.jsView
@@ -1,0 +1,81 @@
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+}

Built with git-ssb-web