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
4 found in the LICENSE file.
7 <link rel="import" href="../lib/net.html">
8 <link rel='import' href='ct-commit.html'>
9 <link rel='import' href='ct-repositories.html'>
12 function CTCommitLog() {
14 this.lastRevision = {};
15 this._repositories = new CTRepositories();
17 this._repositories.names.forEach(function(name) {
18 this.commits[name] = {};
22 CTCommitLog.prototype.update = function() {
24 Object.keys(this._repositories.repositories, (function(name, repository) {
25 var responseHandler = this._handleResponse.bind(this, repository.repositoryUrl, repository.name);
26 // FIXME: Turn net.js into net.html and import it at the top of this file.
27 requests.push(net.ajax({url: repository.dataUrl}).then(responseHandler));
29 return Promise.all(requests);
32 CTCommitLog.prototype._handleResponse = function(repositoryUrl, repository, json) {
33 // FIXME: Fix googlesource to not do this outdated JSON XSS mitigation.
34 json = json.substring(')]}\n'.length);
35 JSON.parse(json).log.forEach(function(entry) {
36 var author = entry.author.email;
37 var message = entry.message;
38 var revision = CTCommit.findRevision(message);
40 // Check for existing commit for that revision, and possibly complete it.
41 // We update the existing commit instead of creating a new one so that the
42 // data-binding properly updates all the <ct-commit>'s.
43 var existingCommit = this.commits[repository][revision];
44 if (existingCommit && !existingCommit.isComplete) {
45 existingCommit.complete(author, message, revision);
47 var commit = CTCommit.create(author, message, repositoryUrl, repository);
48 this.commits[repository][commit.revision] = commit;
52 this._updateLastRevision(repository);
55 CTCommitLog.prototype._updateLastRevision = function(repository) {
56 var sortedCommits = Object.keys(this.commits[repository]).sort();
57 this.lastRevision[repository] = sortedCommits.last();
60 CTCommitLog.prototype.range = function(repository, revisions) {
62 revisions.forEach(function(revision) {
63 var commit = this.commits[repository][revision];
65 var url = this._repositories.repositories[repository].repositoryUrl;
66 var commit = CTCommit.createIncomplete(url, revision, repository);
67 this.commits[repository][revision] = commit;