git ssb

39+

cel / git-ssb



Commit 5a32bb514ba7c50bed24148d4dc1fbd761c13c6e

Add prs/pull-requests command

cel committed on 11/7/2016, 12:22:16 AM
Parent: d2d438a41d60969e657ddf7efd99eeee032c3dde

Files changed

bin.jschanged
lib/issues.jschanged
lib/util.jschanged
lib/pull-requests.jsadded
package.jsonchanged
bin.jsView
@@ -36,8 +36,11 @@
3636 case 'forks':
3737 return require('./lib/forks')(config)
3838 case 'issues':
3939 return require('./lib/issues')(config)
40 + case 'prs':
41 + case 'pull-requests':
42 + return require('./lib/pull-requests')(config)
4043 case 'name':
4144 return nameRepo(config)
4245 case 'pull-request':
4346 return require('./lib/pull-request')(config)
@@ -62,8 +65,9 @@
6265 ' create Create a git repo on SSB',
6366 ' fork Fork a git repo on SSB',
6467 ' forks List forks of a repo',
6568 ' issues List issues for a repo',
69 + ' prs List pull requests for a repo',
6670 ' name Name a repo',
6771 ' pull-request Create a pull-request',
6872 ' web Serve a web server for repos',
6973 ' help Get help about a command')
@@ -120,14 +124,28 @@
120124 '',
121125 ' List issues about a repo',
122126 '',
123127 'Arguments:',
124- ' repo id, url, or git remote name of the base repo.',
128 + ' repo id, url, or git remote name of the repo.',
125129 ' default: \'origin\' or \'ssb\'',
126130 'Options:',
127131 ' --open Show only open issues (default)',
128132 ' --closed Show only closed issues',
129133 ' --all Show issues of all state')
134 + case 'pull-requests':
135 + case 'prs':
136 + return out(
137 + 'Usage: ' + prog + ' prs [--all|--open|--closed] [<repo>]',
138 + '',
139 + ' List pull requests for a repo',
140 + '',
141 + 'Arguments:',
142 + ' repo id, url, or git remote name of the base repo.',
143 + ' default: \'origin\' or \'ssb\'',
144 + 'Options:',
145 + ' --open Show only open pull requests (default)',
146 + ' --closed Show only closed pull-requests',
147 + ' --all Show pull requests of all state')
130148 case 'name':
131149 return out(
132150 'Usage: ' + prog + ' name [<repo>] <name>',
133151 '',
lib/issues.jsView
@@ -3,25 +3,14 @@
33 var u = require('./util')
44 var getAbout = require('ssb-avatar')
55 var Issues = require('ssb-issues')
66
7-function formatTitle(str) {
8- var len = 60
9- str = String(str).replace(/[\n\r\t ]+/g, ' ')
10- if (str.length > len) str = str.substr(0, len) + '…'
11- return str
12-}
13-
147 module.exports = function (argv) {
158 var id = u.repoId(u.getRemoteUrl(argv._[0])) || u.getDefaultRemote()
169 if (!id)
1710 err(1, 'unable to find git-ssb repo')
1811
19- var open =
20- argv.all || (argv.open && argv.closed) ? null :
21- argv.open ? true :
22- argv.closed ? false :
23- true
12 + var open = u.issueStateBool(argv)
2413
2514 u.getSbot(argv, function (err, sbot) {
2615 if (err) throw err
2716 sbot.whoami(function (err, feed) {
@@ -42,9 +31,9 @@
4231 pull.map(function (issue) {
4332 return issue.id + ' ' +
4433 '@' + issue.authorName + ' ' +
4534 (open == null ? issue.open ? 'open: ' : 'closed: ' : '') +
46- formatTitle(issue.text)
35 + u.formatTitle(issue.text, 60)
4736 }),
4837 pull.drain(function (line) {
4938 console.log(line)
5039 }, function (err) {
lib/util.jsView
@@ -94,4 +94,17 @@
9494 cb(err === true ? null : err, name)
9595 })
9696 )
9797 }
98 +
99 +u.formatTitle = function (str, len) {
100 + str = String(str).replace(/[\n\r\t ]+/g, ' ')
101 + if (str.length > len) str = str.substr(0, len) + '…'
102 + return str
103 +}
104 +
105 +u.issueStateBool = function (argv) {
106 + return argv.all || (argv.open && argv.closed) ? null :
107 + argv.open ? true :
108 + argv.closed ? false :
109 + true
110 +}
lib/pull-requests.jsView
@@ -1,0 +1,47 @@
1 +var pull = require('pull-stream')
2 +var paramap = require('pull-paramap')
3 +var u = require('./util')
4 +var getAbout = require('ssb-avatar')
5 +var PRs = require('ssb-pull-requests')
6 +
7 +module.exports = function (argv) {
8 + var headRepo = u.repoId(u.getRemoteUrl(argv._[0])) || u.getDefaultRemote()
9 + if (!headRepo)
10 + err(1, 'unable to find git-ssb head repo')
11 +
12 + var open = u.issueStateBool(argv)
13 +
14 + u.getSbot(argv, function (err, sbot) {
15 + if (err) throw err
16 + sbot.whoami(function (err, feed) {
17 + if (err) throw err
18 + pull(
19 + PRs.init(sbot).list({
20 + repo: headRepo,
21 + open: open
22 + }),
23 + paramap(function (pr, cb) {
24 + getAbout(sbot, feed.id, pr.author, function (err, authorAbout) {
25 + pr.authorName = authorAbout.name
26 + cb(err, pr)
27 + })
28 + }, 8),
29 + pull.map(function (pr) {
30 + var state = pr.open ? 'open' : 'closed'
31 + return state + ' ' + pr.id + ' ' + '@' + pr.authorName + '\n' +
32 + ' ssb://' + pr.headRepo + ':' + pr.headBranch + ' ' +
33 + '→ ' + pr.baseBranch + '\n' +
34 + ' ' + u.formatTitle(pr.text, 77) + '\n'
35 + }),
36 + pull.drain(function (line) {
37 + console.log(line)
38 + }, function (err) {
39 + if (err) throw err
40 + process.exit(0)
41 + })
42 + )
43 + })
44 + })
45 +}
46 +
47 +
package.jsonView
@@ -22,9 +22,9 @@
2222 "ssb-keys": "^6.1.2",
2323 "ssb-issues": "^0.2.3",
2424 "ssb-mentions": "^0.1.0",
2525 "ssb-msg-schemas": "^6.2.1",
26- "ssb-pull-requests": "^0.1.2",
26 + "ssb-pull-requests": "^0.2.3",
2727 "ssb-ref": "^2.6.2",
2828 "stream-to-pull-stream": "^1.7.2"
2929 },
3030 "repository": {

Built with git-ssb-web