git ssb

30+

cel / git-ssb-web



Commit b4ebc518897addfccafcbb7b6dd3c9b653767b78

Fix bugs with pull requests

%pPqJJh2iDxfXsTU4NAnHFqfORPjEU0mdUJeSU0uravc=.sha256
Charles Lehner committed on 4/26/2016, 6:19:04 AM
Parent: 5264137ee26b34066cad458926a86775eb73dddd

Files changed

lib/repos/index.jschanged
lib/repos/pulls.jschanged
lib/util.jschanged
lib/repos/index.jsView
@@ -57,16 +57,8 @@
5757 ])
5858 }
5959 }
6060
61-function hiddenInputs(values) {
62- return Object.keys(values).map(function (key) {
63- return '<input type="hidden"' +
64- ' name="' + u.escape(key) + '"' +
65- ' value="' + u.escape(values[key]) + '"/>'
66- }).join('')
67-}
68-
6961 /* Repo */
7062
7163 R.serveRepoPage = function (req, repo, path) {
7264 var self = this
@@ -259,9 +251,9 @@
259251 (repo.head == 'refs/heads/' + rev ? '' : '@' + rev)
260252 return this.renderRepoPage(req, repo, 'code', rev, title, cat([
261253 pull.once('<section><form action="" method="get">' +
262254 '<h3>' + req._t(type) + ': ' + rev + ' '),
263- revMenu(req, repo, rev),
255+ this.revMenu(req, repo, rev),
264256 pull.once('</h3></form>'),
265257 type == 'Branch' && renderRepoLatest(req, repo, rev),
266258 pull.once('</section><section>'),
267259 renderRepoTree(req, repo, rev, path),
@@ -384,57 +376,42 @@
384376 }
385377
386378 /* Branch menu */
387379
388-function formatRevOptions(currentName) {
380+R.formatRevOptions = function (currentName) {
389381 return function (name) {
390382 var htmlName = u.escape(name)
391383 return '<option value="' + htmlName + '"' +
392384 (name == currentName ? ' selected="selected"' : '') +
393385 '>' + htmlName + '</option>'
394386 }
395387 }
396388
397-function formatRevType(req, type) {
389+R.formatRevType = function(req, type) {
398390 return (
399391 type == 'heads' ? req._t('Branches') :
400392 type == 'tags' ? req._t('Tags') :
401393 type)
402394 }
403395
404-function revMenu(req, repo, currentName) {
396+R.revMenu = function (req, repo, currentName) {
397+ var self = this
405398 return u.readOnce(function (cb) {
406399 repo.getRefNames(function (err, refs) {
407400 if (err) return cb(err)
408401 cb(null, '<select name="rev" onchange="this.form.submit()">' +
409402 Object.keys(refs).map(function (group) {
410- return '<optgroup label="' + formatRevType(req, group) + '">' +
411- refs[group].map(formatRevOptions(currentName)).join('') +
403+ return '<optgroup ' +
404+ 'label="' + self.formatRevType(req, group) + '">' +
405+ refs[group].map(self.formatRevOptions(currentName)).join('') +
412406 '</optgroup>'
413407 }).join('') +
414408 '</select><noscript> ' +
415409 '<input type="submit" value="' + req._t('Go') + '"/></noscript>')
416410 })
417411 })
418412 }
419413
420-function branchMenu(repo, name, currentName) {
421- return cat([
422- pull.once('<select name="' + name + '">'),
423- pull(
424- repo.refs(),
425- pull.map(function (ref) {
426- var m = ref.name.match(/^refs\/([^\/]*)\/(.*)$/) || [,, ref.name]
427- return m[1] == 'heads' && m[2]
428- }),
429- pull.filter(Boolean),
430- u.pullSort(),
431- pull.map(formatRevOptions(currentName))
432- ),
433- pull.once('</select>')
434- ])
435-}
436-
437414 /* Repo tree */
438415
439416 function renderRepoLatest(req, repo, rev) {
440417 return u.readOnce(function (cb) {
@@ -802,9 +779,9 @@
802779 (repo.head == 'refs/heads/' + rev ? '' : '@' + rev)
803780 cb(null, self.renderRepoPage(req, repo, 'code', rev, title, cat([
804781 pull.once('<section><form action="" method="get">' +
805782 '<h3>' + req._t(type) + ': ' + rev + ' '),
806- revMenu(req, repo, rev),
783+ self.revMenu(req, repo, rev),
807784 pull.once('</h3></form>'),
808785 type == 'Branch' && renderRepoLatest(req, repo, rev),
809786 pull.once('</section><section class="collapse">' +
810787 '<h3>' + req._t('Files') + pathLinks + '</h3>' +
@@ -926,9 +903,9 @@
926903 var title = req._t('Fork') + ' · %{author}/%{repo}'
927904 return this.renderRepoPage(req, repo, null, null, title, pull.once(
928905 '<form action="" method="post" onreset="history.back()">' +
929906 '<h3>' + req._t('ForkRepoPrompt') + '</h3>' +
930- '<p>' + hiddenInputs({ id: repo.id }) +
907+ '<p>' + u.hiddenInputs({ id: repo.id }) +
931908 '<button class="btn open" type="submit" name="action" value="fork">' +
932909 req._t('Fork') +
933910 '</button>' +
934911 ' <button class="btn" type="reset">' +
lib/repos/pulls.jsView
@@ -216,8 +216,25 @@
216216 }
217217
218218 /* Compare changes */
219219
220+P.branchMenu = function (repo, name, currentName) {
221+ return cat([
222+ pull.once('<select name="' + name + '">'),
223+ pull(
224+ repo.refs(),
225+ pull.map(function (ref) {
226+ var m = ref.name.match(/^refs\/([^\/]*)\/(.*)$/) || [,, ref.name]
227+ return m[1] == 'heads' && m[2]
228+ }),
229+ pull.filter(Boolean),
230+ u.pullSort(),
231+ pull.map(this.repo.formatRevOptions(currentName))
232+ ),
233+ pull.once('</select>')
234+ ])
235+}
236+
220237 P.serveRepoCompare = function (req, repo) {
221238 var self = this
222239 var query = req._u.query
223240 var base
@@ -233,9 +250,9 @@
233250 if (query.base) gotBase(null, query.base)
234251 else repo.getSymRef('HEAD', true, gotBase)
235252 function gotBase(err, ref) {
236253 if (err) return cb(err)
237- cb(null, branchMenu(repo, 'base', base = ref || 'HEAD'))
254+ cb(null, self.branchMenu(repo, 'base', base = ref || 'HEAD'))
238255 }
239256 }),
240257 pull.once('<br/>' + req._t('ComparisonRepoBranch') + ':'),
241258 pull(
@@ -334,9 +351,9 @@
334351 '<span class="bgslash">' + authorLink + ' / ' + repoLink +
335352 ' / ' + headBranchLink + '</span>' +
336353 '</section>' +
337354 (query.expand ? '<section><form method="post" action="">' +
338- hiddenInputs({
355+ u.hiddenInputs({
339356 action: 'new-pull',
340357 branch: baseBranch,
341358 head_repo: headRepoId,
342359 head_branch: headBranch
@@ -347,9 +364,9 @@
347364 '<button type="submit" class="btn open">' +
348365 req._t('Create') + '</button>' +
349366 '</form></section>'
350367 : '<section><form method="get" action="">' +
351- hiddenInputs({
368+ u.hiddenInputs({
352369 base: baseBranch,
353370 head: query.head
354371 }) +
355372 '<button class="btn open" type="submit" name="expand" value="1">' +
lib/util.jsView
@@ -75,8 +75,16 @@
7575 return '<a href="' + href + '"' + props + '>' + link[1] + '</a>'
7676 }), after || '', '</nav>').join('')
7777 }
7878
79+u.hiddenInputs = function (values) {
80+ return Object.keys(values).map(function (key) {
81+ return '<input type="hidden"' +
82+ ' name="' + u.escape(key) + '"' +
83+ ' value="' + u.escape(values[key]) + '"/>'
84+ }).join('')
85+}
86+
7987 u.highlight = function(code, lang) {
8088 try {
8189 return lang
8290 ? Highlight.highlight(lang, code).value

Built with git-ssb-web