Files: e0b78c9cf91c492ebbd46e4da475f5ebba378fa1 / lib / schemas.js
1277 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 (title) { |
9 | if (typeof title === 'string') |
10 | msg.title = title |
11 | else |
12 | throw new Error('invalid issue title') |
13 | } |
14 | if (text) { |
15 | if (typeof text === 'string') |
16 | msg.text = text |
17 | else |
18 | throw new Error('invalid issue text') |
19 | } |
20 | return msg |
21 | } |
22 | |
23 | exports.edit = function (id, opts) { |
24 | if (!ssbRef.isMsg(id)) |
25 | throw new Error('invalid issue id') |
26 | var msg = { |
27 | type: 'issue-edit', |
28 | issue: id |
29 | } |
30 | if (opts.open != null) |
31 | msg.open = opts.open |
32 | if (opts.title != null) |
33 | msg.title = opts.title |
34 | return msg |
35 | } |
36 | |
37 | exports.close = function (id) { |
38 | return exports.edit(id, {open: false}) |
39 | } |
40 | |
41 | exports.reopen = function (id) { |
42 | return exports.edit(id, {open: true}) |
43 | } |
44 | |
45 | function editMsg(msg, id, open) { |
46 | if (!ssbRef.isMsg(id)) |
47 | throw new Error('invalid issue id') |
48 | ;(msg.issues || (msg.issues = [])).push({ |
49 | link: id, |
50 | open: open |
51 | }) |
52 | return msg |
53 | } |
54 | |
55 | exports.reopens = function (msg, id) { |
56 | return editMsg(msg, id, true) |
57 | } |
58 | |
59 | exports.closes = function (msg, id) { |
60 | return editMsg(msg, id, false) |
61 | } |
62 |
Built with git-ssb-web