OLD | NEW |
1 <!-- | 1 <!-- |
2 Copyright 2014 The Chromium Authors. All rights reserved. | 2 Copyright 2014 The Chromium Authors. All rights reserved. |
3 Use of this source code is governed by a BSD-style license that can be | 3 Use of this source code is governed by a BSD-style license that can be |
4 found in the LICENSE file. | 4 found in the LICENSE file. |
5 --> | 5 --> |
6 | 6 |
7 <link rel='import' href='ct-commit.html'> | 7 <link rel='import' href='ct-commit.html'> |
8 | 8 |
| 9 <link rel='import' href='ct-repositories.html'> |
| 10 |
9 <script> | 11 <script> |
10 function CTCommitLog() { | 12 function CTCommitLog() { |
11 // FIXME: This should be a map of repo-name to revision log using the same | |
12 // repo names that auto-sheriff.appspot's json uses. | |
13 | |
14 // FIXME: Use better feeds. | |
15 // https://chromium.googlesource.com/chromium/blink/+log/master?format=json | |
16 // https://chromium.googlesource.com/chromium/chromium/+log/master?format=json | |
17 // https://code.google.com/feeds/p/skia/svnchanges/basic | |
18 // https://code.google.com/feeds/p/v8/svnchanges/basic | |
19 // https://code.google.com/feeds/p/nativeclient/svnchanges/basic | |
20 this.commits = {}; | 13 this.commits = {}; |
| 14 this.firstRevision = {}; |
| 15 this._repositories = new CTRepositories(); |
21 } | 16 } |
22 | 17 |
23 CTCommitLog.prototype.update = function() { | 18 CTCommitLog.prototype.update = function() { |
24 // FIXME: Turn net.js into net.html and import it at the top of this file. | 19 var requests = []; |
25 return net.xml('http://blink.lc/blink/atom').then(this._processXml.bind(this))
; | 20 Object.keys(this._repositories.repositories, (function(name, repository) { |
| 21 var responseHandler = this._handleResponse.bind(this, repository.repositoryU
rl, repository.name); |
| 22 // FIXME: Turn net.js into net.html and import it at the top of this file. |
| 23 requests.push(net.ajax({url: repository.dataUrl}).then(responseHandler)); |
| 24 }.bind(this))); |
| 25 return Promise.all(requests); |
26 } | 26 } |
27 | 27 |
28 CTCommitLog.prototype._processXml = function(xml) { | 28 CTCommitLog.prototype._handleResponse = function(repositoryUrl, repository, json
) { |
29 Array.prototype.forEach.call(xml.getElementsByTagName('entry'), function(logen
try) { | 29 if (!this.commits[repository]) |
30 var author = logentry.getElementsByTagName('author')[0].textContent.trim(); | 30 this.commits[repository] = {}; |
31 var message = logentry.getElementsByTagName('content')[0].textContent.trim()
; | 31 |
32 // FIXME: Handle base urls for different repos. | 32 // FIXME: Fix googlesource to not do this outdated JSON XSS mitigation. |
33 var commit = new CTCommit(author, message, 'http://src.chromium.org/viewvc/b
link'); | 33 // Don't include the \n in the feature detection because that breaks startWith
. |
34 this.commits[commit.revision] = commit; | 34 var googlesourceJsonHeader = ')]}'; |
| 35 if (json.startsWith(googlesourceJsonHeader)) |
| 36 json = json.substring(googlesourceJsonHeader.length + 1); |
| 37 JSON.parse(json).log.forEach(function(entry) { |
| 38 var commit = CTCommit.create(entry.author.name, entry.message, repositoryUrl
, repository); |
| 39 this.commits[repository][commit.revision] = commit; |
35 }.bind(this)); | 40 }.bind(this)); |
| 41 |
| 42 this.firstRevision[repository] = Object.keys(this.commits[repository]).sort()[
0]; |
| 43 } |
| 44 |
| 45 CTCommitLog.prototype.range = function(repository, first, last) { |
| 46 var commits = []; |
| 47 for (var revision = first; revision <= last; revision++) { |
| 48 // Until we've seen a commit we have data for, fill in dummy data |
| 49 // so that we show something. Assume that we have the correct data |
| 50 // for all the commits after the first one we have data for. |
| 51 if (revision >= this.firstRevision[repository]) { |
| 52 var commit = this.commits[repository][revision]; |
| 53 if (commit) |
| 54 commits.push(commit); |
| 55 } else { |
| 56 var url = this._repositories.repositories[repository].repositoryUrl; |
| 57 commits.push(CTCommit.createIncomplete(url, revision, repository)); |
| 58 } |
| 59 } |
| 60 return commits; |
36 } | 61 } |
37 </script> | 62 </script> |
OLD | NEW |