Commit e3d280e0a83dd60d5e5880b996b30782d4a68f67
Show git repo refs
Charles Lehner committed on 7/22/2016, 3:26:13 AMParent: 33cec11948ed393892f4983430f2302067606560
Files changed
modules/git.js | changed |
modules/git.js | ||
---|---|---|
@@ -1,11 +1,31 @@ | ||
1 | 1 | var h = require('hyperscript') |
2 | 2 | var pull = require('pull-stream') |
3 | +var paramap = require('pull-paramap') | |
4 | +var moment = require('moment') | |
3 | 5 | |
4 | 6 | var plugs = require('../plugs') |
5 | 7 | var message_link = plugs.first(exports.message_link = []) |
6 | 8 | 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') | |
7 | 12 | |
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 | + | |
8 | 28 | function getIssueState(id, cb) { |
9 | 29 | pull( |
10 | 30 | sbot_links({dest: id, rel: 'issues', values: true}), |
11 | 31 | pull.map(function (msg) { |
@@ -41,20 +61,71 @@ | ||
41 | 61 | exports.message_content = function (msg, sbot) { |
42 | 62 | var c = msg.value.content |
43 | 63 | |
44 | 64 | 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 | |
46 | 118 | } |
47 | 119 | |
48 | 120 | if(c.type === 'git-update') { |
49 | 121 | return h('p', |
50 | - 'git-pushed to ', | |
51 | - message_link(c.repo), | |
122 | + 'pushed to ', | |
123 | + repoLink(c.repo), | |
52 | 124 | c.refs ? h('ul', Object.keys(c.refs).map(function (ref) { |
53 | 125 | var rev = c.refs[ref] |
54 | - var shortName = ref.replace(/^refs\/(heads|tags)\//, '') | |
55 | 126 | return h('li', |
56 | - shortName + ': ', | |
127 | + shortRefName(ref) + ': ', | |
57 | 128 | rev ? h('code', rev) : h('em', 'deleted')) |
58 | 129 | })) : null, |
59 | 130 | Array.isArray(c.issues) ? c.issues.map(function (issue) { |
60 | 131 | if (issue.merged === true) |
Built with git-ssb-web