1 | var pull = require('pull-stream')
|
2 | var paramap = require('pull-paramap')
|
3 | var u = require('./util')
|
4 | var getAbout = require('ssb-avatar')
|
5 |
|
6 | exports.help = `
|
7 | Usage: git -p ssb log [--global | <repo>]
|
8 |
|
9 | List history of updates to a repo
|
10 |
|
11 | Options:
|
12 | -g --global Show updates to all repos
|
13 |
|
14 | Arguments:
|
15 | repo id, url, or git remote name of the base repo.
|
16 | default: 'origin' or 'ssb'
|
17 | `
|
18 |
|
19 | exports.fn = function (argv) {
|
20 | var repoId
|
21 | if (argv.global || argv.g) {
|
22 | if (argv._.length > 0) return u.help('log')
|
23 | repoId = null
|
24 | } else {
|
25 | repoId = u.getRemote(argv._[0])
|
26 | if (!repoId) throw 'unable to find git-ssb repo'
|
27 | }
|
28 |
|
29 | u.getSbot(argv, function (err, sbot) {
|
30 | if (err) throw err
|
31 | sbot.whoami(function (err, feed) {
|
32 | if (err) throw err
|
33 | pull(
|
34 | sbot.links({
|
35 | dest: repoId,
|
36 | rel: 'repo',
|
37 | values: true,
|
38 | meta: false,
|
39 | reverse: true,
|
40 | }),
|
41 | pull.filter(function (msg) {
|
42 | var c = msg.value.content
|
43 | return c.type === 'git-update'
|
44 | }),
|
45 |
|
46 |
|
47 |
|
48 | paramap(function (msg, cb) {
|
49 | getAbout(sbot, feed.id, msg.value.author, function (err, about) {
|
50 | if (err) return cb(err)
|
51 | msg.authorName = '@' + about.name
|
52 | cb(err, msg)
|
53 | })
|
54 | }, 8),
|
55 | pull.map(function (msg) {
|
56 | var c = msg.value.content
|
57 | var commits = Array.isArray(c.commits) ? c.commits : []
|
58 | var numMoreCommits = ~~c.commits_more
|
59 | var date = new Date(msg.value.timestamp)
|
60 | return '' +
|
61 | `${msg.key}
|
62 | ${msg.authorName} ${date.toLocaleString()}
|
63 | ${commits.map(commit =>
|
64 | ` + ${String(commit.sha1).substr(0, 8)} ${commit.title||''}
|
65 | `).join('')}`
|
66 | + (c.commits_more ?
|
67 | ` + ${~~c.commits_more} more` : '')
|
68 | }),
|
69 | pull.log(function (err) {
|
70 | if (err) throw err
|
71 | process.exit(0)
|
72 | })
|
73 | )
|
74 | })
|
75 | })
|
76 | }
|