git ssb

39+

cel / git-ssb



Tree: 28bf61d928af584e5e33b424fc41deafa9dddb77

Files: 28bf61d928af584e5e33b424fc41deafa9dddb77 / lib / authors.js

2912 bytesRaw
1var pull = require('pull-stream')
2var paramap = require('pull-paramap')
3var u = require('./util')
4var getAbout = require('ssb-avatar')
5
6exports.help = `
7Usage: git ssb [--no-forks] authors [<repo>]
8
9 List feeds who pushed to a repo, including those which pushed to
10 a fork if their commit was later merged into the upstream.
11
12 Output is space separated lines containing information about the
13 last update by each feed:
14
15 <last update id> <feed id> <feed name>
16
17Options:
18 -n --no-forks Only look at updates pushed directly to the repo,
19 not updates pushed to forks and then merged
20
21Arguments:
22 repo id, url, or git remote name of the base repo.
23 default: 'origin' or 'ssb'
24`
25
26function getRepoUpdates(sbot, repoMsg, includeMerged) {
27 // includeMerged: include updates pushed to downstream (fork) repos
28 // which are merged into the upstream
29
30 var commitsInUpstream = {}
31 function gotUpstreamCommit(commit) {
32 commitsInUpstream[commit.sha1] = true
33 }
34 function isCommitInUpstream(commit) {
35 return commit && commitsInUpstream[commit.sha1]
36 }
37
38 return pull(
39 includeMerged ? u.getForks(sbot, repoMsg) : pull.once(repoMsg),
40 pull.map(function (msg) {
41 return u.gitUpdates(sbot, msg.key)
42 }),
43 pull.flatten(),
44 paramap(u.unboxMessages(sbot), 4),
45 pull.filter(function (msg) {
46 var c = msg.value.content
47 if (c.type !== 'git-update') return false
48 if (!includeMerged) return true
49 var commits = Array.isArray(c.commits) ? c.commits : []
50 // upstream messages come first
51 if (c.repo === repoMsg.key) {
52 // keep track of commits in upstream
53 commits.forEach(gotUpstreamCommit)
54 return true
55 } else {
56 // update to a fork. only include if it was later merged upstream.
57 return commits.some(isCommitInUpstream)
58 }
59 })
60 )
61}
62
63exports.fn = function (argv) {
64 var repoId = u.getRemote(argv._[0])
65 if (!repoId) throw 'unable to find git-ssb repo'
66 var noForks = argv.forks === false || argv.n === true
67
68 u.getSbot(argv, function (err, sbot) {
69 if (err) throw err
70 sbot.whoami(function (err, feed) {
71 if (err) throw err
72 if (repoId[0] === '#') next(sbot, feed.id, {key: repoId})
73 else sbot.get(repoId, function (err, value) {
74 if (err) throw err
75 next(sbot, feed.id, {key: repoId, value: value})
76 })
77 })
78 })
79
80 function next(sbot, myId, repoMsg) {
81 pull(
82 getRepoUpdates(sbot, repoMsg, !noForks),
83 pull.unique(function (msg) {
84 return msg.value.author
85 }),
86 paramap(function (msg, cb) {
87 getAbout(sbot, myId, msg.value.author, function (err, about) {
88 if (err) return cb(err)
89 cb(null, `${msg.key} ${msg.value.author} @${about.name}`)
90 })
91 }, 8),
92 pull.log(function (err) {
93 if (err) throw err
94 sbot.close()
95 })
96 )
97 }
98}
99

Built with git-ssb-web