git ssb

0+

Kira / %V53yIAO6ZNGv1Lx9tCP…



forked from cel / ssb-issues

Tree: 42a68b9d00a60a49e9704e5f92838cd30a216274

Files: 42a68b9d00a60a49e9704e5f92838cd30a216274 / lib / schemas.js

1277 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 (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
23exports.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
37exports.close = function (id) {
38 return exports.edit(id, {open: false})
39}
40
41exports.reopen = function (id) {
42 return exports.edit(id, {open: true})
43}
44
45function 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
55exports.reopens = function (msg, id) {
56 return editMsg(msg, id, true)
57}
58
59exports.closes = function (msg, id) {
60 return editMsg(msg, id, false)
61}
62

Built with git-ssb-web