git ssb

30+

cel / git-ssb-web



Commit aab7516eaaea84704ac2a3f1c5b868b6c2f2dd84

Whitespace

cel committed on 11/24/2016, 12:41:01 PM
Parent: 2ed137317e22416efbf15ecd4b2ac323d55a34b6

Files changed

lib/index-cache.jschanged
lib/index-cache.jsView
@@ -2,113 +2,113 @@
22 var cat = require('pull-cat')
33
44 // work around sync not getting emitted
55 function logt(sbot, opt) {
6- if (!opt.live) return sbot.messagesByType(opt)
7- var optOld = {}, optNew = {}
8- for (var k in opt) optOld[k] = opt[k], optNew[k] = opt[k]
9- optOld.live = false, optOld.old = true
10- optNew.live = true, optNew.old = false
11- return cat([
12- sbot.messagesByType(optOld),
13- pull.once({sync: true}),
14- sbot.messagesByType(optNew)
15- ])
6 + if (!opt.live) return sbot.messagesByType(opt)
7 + var optOld = {}, optNew = {}
8 + for (var k in opt) optOld[k] = opt[k], optNew[k] = opt[k]
9 + optOld.live = false, optOld.old = true
10 + optNew.live = true, optNew.old = false
11 + return cat([
12 + sbot.messagesByType(optOld),
13 + pull.once({sync: true}),
14 + sbot.messagesByType(optNew)
15 + ])
1616 }
1717
1818 // Keep track of the set of open issues and pull-requests for each repo.
1919 // This is like a 2P-set, where an issue/pull-request message adds to the set
2020 // and a link rel issues with property close: true is a remove from the set.
2121
2222 module.exports = function (sbot) {
23- var repos = {/* issue/pr id : repo id */}
24- var repoIssues = {/* repo id : {issue id} */}
25- var repoPRs = {/* repo id : {pr id} */}
26- var closed = {/* issue/pr id */}
27- var waiting = 3
28- var start = new Date
23 + var repos = {/* issue/pr id : repo id */}
24 + var repoIssues = {/* repo id : {issue id} */}
25 + var repoPRs = {/* repo id : {pr id} */}
26 + var closed = {/* issue/pr id */}
27 + var waiting = 3
28 + var start = new Date
2929
30- pull(
31- logt(sbot, {
32- type: 'issue',
33- live: true,
34- }),
35- pull.drain(function (msg) {
36- if (msg.sync) return sync()
37- if (msg.key in closed) return delete closed[msg.key]
38- var repoId = msg.value.content.project || msg.value.content.repo
39- var issues = repoIssues[repoId] || (repoIssues[repoId] = {count: 0})
40- issues[msg.key] = true
41- repos[msg.key] = repoId
42- issues.count++
43- }, function (err) {
44- if (err) console.error(err.stack || err)
45- })
46- )
30 + pull(
31 + logt(sbot, {
32 + type: 'issue',
33 + live: true,
34 + }),
35 + pull.drain(function (msg) {
36 + if (msg.sync) return sync()
37 + if (msg.key in closed) return delete closed[msg.key]
38 + var repoId = msg.value.content.project || msg.value.content.repo
39 + var issues = repoIssues[repoId] || (repoIssues[repoId] = {count: 0})
40 + issues[msg.key] = true
41 + repos[msg.key] = repoId
42 + issues.count++
43 + }, function (err) {
44 + if (err) console.error(err.stack || err)
45 + })
46 + )
4747
48- pull(
49- logt(sbot, {
50- type: 'pull-request',
51- live: true,
52- }),
53- pull.drain(function (msg) {
54- if (msg.sync) return sync()
55- if (msg.key in closed) return delete closed[msg.key]
56- var repoId = msg.value.content.repo
57- var prs = repoPRs[repoId] || (repoPRs[repoId] = {count: 0})
58- prs[msg.key] = true
59- repos[msg.key] = repoId
60- prs.count++
61- }, function (err) {
62- if (err) console.error(err.stack || err)
63- })
64- )
48 + pull(
49 + logt(sbot, {
50 + type: 'pull-request',
51 + live: true,
52 + }),
53 + pull.drain(function (msg) {
54 + if (msg.sync) return sync()
55 + if (msg.key in closed) return delete closed[msg.key]
56 + var repoId = msg.value.content.repo
57 + var prs = repoPRs[repoId] || (repoPRs[repoId] = {count: 0})
58 + prs[msg.key] = true
59 + repos[msg.key] = repoId
60 + prs.count++
61 + }, function (err) {
62 + if (err) console.error(err.stack || err)
63 + })
64 + )
6565
66- pull(
67- sbot.links({
68- rel: 'issues',
69- values: true,
70- live: true,
71- }),
66 + pull(
67 + sbot.links({
68 + rel: 'issues',
69 + values: true,
70 + live: true,
71 + }),
7272 pull.map(function (msg) {
73- if (msg.sync) return sync()
73 + if (msg.sync) return sync()
7474 return msg.value.content.issues
7575 }),
7676 pull.flatten(),
77- pull.filter(function (issue) {
78- return issue.open === false
79- }),
80- pull.drain(function (update) {
81- var id = update.link
82- var repoId = repos[id]
83- if (repoId) {
84- var issues, prs
85- if ((issues = repoIssues[repoId]) && issues[id])
86- delete issues[id], issues.count--
87- if ((prs = repoPRs[repoId]) && prs[id])
88- delete prs[id], prs.count--
89- } else {
90- closed[id] = true
91- }
92- }, function (err) {
93- if (err) console.error(err.stack || err)
94- })
95- )
77 + pull.filter(function (issue) {
78 + return issue.open === false
79 + }),
80 + pull.drain(function (update) {
81 + var id = update.link
82 + var repoId = repos[id]
83 + if (repoId) {
84 + var issues, prs
85 + if ((issues = repoIssues[repoId]) && issues[id])
86 + delete issues[id], issues.count--
87 + if ((prs = repoPRs[repoId]) && prs[id])
88 + delete prs[id], prs.count--
89 + } else {
90 + closed[id] = true
91 + }
92 + }, function (err) {
93 + if (err) console.error(err.stack || err)
94 + })
95 + )
9696
97- function sync() {
98- if (--waiting) return
99- console.log('Issues state synced', -(start -= new Date)/1000 + 's')
100- }
97 + function sync() {
98 + if (--waiting) return
99 + console.log('Issues state synced', -(start -= new Date)/1000 + 's')
100 + }
101101
102- return {
103- getIssuesCount: function (repoId, placeholder) {
104- if (waiting) return placeholder || NaN
105- var issue = repoIssues[repoId]
106- return issue ? issue.count : 0
107- },
108- getPRsCount: function (repoId, placeholder) {
109- if (waiting) return placeholder || NaN
110- var pr = repoPRs[repoId]
111- return pr ? pr.count : 0
112- },
113- }
102 + return {
103 + getIssuesCount: function (repoId, placeholder) {
104 + if (waiting) return placeholder || NaN
105 + var issue = repoIssues[repoId]
106 + return issue ? issue.count : 0
107 + },
108 + getPRsCount: function (repoId, placeholder) {
109 + if (waiting) return placeholder || NaN
110 + var pr = repoPRs[repoId]
111 + return pr ? pr.count : 0
112 + },
113 + }
114114 }

Built with git-ssb-web