Commit 6045860192b4a93aa6ab2006b28b4ce056237bd4
Add getMention method
Charles Lehner committed on 3/29/2016, 9:47:35 PMParent: afcbea7780f83c601550a863ce0be8c654a88d78
Files changed
README.md | changed |
index.js | changed |
test.js | changed |
README.md | ||
---|---|---|
@@ -142,8 +142,23 @@ | ||
142 | 142 | - `issue` (Issue): issue to check for update |
143 | 143 | - `open` (boolean?): whether the message updates the issue to be open (true) |
144 | 144 | closed (false), or does not affect it (null) |
145 | 145 | |
146 | +#### getMention: sync | |
147 | + | |
148 | +```js | |
149 | +var mention = issueSchemas.getMention(issue, msg) | |
150 | +``` | |
151 | + | |
152 | +Get a mention of an issue in a message, if any | |
153 | + | |
154 | +- `msg` (Msg in metadata): message to check | |
155 | +- `issue` (Issue): issue to check for update | |
156 | +- `mention` (object?): mention object, with properties like | |
157 | + - `mention.open` (boolean?): whether the issue is updated to be open (true), | |
158 | + closed (false), or not (null) | |
159 | + | |
160 | + | |
146 | 161 | ### schemas |
147 | 162 | |
148 | 163 | ```js |
149 | 164 | var issueSchemas = Issues.schemas |
index.js | ||
---|---|---|
@@ -21,27 +21,34 @@ | ||
21 | 21 | new: 'async', |
22 | 22 | edit: 'async', |
23 | 23 | close: 'async', |
24 | 24 | reopen: 'async', |
25 | + getMention: 'sync', | |
25 | 26 | isStatusChanged: 'sync' |
26 | 27 | } |
27 | 28 | |
28 | 29 | exports.schemas = issueSchemas |
29 | 30 | |
30 | 31 | function isStatusChanged(msg, issue) { |
32 | + var mention = getMention(msg, issue) | |
33 | + return mention ? mention.open : null | |
34 | +} | |
35 | + | |
36 | +function getMention(msg, issue) { | |
31 | 37 | var c = msg.value.content |
32 | 38 | if (msg.key == issue.id || c.issue == issue.id || c.link == issue.id) |
33 | 39 | if (c.open != null) |
34 | - return c.open | |
40 | + return c | |
35 | 41 | if (c.issues) { |
36 | - var changed | |
42 | + var mention | |
37 | 43 | for (var i = 0; i < c.issues.length; i++) { |
38 | - changed = isStatusChanged({value: { | |
44 | + mention = getMention({value: { | |
39 | 45 | timestamp: msg.value.timestamp, |
40 | 46 | author: msg.value.author, |
41 | 47 | content: c.issues[i] |
42 | 48 | }}, issue) |
43 | - if (changed != null) return changed | |
49 | + if (mention) | |
50 | + return mention | |
44 | 51 | } |
45 | 52 | } |
46 | 53 | } |
47 | 54 | |
@@ -229,7 +236,8 @@ | ||
229 | 236 | new: newIssue, |
230 | 237 | edit: editIssue, |
231 | 238 | close: closeIssue, |
232 | 239 | reopen: reopenIssue, |
240 | + getMention: getMention, | |
233 | 241 | isStatusChanged: isStatusChanged |
234 | 242 | } |
235 | 243 | } |
test.js | ||
---|---|---|
@@ -94,8 +94,10 @@ | ||
94 | 94 | t.ok(msg, 'msg') |
95 | 95 | awaitMsg(sbot, msg, function (err) { |
96 | 96 | t.error(err, 'await') |
97 | 97 | t.equals(issue1.open, true, 'open') |
98 | + var mention = issues.getMention(msg, issue1) | |
99 | + t.equals(mention && mention.open, true, 'mention') | |
98 | 100 | updated_at = issue1.updated_at |
99 | 101 | t.end() |
100 | 102 | }) |
101 | 103 | }) |
Built with git-ssb-web