UNPKG

1.76 kBJavaScriptView Raw
1var pull = require('pull-stream')
2var paramap = require('pull-paramap')
3var u = require('./util')
4var getAbout = require('ssb-avatar')
5
6module.exports = function (argv) {
7 var repoId
8 if (argv.global || argv.g) {
9 if (argv._.length > 0) return require('./help')('log')
10 repoId = null
11 } else {
12 repoId = u.getRemote(argv._[0])
13 if (!repoId) throw 'unable to find git-ssb repo'
14 }
15
16 u.getSbot(argv, function (err, sbot) {
17 if (err) throw err
18 sbot.whoami(function (err, feed) {
19 if (err) throw err
20 pull(
21 sbot.links({
22 dest: repoId,
23 rel: 'repo',
24 values: true,
25 meta: false,
26 reverse: true,
27 }),
28 pull.filter(function (msg) {
29 var c = msg.value.content
30 return c.type === 'git-update'
31 }),
32 // TODO:
33 // - sort by timestamp, or causal order?
34 // - show causal links
35 paramap(function (msg, cb) {
36 getAbout(sbot, feed.id, msg.value.author, function (err, about) {
37 if (err) return cb(err)
38 msg.authorName = '@' + about.name
39 cb(err, msg)
40 })
41 }, 8),
42 pull.map(function (msg) {
43 var c = msg.value.content
44 var commits = Array.isArray(c.commits) ? c.commits : []
45 var numMoreCommits = ~~c.commits_more
46 var date = new Date(msg.value.timestamp)
47 return '' +
48`${msg.key}
49${msg.authorName} ${date.toLocaleString()}
50${commits.map(commit =>
51` + ${String(commit.sha1).substr(0, 8)} ${commit.title||''}
52`).join('')}`
53+ (c.commits_more ?
54` + ${~~c.commits_more} more` : '')
55 }),
56 pull.log(function (err) {
57 if (err) throw err
58 process.exit(0)
59 })
60 )
61 })
62 })
63}