Files: 0099a6481da34ffa656cc6b1699549145fe444b7 / lib / schemas.js
1380 bytesRaw
1 | var ssbRef = require('ssb-ref') |
2 | var mlib = require('ssb-msgs') |
3 | |
4 | exports.new = function (project, title, text) { |
5 | if (!ssbRef.isLink(project)) |
6 | throw new Error('invalid project id') |
7 | var msg = { type: 'issue', project: project } |
8 | if (text == null) { |
9 | text = title |
10 | title = null |
11 | } |
12 | if (title) { |
13 | if (typeof title === 'string') |
14 | msg.title = title |
15 | else |
16 | throw new Error('invalid issue title') |
17 | } |
18 | if (text) { |
19 | if (typeof text === 'string') |
20 | msg.text = text |
21 | else |
22 | throw new Error('invalid issue text') |
23 | } |
24 | return msg |
25 | } |
26 | |
27 | exports.edit = function (id, opts) { |
28 | if (!ssbRef.isMsg(id)) |
29 | throw new Error('invalid issue id') |
30 | var msg = { |
31 | type: 'issue-edit', |
32 | issues: [{ |
33 | link: id |
34 | }] |
35 | } |
36 | if (opts.open != null) |
37 | msg.issues[0].open = opts.open |
38 | if (opts.title != null) |
39 | msg.issues[0].title = opts.title |
40 | return msg |
41 | } |
42 | |
43 | exports.close = function (id) { |
44 | return exports.edit(id, {open: false}) |
45 | } |
46 | |
47 | exports.reopen = function (id) { |
48 | return exports.edit(id, {open: true}) |
49 | } |
50 | |
51 | function editMsg(msg, id, open) { |
52 | if (!ssbRef.isMsg(id)) |
53 | throw new Error('invalid issue id') |
54 | ;(msg.issues || (msg.issues = [])).push({ |
55 | link: id, |
56 | open: open |
57 | }) |
58 | return msg |
59 | } |
60 | |
61 | exports.reopens = function (msg, id) { |
62 | return editMsg(msg, id, true) |
63 | } |
64 | |
65 | exports.closes = function (msg, id) { |
66 | return editMsg(msg, id, false) |
67 | } |
68 |
Built with git-ssb-web