aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-01-08 22:03:51 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-01-08 22:03:51 -1000
commit09cf04663fe2a772d5a06bbcf86b9014dc4f5228 (patch)
treeae755d9bf9757a807938718acf5910b291f90198 /lib/serve.js
parentcbf9a1d87eb43eaea73e6c019e7b4a2dca3bbaa6 (diff)
downloadpatchfoo-09cf04663fe2a772d5a06bbcf86b9014dc4f5228.tar.gz
patchfoo-09cf04663fe2a772d5a06bbcf86b9014dc4f5228.zip
Render line comments on diffs
Diffstat (limited to 'lib/serve.js')
-rw-r--r--lib/serve.js133
1 files changed, 95 insertions, 38 deletions
diff --git a/lib/serve.js b/lib/serve.js
index f191b77..78ff104 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -1651,6 +1651,7 @@ Serve.prototype.git = function (url) {
case 'blob': return this.gitBlob(m[2])
case 'raw': return this.gitRaw(m[2])
case 'diff': return this.gitDiff(m[2])
+ case 'line-comment': return this.gitLineComment(m[2])
default: return this.respond(404, 'Not found')
}
}
@@ -2114,12 +2115,16 @@ Serve.prototype.gitDiff = function (revs) {
var done = multicb({pluck: 1, spread: true})
pull.collect(done())(self.app.git.readObject(obj1))
pull.collect(done())(self.app.git.readObject(obj2))
- done(function (err, bufs1, bufs2) {
+ self.app.getLineComments({obj: obj2, hash: rev2}, done())
+ done(function (err, bufs1, bufs2, lineComments) {
if (err) return cb(err)
var str1 = Buffer.concat(bufs1, obj1.length).toString('utf8')
var str2 = Buffer.concat(bufs2, obj2.length).toString('utf8')
var diff = Diff.structuredPatch('', '', str1, str2)
- cb(null, self.gitDiffTable(diff))
+ cb(null, self.gitDiffTable(diff, lineComments, {
+ obj: obj2,
+ hash: rev2,
+ }))
})
})
})
@@ -2130,12 +2135,10 @@ Serve.prototype.gitDiff = function (revs) {
})
}
-Serve.prototype.gitDiffTable = function (diff) {
+Serve.prototype.gitDiffTable = function (diff, lineComments, lineCommentInfo) {
var self = this
return pull(
ph('table', [
- ph('tr', [
- ]),
pull(
pull.values(diff.hunks),
pull.map(function (hunk) {
@@ -2157,39 +2160,42 @@ Serve.prototype.gitDiffTable = function (diff) {
var lineNums = [s == '+' ? '' : oldLine++, s == '-' ? '' : newLine++]
// var id = [filename].concat(lineNums).join('-')
var newLineNum = lineNums[lineNums.length-1]
- return ph('tr', {
- class: s == '+' ? 'diff-new' : s == '-' ? 'diff-old' : ''
- }, [
- lineNums.map(function (num, i) {
- return ph('td', String(num))
- // TODO: allow linking to comments
- /*
- var idEnc = encodeURIComponent(id)
- return '<td class="code-linenum">' +
- (num ? '<a href="#' + idEnc + '">' +
- num + '</a>' +
- (updateId && i === lineNums.length-1 && s !== '-' ?
- ' <a href="?comment=' + idEnc + '#' + idEnc + '">…</a>'
- : '')
- : '') + '</td>'
- }
- */
- }),
- ph('td', ph('pre', u.escapeHTML(html)))
- ])
-
- // TODO: line-comments
- /*
- (lineCommentThreads[newLineNum] ?
- '<tr><td colspan=4>' +
- lineCommentThreads[newLineNum] +
- '</td></tr>'
- : commit && query.comment === id ?
- '<tr><td colspan=4>' +
- forms.lineComment(req, repo, updateId, commit, filename, newLineNum) +
- '</td></tr>'
- : '')
- */
+ return [
+ ph('tr', {
+ class: s == '+' ? 'diff-new' : s == '-' ? 'diff-old' : ''
+ }, [
+ lineNums.map(function (num, i) {
+ return ph('td', String(num))
+ // TODO: allow linking to comments
+ /*
+ var idEnc = encodeURIComponent(id)
+ return '<td class="code-linenum">' +
+ (num ? '<a href="#' + idEnc + '">' +
+ num + '</a>' +
+ (updateId && i === lineNums.length-1 && s !== '-' ?
+ ' <a href="?comment=' + idEnc + '#' + idEnc + '">…</a>'
+ : '')
+ : '') + '</td>'
+ }
+ */
+ }),
+ ph('td', ph('pre', u.escapeHTML(html)))
+ ]),
+ (lineComments[newLineNum] ?
+ ph('tr',
+ ph('td', {colspan: 4},
+ self.renderLineCommentThread(lineComments[newLineNum])
+ )
+ )
+ : /*commit && query.comment === id ?
+ ph('tr',
+ ph('td', {colspan: 4},
+ // self.renderLineCommentForm(req, repo, updateId, commit, filename, newLineNum)
+ self.renderLineCommentForm(lineCommentInfo)
+ )
+ )
+ :*/ '')
+ ]
})
)
]
@@ -2199,6 +2205,57 @@ Serve.prototype.gitDiffTable = function (diff) {
)
}
+Serve.prototype.renderLineCommentThread = function (lineComment) {
+ var self = this
+ return ph('table', {class: 'ssb-msgs'}, pull(
+ this.app.getThread(lineComment.msg),
+ self.renderThread()
+ ))
+}
+
+Serve.prototype.renderLineCommentForm = function (info) {
+ var obj = info.obj
+ var hash = info.hash
+ return ph('pre', JSON.stringify(info, 0, 2))
+}
+
+Serve.prototype.gitLineComment = function (path) {
+ var self = this
+ var id = decodeURIComponent(String(path))
+ self.getMsgDecryptedMaybeOoo(id, function (err, msg) {
+ if (err) return pull(
+ pull.once(u.renderError(err).outerHTML),
+ self.respondSink(400, {'Content-Type': ctype('html')})
+ )
+ var c = msg && msg.value && msg.value.content
+ if (!c) return pull(
+ pull.once('Missing message ' + id),
+ self.respondSink(500, {'Content-Type': ctype('html')})
+ )
+ self.app.git.getObjectAtPath({
+ msg: c.updateId,
+ obj: c.commitId,
+ path: c.filePath,
+ }, function (err, obj) {
+ if (err && err.name === 'BlobNotFoundError')
+ return self.askWantBlobs(err.links)
+ if (err) return pull(
+ pull.once(err.stack),
+ self.respondSink(400, {'Content-Type': 'text/plain'})
+ )
+
+ self.redirect(self.app.render.toUrl(publishedMsg.key))
+
+ /*
+ pull(
+ ph('pre', JSON.stringify(obj, 0, 2)),
+ self.respondSink(200)
+ )
+ */
+ })
+ })
+}
+
Serve.prototype.gitObjectLinks = function (headMsgId, type) {
var self = this
return paramap(function (id, cb) {