git ssb

0+

Kira / %V53yIAO6ZNGv1Lx9tCP…



forked from cel / ssb-issues

Commit 3c92db173ab8661c8ac76098857639346343f9c4

Deprecate title property

Close %b9wdyGH54m8uHkONgqFrMEv7/qDNlRKs5umsOh2Mm0I=.sha256
Charles Lehner committed on 7/25/2016, 10:06:42 PM
Parent: c25e6d705c1dac43baa7b9e092c8bbd14249cae6

Files changed

README.mdchanged
index.jschanged
lib/schemas.jschanged
test.jschanged
README.mdView
@@ -64,9 +64,9 @@
6464 - `id`: id of the issue
6565 - `author`: author of the issue
6666 - `created_at` (timestamp): when the issue was created
6767 - `updated_at` (timestamp): when the issue was last updated
68-- `title`: title of the issue
68+- `title`: title of the issue (deprecated)
6969 - `open`: whether the issue is open (true) or closed (false)
7070 - `project`: the project that the issue is for
7171 - `projectAuthor`: the author of the project
7272 - `msg`: ssb message object that created the issue (with
@@ -96,9 +96,9 @@
9696 issues.new({ project:, title:, text: }, cb)
9797 ```
9898
9999 - `project` (Ref): id of an ssb object representing the target of the issue
100-- `title` (string): title of the issue
100+- `title` (string): title of the issue (deprecated)
101101 - `text` (string): text describing the issue
102102
103103 #### close: async
104104
@@ -130,9 +130,9 @@
130130 Edit an issue.
131131
132132 `id` (MsgRef): id of the issue to reopen
133133 `opts.open` (boolean): set open/closed status
134-`opts.title` (string): set title
134+`opts.title` (string): set title (deprecated)
135135
136136 #### isStatusChanged: sync
137137
138138 ```js
@@ -171,17 +171,17 @@
171171
172172 Create a new issue.
173173
174174 - `project` (Ref): id of project to associate the issue with
175-- `title` (string): title to give the issue
175+- `title` (string): title to give the issue (deprecated)
176176 - `text` (string): text body for the issue
177177
178178 #### `issueSchemas.edit(id, opts)`
179179
180180 Edit an issue.
181181
182182 - `opts.open` (boolean): open or close the issue
183-- `opts.title` (string): set the title of the issue
183+- `opts.title` (string): set the title of the issue (deprecated)
184184
185185 #### `issueSchemas.close(id)`
186186
187187 Close an issue.
index.jsView
@@ -12,8 +12,12 @@
1212 return msg.value.author == issue.author
1313 || msg.value.author == issue.projectAuthor
1414 }
1515
16+function truncate(str, len) {
17+ return str.length > len ? str.substr(0, len) + '...' : str
18+}
19+
1620 exports.name = 'issues'
1721
1822 exports.manifest = {
1923 get: 'async',
@@ -68,9 +72,9 @@
6872 issue.msg = msg
6973 issue.author = msg.value.author
7074 var c = msg.value.content
7175 issue.project = c.project
72- issue.text = c.text
76+ issue.text = String(c.text)
7377 issue.created_at = issue.updated_at = msg.value.timestamp
7478 if (c.project)
7579 ssbGet(c.project, gotProjectMsg)
7680 else
@@ -174,9 +178,9 @@
174178 if (cb) {
175179 if (issue.open == null)
176180 issue.open = true
177181 if (issue.title == null)
178- issue.title = issue.id
182+ issue.title = truncate(issue.text, 40) || issue.id
179183 checkReady()
180184 }
181185 }
182186
lib/schemas.jsView
@@ -4,8 +4,12 @@
44 exports.new = function (project, title, text) {
55 if (!ssbRef.isLink(project))
66 throw new Error('invalid project id')
77 var msg = { type: 'issue', project: project }
8+ if (text == null) {
9+ text = title
10+ title = null
11+ }
812 if (title) {
913 if (typeof title === 'string')
1014 msg.title = title
1115 else
test.jsView
@@ -18,9 +18,9 @@
1818 .use(require('scuttlebot/plugins/blobs'))
1919
2020 var sbot = createSbot({
2121 temp: 'test-ssb-issues', timeout: 200,
22- allowPrivate: true,
22+ /textallowPrivate: true,
2323 keys: ssbKeys.generate()
2424 })
2525
2626 var issues = Issues.init(sbot)
@@ -42,41 +42,24 @@
4242 var issue1
4343 var updated_at
4444
4545 test('create an issue', function (t) {
46- var title = 'Test Title'
4746 issues.new({
4847 project: projectId,
49- title: title,
5048 text: 'Test Text'
5149 }, function (err, issue) {
5250 t.error(err, 'new issue')
5351 t.ok(issue.id, 'id')
5452 t.equals(issue.project, projectId, 'project')
5553 t.equals(issue.author, sbot.id, 'author')
56- t.equals(issue.title, title, 'title')
54+ t.equals(issue.title, 'Test Text', 'title/text')
5755 t.equals(issue.open, true, 'open')
5856 t.equals(~~(issue.created_at/1e5), ~~(Date.now()/1e5), 'created_at')
5957 issue1 = issue
6058 t.end()
6159 })
6260 })
6361
64-test('update the issue', function (t) {
65- var title = 'New Title'
66- issues.edit(issue1.id, {title: title}, function (err, msg) {
67- t.error(err, 'edit')
68- t.ok(msg, 'msg')
69- awaitMsg(sbot, msg, function (err) {
70- t.error(err, 'await')
71- t.equals(issue1.title, title, 'new title')
72- t.notEquals(issue1.updated_at, issue1.created_at, 'updated_at is new')
73- t.ok(Date.now() - issue1.updated_at < 60e3, 'updated_at is recent')
74- t.end()
75- })
76- })
77-})
78-
7962 test('close the issue', function (t) {
8063 issues.close(issue1.id, function (err, msg) {
8164 t.error(err, 'close')
8265 t.ok(msg, 'msg')

Built with git-ssb-web