Commit 881fe3c322cf12c7c95d10e256c3c81a20fb989a
Initial commit
Charles Lehner committed on 4/11/2016, 3:01:01 AMFiles changed
README.md | added |
index.js | added |
lib/schemas.js | added |
package.json | added |
README.md | ||
---|---|---|
@@ -1,0 +1,114 @@ | ||
1 … | +# ssb-pull-requests | |
2 … | + | |
3 … | +Pull requests for git-ssb repos | |
4 … | + | |
5 … | +## API | |
6 … | + | |
7 … | +``` | |
8 … | +var Pulls = require('ssb-pull-requests') | |
9 … | +var pulls = Pulls.init(sbot) | |
10 … | +``` | |
11 … | + | |
12 … | +#### get: async | |
13 … | + | |
14 … | +Get a pull request by its id | |
15 … | + | |
16 … | +```js | |
17 … | +pulls.get(id, cb) | |
18 … | +``` | |
19 … | + | |
20 … | +→ | |
21 … | +```js | |
22 … | +{ | |
23 … | + id: Ref, | |
24 … | + created_at: timestamp, | |
25 … | + headRepo: Ref, | |
26 … | + headBranch: string, | |
27 … | + baseRepo: Ref, | |
28 … | + baseBranch: string, | |
29 … | + title: string?, | |
30 … | + text: string?, | |
31 … | + open: boolean, | |
32 … | + mergeable: boolean? | |
33 … | +} | |
34 … | +``` | |
35 … | + | |
36 … | +- `mergeable`: whether the pull request can be automatically merged (`true`), | |
37 … | + or not (`false`), or it is unknown (`null`) | |
38 … | + | |
39 … | +#### list: source | |
40 … | + | |
41 … | +Get a stream of pull requests | |
42 … | + | |
43 … | +```js | |
44 … | +issues.list({ repo:, open:, author:, live:, gt:, gte:, lt:, lte:, reverse: }) | |
45 … | +``` | |
46 … | + | |
47 … | +- `repo` (Ref): filter by base git-ssb repo | |
48 … | +- `open` (boolean): filter by open/closed status | |
49 … | +- `author` (FeedRef): get only pull requests created by the given feed | |
50 … | +- `live` (boolean, default: `false`): Keep the stream open and emit new messages as they are received. | |
51 … | +- `gt` (greater than), `gte` (greater than or equal): maximum `[timestamp, id]` | |
52 … | +- `lt` (less than), `lte` (less than or equal): minimum `[timestamp, id]` | |
53 … | +- `reverse` (boolean, default: `false`): reverse the order of results | |
54 … | + | |
55 … | +→ | |
56 … | +```js | |
57 … | +{ | |
58 … | + id: Ref, | |
59 … | + created_at: timestamp, | |
60 … | + repo: Ref, | |
61 … | + branch: string, | |
62 … | + head_repo: Ref, | |
63 … | + head_branch: string, | |
64 … | + title: string?, | |
65 … | + text: string?, | |
66 … | + open: boolean, | |
67 … | + mergeable: boolean?, | |
68 … | +} | |
69 … | +``` | |
70 … | + | |
71 … | +- `mergeable`: whether the pull request can be automatically merged | |
72 … | + | |
73 … | +## Schemas | |
74 … | + | |
75 … | +```js | |
76 … | +var prSchemas = Pulls.schemas | |
77 … | +``` | |
78 … | + | |
79 … | +#### `prSchemas.new(baseRepo, baseBranch, headRepo, headBranch, title, text)` | |
80 … | + | |
81 … | +Create a pull request. A pull request is a request to pull from a branch of one | |
82 … | +git-ssb repo (head), to a branch on another git-ssb repo (base). | |
83 … | + | |
84 … | +- `baseRepo` (Ref): repo to request changes pulled into | |
85 … | +- `baseBranch` (string): branch of the repo to request changes pulled into | |
86 … | +- `headRepo` (Ref): repo where the changes are implemented | |
87 … | +- `headBranch` (string): branch of the repo to pull from | |
88 … | +- `title` (string): title of the pull request | |
89 … | +- `text` (string): text describing the pull request | |
90 … | + | |
91 … | +→ | |
92 … | + | |
93 … | +```js | |
94 … | +{ | |
95 … | + type: 'pull-request', | |
96 … | + project: Ref, | |
97 … | + repo: Ref, | |
98 … | + branch: string, | |
99 … | + base_repo: Ref, | |
100 … | + base_branch: string, | |
101 … | + title: string?, | |
102 … | + text: string? | |
103 … | +} | |
104 … | +``` | |
105 … | + | |
106 … | +## License | |
107 … | + | |
108 … | +Copyright (c) 2016 Charles Lehner | |
109 … | + | |
110 … | +Usage of the works is permitted provided that this instrument is | |
111 … | +retained with the works, so that any entity that uses the works is | |
112 … | +notified of this instrument. | |
113 … | + | |
114 … | +DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY. |
index.js | ||
---|---|---|
@@ -1,0 +1,73 @@ | ||
1 … | +var pull = require('pull-stream') | |
2 … | +var paramap = require('pull-paramap') | |
3 … | +var asyncMemo = require('asyncmemo') | |
4 … | +var Issues = require('ssb-issues') | |
5 … | +var ssbGit = require('ssb-git-repo') | |
6 … | + | |
7 … | +function readNext(fn) { | |
8 … | + var next | |
9 … | + return function (end, cb) { | |
10 … | + if (next) return next(end, cb) | |
11 … | + fn(function (err, _next) { | |
12 … | + if (err) return cb(err) | |
13 … | + next = _next | |
14 … | + next(null, cb) | |
15 … | + }) | |
16 … | + } | |
17 … | +} | |
18 … | + | |
19 … | +module.exports = { | |
20 … | + name: 'pull-requests', | |
21 … | + version: '1.0.0', | |
22 … | + manifest: { | |
23 … | + get: 'async', | |
24 … | + list: 'source' | |
25 … | + }, | |
26 … | + schemas: require('./lib/schemas'), | |
27 … | + init: function (sbot) { | |
28 … | + | |
29 … | + var issues = Issues.init(sbot) | |
30 … | + var getMsg = asyncMemo(sbot.get) | |
31 … | + var getRepo = asyncMemo(function (id, cb) { | |
32 … | + getMsg(id, function (err, msg) { | |
33 … | + if (err) return cb(err) | |
34 … | + ssbGit.getRepo(sbot, {key: id, value: msg}, {live: true}, cb) | |
35 … | + }) | |
36 … | + }) | |
37 … | + | |
38 … | + var getPullReq = asyncMemo(function (id, cb) { | |
39 … | + issues.get(id, function (err, issue) { | |
40 … | + if (err) return cb(err) | |
41 … | + var c = issue.msg.value.content | |
42 … | + issue.baseRepo = c.repo | |
43 … | + issue.baseBranch = c.branch | |
44 … | + issue.headRepo = c.head_repo | |
45 … | + issue.headBranch = c.head_branch | |
46 … | + cb(null, issue) | |
47 … | + }) | |
48 … | + }) | |
49 … | + | |
50 … | + function listPullReqs(opts) { | |
51 … | + opts = opts || {} | |
52 … | + opts.type = 'pull-request' | |
53 … | + return pull( | |
54 … | + sbot.messagesByType(opts), | |
55 … | + pull.filter(function (msg) { | |
56 … | + return (!opts.repo || opts.repo == msg.value.content.repo) | |
57 … | + && (!opts.author || opts.author == msg.value.author) | |
58 … | + }), | |
59 … | + paramap(function (msg, cb) { | |
60 … | + getPullReq(msg.key, cb) | |
61 … | + }, 8), | |
62 … | + pull.filter(opts.open != null && function (pr) { | |
63 … | + return pr.open == opts.open | |
64 … | + }) | |
65 … | + ) | |
66 … | + } | |
67 … | + | |
68 … | + return { | |
69 … | + get: getPullReq, | |
70 … | + list: listPullReqs | |
71 … | + } | |
72 … | + } | |
73 … | +} |
lib/schemas.js | ||
---|---|---|
@@ -1,0 +1,33 @@ | ||
1 … | +var ssbRef = require('ssb-ref') | |
2 … | + | |
3 … | +exports.new = function (baseRepo, baseBranch, headRepo, headBranch, | |
4 … | + title, text) { | |
5 … | + if (!ssbRef.isLink(baseRepo)) | |
6 … | + throw new Error('invalid base repo id') | |
7 … | + if (!baseBranch || typeof baseBranch != 'string') | |
8 … | + throw new Error('invalid base branch') | |
9 … | + if (!ssbRef.isLink(headRepo)) | |
10 … | + throw new Error('invalid head repo id') | |
11 … | + if (!headBranch || typeof headBranch != 'string') | |
12 … | + throw new Error('invalid head branch') | |
13 … | + | |
14 … | + var msg = { | |
15 … | + type: 'pull-request', | |
16 … | + repo: baseRepo, | |
17 … | + project: baseRepo, | |
18 … | + branch: baseBranch, | |
19 … | + head_repo: headRepo, | |
20 … | + head_branch: headBranch | |
21 … | + } | |
22 … | + | |
23 … | + if (title) { | |
24 … | + if (typeof title === 'string') msg.title = title | |
25 … | + else throw new Error('invalid title') | |
26 … | + } | |
27 … | + if (text) { | |
28 … | + if (typeof text === 'string') msg.text = text | |
29 … | + else throw new Error('invalid text') | |
30 … | + } | |
31 … | + | |
32 … | + return msg | |
33 … | +} |
package.json | ||
---|---|---|
@@ -1,0 +1,18 @@ | ||
1 … | +{ | |
2 … | + "name": "ssb-pull-requests", | |
3 … | + "version": "0.0.0", | |
4 … | + "description": "pull requests for git-ssb repos", | |
5 … | + "main": "index.js", | |
6 … | + "homepage": "http://git-ssb.celehner.com/%254aw2wDMB07FH03P6EAHT1Q5x4TZ8mRS7j9%2FOLAcj%2FNw%3D.sha256", | |
7 … | + "bugs": "http://git-ssb.celehner.com/%254aw2wDMB07FH03P6EAHT1Q5x4TZ8mRS7j9%2FOLAcj%2FNw%3D.sha256/issues", | |
8 … | + "dependencies": { | |
9 … | + "asyncmemo": "^0.1.0", | |
10 … | + "ssb-issues": "^0.0.6", | |
11 … | + "pull-paramap": "^1.1.2", | |
12 … | + "pull-stream": "^3.2.0", | |
13 … | + "ssb-git-repo": "^1.5.2", | |
14 … | + "ssb-ref": "^2.3.0" | |
15 … | + }, | |
16 … | + "author": "Charles Lehner (http://celehner.com/)", | |
17 … | + "license": "Fair" | |
18 … | +} |
Built with git-ssb-web