git ssb

39+

cel / git-ssb



Commit ce32700bb99534de84bce95069bc5daaff7f3d9d

Add authors command

cel committed on 11/22/2016, 1:33:47 AM
Parent: f293f5fc8c88838097689905445366d522ac6f3b

Files changed

lib/index.txtchanged
lib/authors.jsadded
lib/authors.txtadded
lib/index.txtView
@@ -5,8 +5,9 @@
55 fork Fork a git repo on SSB
66 forks List forks of a repo
77 issues List issues for a repo
88 prs List pull requests for a repo
9 + authors List contributors to a repo
910 name Name a repo
1011 pull-request Create a pull-request
1112 web Serve a web server for repos
1213 help Get help about a command
lib/authors.jsView
@@ -1,0 +1,81 @@
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 +function getRepoUpdates(sbot, repoMsg, includeMerged) {
7 + // includeMerged: include updates pushed to downstream (fork) repos
8 + // which are merged into the upstream
9 +
10 + var commitsInUpstream = {}
11 + function gotUpstreamCommit(commit) {
12 + commitsInUpstream[commit.sha1] = true
13 + }
14 + function isCommitInUpstream(commit) {
15 + return commit && commitsInUpstream[commit.sha1]
16 + }
17 +
18 + return pull(
19 + includeMerged ? u.getForks(sbot, repoMsg) : pull.once(repoMsg),
20 + pull.map(function (msg) {
21 + return sbot.links({
22 + dest: msg.key,
23 + rel: 'repo',
24 + values: true,
25 + reverse: true,
26 + })
27 + }),
28 + pull.flatten(),
29 + pull.filter(function (msg) {
30 + var c = msg.value.content
31 + if (c.type !== 'git-update') return false
32 + if (!includeMerged) return true
33 + var commits = Array.isArray(c.commits) ? c.commits : []
34 + // upstream messages come first
35 + if (c.repo === repoMsg.key) {
36 + // keep track of commits in upstream
37 + commits.forEach(gotUpstreamCommit)
38 + return true
39 + } else {
40 + // update to a fork. only include if it was later merged upstream.
41 + return commits.some(isCommitInUpstream)
42 + }
43 + })
44 + )
45 +}
46 +
47 +module.exports = function (argv) {
48 + var repoId = u.getRemote(argv._[0])
49 + if (!repoId) throw 'unable to find git-ssb repo'
50 + var noForks = argv.forks === false || argv.n === true
51 +
52 + u.getSbot(argv, function (err, sbot) {
53 + if (err) throw err
54 + sbot.whoami(function (err, feed) {
55 + if (err) throw err
56 + sbot.get(repoId, function (err, value) {
57 + if (err) throw err
58 + next(sbot, feed.id, {key: repoId, value: value})
59 + })
60 + })
61 + })
62 +
63 + function next(sbot, myId, repoMsg) {
64 + pull(
65 + getRepoUpdates(sbot, repoMsg, !noForks),
66 + pull.unique(function (msg) {
67 + return msg.value.author
68 + }),
69 + paramap(function (msg, cb) {
70 + getAbout(sbot, myId, msg.value.author, function (err, about) {
71 + if (err) return cb(err)
72 + cb(null, `${msg.key} ${msg.value.author} @${about.name}`)
73 + })
74 + }, 8),
75 + pull.log(function (err) {
76 + if (err) throw err
77 + sbot.close()
78 + })
79 + )
80 + }
81 +}
lib/authors.txtView
@@ -1,0 +1,17 @@
1 +Usage: git ssb [--no-forks] authors [<repo>]
2 +
3 + List feeds who pushed to a repo, including those which pushed to
4 + a fork if their commit was later merged into the upstream.
5 +
6 + Output is space separated lines containing information about the
7 + last update by each feed:
8 +
9 + <last update id> <feed id> <feed name>
10 +
11 +Options:
12 + -n --no-forks Only look at updates pushed directly to the repo,
13 + not updates pushed to forks and then merged
14 +
15 +Arguments:
16 + repo id, url, or git remote name of the base repo.
17 + default: 'origin' or 'ssb'

Built with git-ssb-web