git ssb

0+

cel / ssb-issues



Tree: 7880a84c53be4a312a09ca7cb7d1ac5bafc76d23

Files: 7880a84c53be4a312a09ca7cb7d1ac5bafc76d23 / lib / schemas.js

1337 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 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
41exports.close = function (id) {
42 return exports.edit(id, {open: false})
43}
44
45exports.reopen = function (id) {
46 return exports.edit(id, {open: true})
47}
48
49function 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
59exports.reopens = function (msg, id) {
60 return editMsg(msg, id, true)
61}
62
63exports.closes = function (msg, id) {
64 return editMsg(msg, id, false)
65}
66

Built with git-ssb-web