Commit 77ca943d1889e9ed48ffceb25d8de3f1b5998515
Fix git issue closing/reopening and rendering
Charles Lehner committed on 8/2/2016, 8:12:02 PMParent: 4634187810d6f06d0603f7e7e2935ecf2ba4c000
Files changed
modules/git.js | changed |
modules/git.js | ||
---|---|---|
@@ -82,8 +82,17 @@ | ||
82 | 82 | }) |
83 | 83 | return el |
84 | 84 | } |
85 | 85 | |
86 | +function renderIssueEdit(c) { | |
87 | + var id = c.issue || c.link | |
88 | + return [ | |
89 | + c.title ? h('p', 'renamed issue ', message_link(id), | |
90 | + ' to ', h('ins', c.title)) : null, | |
91 | + c.open === false ? h('p', 'closed issue ', message_link(id)) : null, | |
92 | + c.open === true ? h('p', 'reopened issue ', message_link(id)) : null] | |
93 | +} | |
94 | + | |
86 | 95 | exports.message_content = function (msg, sbot) { |
87 | 96 | var c = msg.value.content |
88 | 97 | |
89 | 98 | if(c.type === 'git-repo') { |
@@ -227,15 +236,10 @@ | ||
227 | 236 | } |
228 | 237 | |
229 | 238 | if(c.type === 'issue-edit') { |
230 | 239 | return h('div', |
231 | - 0, false, null, undefined, '', 'ok', | |
232 | - c.title ? h('p', 'renamed issue ', message_link(c.issue), | |
233 | - ' to ', h('ins', c.title)) : null, | |
234 | - c.open === false ? h('p', 'closed issue ', message_link(c.issue)) : null, | |
235 | - c.open === true ? h('p', 'reopened issue ', message_link(c.issue)) : '', | |
236 | - c.issues ? c.issues : null | |
237 | - ) | |
240 | + c.issue ? renderIssueEdit(c) : null, | |
241 | + c.issues ? c.issues.map(renderIssueEdit) : null) | |
238 | 242 | } |
239 | 243 | |
240 | 244 | if(c.type === 'issue') { |
241 | 245 | return h('div', |
@@ -257,10 +261,11 @@ | ||
257 | 261 | } |
258 | 262 | |
259 | 263 | exports.message_meta = function (msg, sbot) { |
260 | 264 | var type = msg.value.content.type |
261 | - if (type == 'issue' || type == 'pull-request') { | |
265 | + if (type === 'issue' || type === 'pull-request') { | |
262 | 266 | var el = h('em', '...') |
267 | + // TODO: update if issue is changed | |
263 | 268 | getIssueState(msg.key, function (err, state) { |
264 | 269 | if (err) return console.error(err) |
265 | 270 | el.textContent = state |
266 | 271 | }) |
@@ -274,21 +279,30 @@ | ||
274 | 279 | var isOpen |
275 | 280 | var a = h('a', {href: '#', onclick: function () { |
276 | 281 | message_confirm({ |
277 | 282 | type: 'issue-edit', |
283 | + root: msg.key, | |
278 | 284 | issues: [{ |
279 | 285 | link: msg.key, |
280 | 286 | open: !isOpen |
281 | 287 | }] |
288 | + }, function (err, msg) { | |
289 | + if(err) return alert(err) | |
290 | + if(!msg) return | |
291 | + isOpen = msg.value.content.open | |
292 | + update() | |
282 | 293 | }) |
283 | 294 | }}) |
284 | 295 | getIssueState(msg.key, function (err, state) { |
285 | 296 | if (err) return console.error(err) |
286 | 297 | isOpen = state === 'open' |
298 | + update() | |
299 | + }) | |
300 | + function update() { | |
287 | 301 | a.textContent = c.type === 'pull-request' |
288 | 302 | ? isOpen ? 'Close Pull Request' : 'Reopen Pull Request' |
289 | 303 | : isOpen ? 'Close Issue' : 'Reopen Issue' |
290 | - }) | |
304 | + } | |
291 | 305 | return a |
292 | 306 | } |
293 | 307 | } |
294 | 308 |
Built with git-ssb-web