git ssb

0+

ev / microbay



forked from Dominic / patchbay

Commit e3d280e0a83dd60d5e5880b996b30782d4a68f67

Show git repo refs

Charles Lehner committed on 7/22/2016, 3:26:13 AM
Parent: 33cec11948ed393892f4983430f2302067606560

Files changed

modules/git.jschanged
modules/git.jsView
@@ -1,11 +1,31 @@
11 var h = require('hyperscript')
22 var pull = require('pull-stream')
3+var paramap = require('pull-paramap')
4+var moment = require('moment')
35
46 var plugs = require('../plugs')
57 var message_link = plugs.first(exports.message_link = [])
68 var sbot_links = plugs.first(exports.sbot_links = [])
9+var sbot_links2 = plugs.first(exports.sbot_links2 = [])
10+var sbot_get = plugs.first(exports.sbot_get = [])
11+var getAvatar = require('ssb-avatar')
712
13+var self_id = require('../keys').id
14+
15+function shortRefName(ref) {
16+ return ref.replace(/^refs\/(heads|tags)\//, '')
17+}
18+
19+function repoLink(id) {
20+ var el = h('a', {href: '#'+id}, id.substr(0, 10) + '…')
21+ getAvatar({links: sbot_links}, self_id, id, function (err, avatar) {
22+ if(err) return console.error(err)
23+ el.textContent = avatar.name
24+ })
25+ return el
26+}
27+
828 function getIssueState(id, cb) {
929 pull(
1030 sbot_links({dest: id, rel: 'issues', values: true}),
1131 pull.map(function (msg) {
@@ -41,20 +61,71 @@
4161 exports.message_content = function (msg, sbot) {
4262 var c = msg.value.content
4363
4464 if(c.type === 'git-repo') {
45- return h('p', 'git repo')
65+ var nameEl, refsTable
66+ var div = h('div',
67+ h('p', 'git repo ', nameEl = h('ins')),
68+ h('p', h('code', 'ssb://' + msg.key)),
69+ refsTable = h('table')
70+ )
71+
72+ // show repo name
73+ getAvatar({links: sbot_links}, self_id, msg.key, function (err, avatar) {
74+ if(err) return console.error(err)
75+ nameEl.textContent = avatar.name
76+ })
77+
78+ // compute refs
79+ var refs = {}
80+ var first = true
81+ pull(
82+ sbot_links({
83+ reverse: true,
84+ source: msg.value.author,
85+ dest: msg.key,
86+ rel: 'repo',
87+ values: true
88+ }),
89+ pull.drain(function (link) {
90+ var refUpdates = link.value.content.refs
91+ if (first) {
92+ first = false
93+ refsTable.appendChild(h('tr',
94+ h('th', 'branch'),
95+ h('th', 'commit'),
96+ h('th', 'last update')))
97+ }
98+ for (var ref in refUpdates) {
99+ if (refs[ref]) continue
100+ refs[ref] = true
101+ var rev = refUpdates[ref]
102+ var m = moment(link.value.timestamp)
103+ refsTable.appendChild(h('tr',
104+ h('td', shortRefName(ref)),
105+ h('td', h('code', rev)),
106+ h('td', h('a.timestamp', {
107+ timestamp: m,
108+ title: m.format('LLLL'),
109+ href: '#'+link.key
110+ }, m.fromNow()))))
111+ }
112+ }, function (err) {
113+ if (err) console.error(err)
114+ })
115+ )
116+
117+ return div
46118 }
47119
48120 if(c.type === 'git-update') {
49121 return h('p',
50- 'git-pushed to ',
51- message_link(c.repo),
122+ 'pushed to ',
123+ repoLink(c.repo),
52124 c.refs ? h('ul', Object.keys(c.refs).map(function (ref) {
53125 var rev = c.refs[ref]
54- var shortName = ref.replace(/^refs\/(heads|tags)\//, '')
55126 return h('li',
56- shortName + ': ',
127+ shortRefName(ref) + ': ',
57128 rev ? h('code', rev) : h('em', 'deleted'))
58129 })) : null,
59130 Array.isArray(c.issues) ? c.issues.map(function (issue) {
60131 if (issue.merged === true)

Built with git-ssb-web