Commit 3c92db173ab8661c8ac76098857639346343f9c4
Deprecate title property
Close %b9wdyGH54m8uHkONgqFrMEv7/qDNlRKs5umsOh2Mm0I=.sha256Charles Lehner committed on 7/25/2016, 10:06:42 PM
Parent: c25e6d705c1dac43baa7b9e092c8bbd14249cae6
Files changed
README.md | changed |
index.js | changed |
lib/schemas.js | changed |
test.js | changed |
README.md | ||
---|---|---|
@@ -64,9 +64,9 @@ | ||
64 | 64 | - `id`: id of the issue |
65 | 65 | - `author`: author of the issue |
66 | 66 | - `created_at` (timestamp): when the issue was created |
67 | 67 | - `updated_at` (timestamp): when the issue was last updated |
68 | -- `title`: title of the issue | |
68 | +- `title`: title of the issue (deprecated) | |
69 | 69 | - `open`: whether the issue is open (true) or closed (false) |
70 | 70 | - `project`: the project that the issue is for |
71 | 71 | - `projectAuthor`: the author of the project |
72 | 72 | - `msg`: ssb message object that created the issue (with |
@@ -96,9 +96,9 @@ | ||
96 | 96 | issues.new({ project:, title:, text: }, cb) |
97 | 97 | ``` |
98 | 98 | |
99 | 99 | - `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) | |
101 | 101 | - `text` (string): text describing the issue |
102 | 102 | |
103 | 103 | #### close: async |
104 | 104 | |
@@ -130,9 +130,9 @@ | ||
130 | 130 | Edit an issue. |
131 | 131 | |
132 | 132 | `id` (MsgRef): id of the issue to reopen |
133 | 133 | `opts.open` (boolean): set open/closed status |
134 | -`opts.title` (string): set title | |
134 | +`opts.title` (string): set title (deprecated) | |
135 | 135 | |
136 | 136 | #### isStatusChanged: sync |
137 | 137 | |
138 | 138 | ```js |
@@ -171,17 +171,17 @@ | ||
171 | 171 | |
172 | 172 | Create a new issue. |
173 | 173 | |
174 | 174 | - `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) | |
176 | 176 | - `text` (string): text body for the issue |
177 | 177 | |
178 | 178 | #### `issueSchemas.edit(id, opts)` |
179 | 179 | |
180 | 180 | Edit an issue. |
181 | 181 | |
182 | 182 | - `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) | |
184 | 184 | |
185 | 185 | #### `issueSchemas.close(id)` |
186 | 186 | |
187 | 187 | Close an issue. |
index.js | ||
---|---|---|
@@ -12,8 +12,12 @@ | ||
12 | 12 | return msg.value.author == issue.author |
13 | 13 | || msg.value.author == issue.projectAuthor |
14 | 14 | } |
15 | 15 | |
16 | +function truncate(str, len) { | |
17 | + return str.length > len ? str.substr(0, len) + '...' : str | |
18 | +} | |
19 | + | |
16 | 20 | exports.name = 'issues' |
17 | 21 | |
18 | 22 | exports.manifest = { |
19 | 23 | get: 'async', |
@@ -68,9 +72,9 @@ | ||
68 | 72 | issue.msg = msg |
69 | 73 | issue.author = msg.value.author |
70 | 74 | var c = msg.value.content |
71 | 75 | issue.project = c.project |
72 | - issue.text = c.text | |
76 | + issue.text = String(c.text) | |
73 | 77 | issue.created_at = issue.updated_at = msg.value.timestamp |
74 | 78 | if (c.project) |
75 | 79 | ssbGet(c.project, gotProjectMsg) |
76 | 80 | else |
@@ -174,9 +178,9 @@ | ||
174 | 178 | if (cb) { |
175 | 179 | if (issue.open == null) |
176 | 180 | issue.open = true |
177 | 181 | if (issue.title == null) |
178 | - issue.title = issue.id | |
182 | + issue.title = truncate(issue.text, 40) || issue.id | |
179 | 183 | checkReady() |
180 | 184 | } |
181 | 185 | } |
182 | 186 |
lib/schemas.js | ||
---|---|---|
@@ -4,8 +4,12 @@ | ||
4 | 4 | exports.new = function (project, title, text) { |
5 | 5 | if (!ssbRef.isLink(project)) |
6 | 6 | throw new Error('invalid project id') |
7 | 7 | var msg = { type: 'issue', project: project } |
8 | + if (text == null) { | |
9 | + text = title | |
10 | + title = null | |
11 | + } | |
8 | 12 | if (title) { |
9 | 13 | if (typeof title === 'string') |
10 | 14 | msg.title = title |
11 | 15 | else |
test.js | ||
---|---|---|
@@ -18,9 +18,9 @@ | ||
18 | 18 | .use(require('scuttlebot/plugins/blobs')) |
19 | 19 | |
20 | 20 | var sbot = createSbot({ |
21 | 21 | temp: 'test-ssb-issues', timeout: 200, |
22 | - allowPrivate: true, | |
22 | + /textallowPrivate: true, | |
23 | 23 | keys: ssbKeys.generate() |
24 | 24 | }) |
25 | 25 | |
26 | 26 | var issues = Issues.init(sbot) |
@@ -42,41 +42,24 @@ | ||
42 | 42 | var issue1 |
43 | 43 | var updated_at |
44 | 44 | |
45 | 45 | test('create an issue', function (t) { |
46 | - var title = 'Test Title' | |
47 | 46 | issues.new({ |
48 | 47 | project: projectId, |
49 | - title: title, | |
50 | 48 | text: 'Test Text' |
51 | 49 | }, function (err, issue) { |
52 | 50 | t.error(err, 'new issue') |
53 | 51 | t.ok(issue.id, 'id') |
54 | 52 | t.equals(issue.project, projectId, 'project') |
55 | 53 | t.equals(issue.author, sbot.id, 'author') |
56 | - t.equals(issue.title, title, 'title') | |
54 | + t.equals(issue.title, 'Test Text', 'title/text') | |
57 | 55 | t.equals(issue.open, true, 'open') |
58 | 56 | t.equals(~~(issue.created_at/1e5), ~~(Date.now()/1e5), 'created_at') |
59 | 57 | issue1 = issue |
60 | 58 | t.end() |
61 | 59 | }) |
62 | 60 | }) |
63 | 61 | |
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 | - | |
79 | 62 | test('close the issue', function (t) { |
80 | 63 | issues.close(issue1.id, function (err, msg) { |
81 | 64 | t.error(err, 'close') |
82 | 65 | t.ok(msg, 'msg') |
Built with git-ssb-web