Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // TODO(wittman): Convert this extension to event pages once they work with | 5 // TODO(wittman): Convert this extension to event pages once they work with |
| 6 // the notifications API. Currently it's not possible to restore the | 6 // the notifications API. Currently it's not possible to restore the |
| 7 // Notification object when event pages get reloaded. See | 7 // Notification object when event pages get reloaded. See |
| 8 // http://crbug.com/165276. | 8 // http://crbug.com/165276. |
| 9 | 9 |
| 10 (function() { | |
| 11 | |
| 10 var statusURL = "http://chromium-status.appspot.com/current?format=raw"; | 12 var statusURL = "http://chromium-status.appspot.com/current?format=raw"; |
| 11 var statusHistoryURL = | 13 var statusHistoryURL = |
| 12 "http://chromium-status.appspot.com/allstatus?limit=20&format=json"; | 14 "http://chromium-status.appspot.com/allstatus?limit=20&format=json"; |
| 13 var pollFrequencyInMs = 30000; | 15 var pollFrequencyInMs = 30000; |
| 14 var tryPollFrequencyInMs = 30000; | 16 var tryPollFrequencyInMs = 30000; |
| 15 | 17 |
| 16 var prefs = new Prefs; | 18 var prefs = new Prefs; |
| 17 | 19 |
| 18 function updateBadgeOnErrorStatus() { | 20 function updateBadgeOnErrorStatus() { |
| 19 chrome.browserAction.setBadgeText({text:"?"}); | 21 chrome.browserAction.setBadgeText({text:"?"}); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 } | 114 } |
| 113 updateTimeBadge(Date.now() - lastChangeTime); | 115 updateTimeBadge(Date.now() - lastChangeTime); |
| 114 } | 116 } |
| 115 } | 117 } |
| 116 | 118 |
| 117 function requestStatus() { | 119 function requestStatus() { |
| 118 requestURL(statusURL, "text", updateStatus, updateBadgeOnErrorStatus); | 120 requestURL(statusURL, "text", updateStatus, updateBadgeOnErrorStatus); |
| 119 setTimeout(requestStatus, pollFrequencyInMs); | 121 setTimeout(requestStatus, pollFrequencyInMs); |
| 120 } | 122 } |
| 121 | 123 |
| 122 var activeIssues = {}; | |
| 123 // Record of the last defunct build number we're aware of on each builder. If | 124 // Record of the last defunct build number we're aware of on each builder. If |
| 124 // the build number is less than or equal to this number, the buildbot | 125 // the build number is less than or equal to this number, the buildbot |
| 125 // information is not available and a request will return a 404. | 126 // information is not available and a request will return a 404. |
| 126 var lastDefunctTryJob = {}; | 127 var lastDefunctTryJob = {}; |
| 127 | 128 |
| 128 function fetchTryJobResults(fullPatchset, builder, buildnumber) { | 129 function fetchTryJobResults(fullPatchset, builder, buildnumber, completed) { |
| 129 var tryJobURL = | 130 var tryJobURL = |
| 130 "http://build.chromium.org/p/tryserver.chromium/json/builders/" + | 131 "http://build.chromium.org/p/tryserver.chromium/json/builders/" + |
| 131 builder + "/builds/" + buildnumber; | 132 builder + "/builds/" + buildnumber; |
| 132 | 133 |
| 133 if (lastDefunctTryJob.hasOwnProperty(builder) && | 134 if (lastDefunctTryJob.hasOwnProperty(builder) && |
| 134 buildnumber <= lastDefunctTryJob[builder]) | 135 buildnumber <= lastDefunctTryJob[builder]) |
| 135 return; | 136 return; |
| 136 | 137 |
| 137 var onStatusError = function(status) { | 138 var onStatusError = function(status) { |
|
not at google - send to devlin
2013/07/04 00:37:11
can you inline this function, or un-inline the oth
Mike Wittman
2013/07/16 17:53:19
Done.
| |
| 138 if (status == 404) | 139 if (status == 404) { |
| 139 lastDefunctTryJob[builder] = buildnumber; | 140 lastDefunctTryJob[builder] = |
| 141 Math.max(lastDefunctTryJob[builder] || 0, buildnumber); | |
| 142 completed(); | |
| 143 } | |
| 140 }; | 144 }; |
| 141 | 145 |
| 142 requestURL(tryJobURL, "json", function(tryJobResult) { | 146 requestURL(tryJobURL, "json", function(tryJobResult) { |
| 143 if (!fullPatchset.full_try_job_results) | 147 if (!fullPatchset.full_try_job_results) |
| 144 fullPatchset.full_try_job_results = {}; | 148 fullPatchset.full_try_job_results = {}; |
| 145 | 149 |
| 146 var key = builder + "-" + buildnumber; | 150 var key = builder + "-" + buildnumber; |
| 147 fullPatchset.full_try_job_results[key] = tryJobResult; | 151 fullPatchset.full_try_job_results[key] = tryJobResult; |
| 152 | |
| 153 completed(); | |
| 148 }, onStatusError); | 154 }, onStatusError); |
| 149 } | 155 } |
| 150 | 156 |
| 151 function fetchPatches(issue, completed) { | 157 // Enums corresponding to how much state has been loaded for an issue. |
| 158 var PATCHES_COMPLETE = 0; | |
| 159 var TRY_JOBS_COMPLETE = 1; | |
| 160 | |
| 161 function fetchPatches(issue, updatedCallback) { | |
| 162 // Notify updated once after receiving all patchsets, and a second time after | |
| 163 // receiving all try job results. | |
| 152 var patchsetsRetrieved = 0; | 164 var patchsetsRetrieved = 0; |
| 165 var tryJobResultsOutstanding = 0; | |
| 153 issue.patchsets.forEach(function(patchset) { | 166 issue.patchsets.forEach(function(patchset) { |
| 154 var patchURL = "https://codereview.chromium.org/api/" + issue.issue + | 167 var patchURL = "https://codereview.chromium.org/api/" + issue.issue + |
| 155 "/" + patchset; | 168 "/" + patchset; |
| 156 | 169 |
| 157 requestURL(patchURL, "json", function(patch) { | 170 requestURL(patchURL, "json", function(patch) { |
| 158 if (!issue.full_patchsets) | 171 if (!issue.full_patchsets) |
| 159 issue.full_patchsets = {}; | 172 issue.full_patchsets = {}; |
| 160 | 173 |
| 161 issue.full_patchsets[patch.patchset] = patch; | 174 issue.full_patchsets[patch.patchset] = patch; |
| 162 | 175 |
| 163 patch.try_job_results.forEach(function(results) { | 176 patch.try_job_results.forEach(function(results) { |
| 164 if (results.buildnumber) | 177 if (results.buildnumber) { |
| 165 fetchTryJobResults(patch, results.builder, results.buildnumber); | 178 tryJobResultsOutstanding++; |
| 179 | |
| 180 fetchTryJobResults( | |
| 181 patch, | |
| 182 results.builder, | |
| 183 results.buildnumber, | |
| 184 function() { | |
| 185 if (--tryJobResultsOutstanding == 0) | |
| 186 updatedCallback(TRY_JOBS_COMPLETE); | |
| 187 }); | |
|
not at google - send to devlin
2013/07/04 00:37:11
looks a bit, odd, I'd probably cheat like
Mike Wittman
2013/07/16 17:53:19
Done.
| |
| 188 } | |
| 166 }); | 189 }); |
| 167 | 190 |
| 168 if (++patchsetsRetrieved == issue.patchsets.length) | 191 if (++patchsetsRetrieved == issue.patchsets.length) |
| 169 completed(issue); | 192 updatedCallback(PATCHES_COMPLETE); |
| 170 }); | 193 }); |
| 171 }); | 194 }); |
| 172 } | 195 } |
| 173 | 196 |
| 174 function updateTryStatus(status) { | 197 function updateTryStatus(status) { |
| 175 var seen = {}; | 198 var seen = {}; |
| 199 var activeIssues = getActiveIssues(); | |
| 176 status.results.forEach(function(result) { | 200 status.results.forEach(function(result) { |
| 177 var issueURL = "https://codereview.chromium.org/api/" + result.issue; | 201 var issueURL = "https://codereview.chromium.org/api/" + result.issue; |
| 178 | 202 |
| 179 requestURL(issueURL, "json", function(issue) { | 203 requestURL(issueURL, "json", function(issue) { |
| 180 fetchPatches(issue, function() {activeIssues[issue.issue] = issue;}); | 204 fetchPatches(issue, function(state) { |
| 205 // If the issue already exists, wait until all the issue state has | |
| 206 // loaded before updating the issue so we don't lose try job information | |
| 207 // from the display. | |
| 208 if (activeIssues.getIssue(issue.issue)) { | |
| 209 if (state == TRY_JOBS_COMPLETE) | |
| 210 activeIssues.updateIssue(issue); | |
| 211 } else { | |
| 212 activeIssues.updateIssue(issue); | |
| 213 } | |
| 214 }); | |
| 181 }); | 215 }); |
| 182 | 216 |
| 183 seen[result.issue] = true; | 217 seen[result.issue] = true; |
| 184 }); | 218 }); |
| 185 | 219 |
| 186 for (var issue in activeIssues) | 220 activeIssues.forEach(function(issue) { |
| 187 if (!seen[issue]) | 221 if (!seen[issue.issue]) |
| 188 delete activeIssues[issue]; | 222 activeIssues.removeIssue(issue); |
| 223 }); | |
| 189 } | 224 } |
| 190 | 225 |
| 226 var tryStatusTimeoutID; | |
| 227 | |
| 191 function requestTryStatus() { | 228 function requestTryStatus() { |
| 229 var searchBaseURL = "https://codereview.chromium.org/search"; | |
| 230 | |
| 192 prefs.getTryJobUsername(function(username) { | 231 prefs.getTryJobUsername(function(username) { |
| 193 if (username) { | 232 // Use the username if set and not consisting solely of whitespace. |
| 194 var url = "https://codereview.chromium.org/search" + | 233 if (username && username.trim()) { |
| 234 var url = searchBaseURL + | |
| 195 // commit=2 is CLs with commit bit set, commit=3 is CLs with commit | 235 // commit=2 is CLs with commit bit set, commit=3 is CLs with commit |
| 196 // bit cleared, commit=1 is either. | 236 // bit cleared, commit=1 is either. |
| 197 "?closed=3&commit=1&limit=100&order=-modified&format=json&owner=" + | 237 "?closed=3&commit=1&limit=100&order=-modified&format=json&owner=" + |
| 198 username; | 238 username.trim(); |
| 199 requestURL(url, "json", updateTryStatus); | 239 requestURL(url, "json", updateTryStatus); |
| 240 } else if (username == null) { | |
| 241 // Try scraping username from Rietveld if unset. | |
| 242 requestURL(searchBaseURL, "text", function(text) { | |
| 243 var match = /([^<>\s]+@\S+)\s+\(.+\)/.exec(text); | |
| 244 if (match) { | |
| 245 prefs.setTryJobUsername(match[1]); | |
| 246 clearTimeout(tryStatusTimeoutID); | |
|
not at google - send to devlin
2013/07/04 00:37:11
I'm a bit confused by the flow here, with the clea
Mike Wittman
2013/07/16 17:53:19
I've refactored this to avoid the clearTimeout and
| |
| 247 requestTryStatus(); | |
| 248 } | |
| 249 }); | |
| 200 } | 250 } |
| 201 | 251 |
| 202 setTimeout(requestTryStatus, tryPollFrequencyInMs); | 252 tryStatusTimeoutID = setTimeout(requestTryStatus, tryPollFrequencyInMs); |
| 203 }); | 253 }); |
| 204 } | 254 } |
| 205 | 255 |
| 206 function main() { | 256 function main() { |
| 207 requestStatus(); | 257 requestStatus(); |
| 208 requestTryStatus(); | 258 requestTryStatus(); |
| 209 } | 259 } |
| 210 | 260 |
| 211 main(); | 261 main(); |
| 262 | |
| 263 })(); | |
| OLD | NEW |