git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 17a07cae56f9526af24d72a4feda4e99d29e71ea

Files: 17a07cae56f9526af24d72a4feda4e99d29e71ea / plugs / message / html / render / git.js

1171 bytesRaw
1var {h, when} = require('mutant')
2var nest = require('depnest')
3var extend = require('xtend')
4
5exports.needs = nest({
6 'message.html': {
7 decorate: 'reduce',
8 layout: 'first',
9 link: 'first',
10 markdown: 'first'
11 }
12})
13
14exports.gives = nest('message.html.render')
15
16exports.create = function (api) {
17 return nest('message.html.render', function renderMessage (msg, opts) {
18 if (msg.value.content.type !== 'git-update') return
19 var element = api.message.html.layout(msg, extend({
20 content: messageContent(msg),
21 layout: 'mini'
22 }, opts))
23
24 return api.message.html.decorate(element, { msg })
25 })
26
27 function messageContent (msg) {
28 var commits = msg.value.content.commits || []
29 return [
30 h('a', {href: msg.key, title: commitSummary(commits)}, [
31 'pushed',
32 when(commits, [' ', pluralizeCommits(commits)])
33 ]),
34 ' to ',
35 api.message.html.link(msg.value.content.repo)
36 ]
37 }
38}
39
40function pluralizeCommits (commits) {
41 return when(commits.length === 1, '1 commit', `${commits.length} commits`)
42}
43
44function commitSummary (commits) {
45 return commits.map(commit => `- ${commit.title}`).join('\n')
46}
47

Built with git-ssb-web