git ssb

0+

cel / ssb-issues



Tree: 14d3ae7ec41db46483040757b3dcfbbb6ace0030

Files: 14d3ae7ec41db46483040757b3dcfbbb6ace0030 / lib / schemas.js

1380 bytesRaw
1var ssbRef = require('ssb-ref')
2var mlib = require('ssb-msgs')
3
4exports.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
27exports.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
43exports.close = function (id) {
44 return exports.edit(id, {open: false})
45}
46
47exports.reopen = function (id) {
48 return exports.edit(id, {open: true})
49}
50
51function 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
61exports.reopens = function (msg, id) {
62 return editMsg(msg, id, true)
63}
64
65exports.closes = function (msg, id) {
66 return editMsg(msg, id, false)
67}
68

Built with git-ssb-web