Files: ea7483671e4c557ff8a2d71717148f1ea356c1f4 / lib / schemas.js
1337 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 | issue: id |
33 | } |
34 | if (opts.open != null) |
35 | msg.open = opts.open |
36 | if (opts.title != null) |
37 | msg.title = opts.title |
38 | return msg |
39 | } |
40 | |
41 | exports.close = function (id) { |
42 | return exports.edit(id, {open: false}) |
43 | } |
44 | |
45 | exports.reopen = function (id) { |
46 | return exports.edit(id, {open: true}) |
47 | } |
48 | |
49 | function editMsg(msg, id, open) { |
50 | if (!ssbRef.isMsg(id)) |
51 | throw new Error('invalid issue id') |
52 | ;(msg.issues || (msg.issues = [])).push({ |
53 | link: id, |
54 | open: open |
55 | }) |
56 | return msg |
57 | } |
58 | |
59 | exports.reopens = function (msg, id) { |
60 | return editMsg(msg, id, true) |
61 | } |
62 | |
63 | exports.closes = function (msg, id) { |
64 | return editMsg(msg, id, false) |
65 | } |
66 |
Built with git-ssb-web