1 /* 2 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Google Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 24 * THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 var trac = trac || {}; 28 29 (function() { 30 31 function findUsingRegExp(string, regexp) 32 { 33 var match = regexp.exec(string); 34 if (match) 35 return match[1]; 36 return null; 37 } 38 39 function findReviewer(message) 40 { 41 var regexp = /R=([^.]+)/; 42 return findUsingRegExp(message, regexp); 43 } 44 45 function findBugID(message) 46 { 47 var regexp = /BUG=(\d+)/; 48 var bugID = parseInt(findUsingRegExp(message, regexp), 10); 49 return isNaN(bugID) ? 0 : bugID; 50 51 } 52 53 function findRevision(message) 54 { 55 var regexp = /git-svn-id: svn:\/\/svn.chromium.org\/blink\/trunk@(\d+)/; 56 var svnRevision = parseInt(findUsingRegExp(message, regexp), 10); 57 return isNaN(svnRevision) ? null : svnRevision; 58 } 59 60 function parseCommitMessage(message) { 61 var lines = message.split('\n'); 62 var title = lines[1]; 63 var summary = lines.join('\n').trim(); 64 return { 65 title: title, 66 summary: summary, 67 bugID: findBugID(summary), 68 reviewer: findReviewer(summary), 69 revision: findRevision(summary), 70 } 71 } 72 73 // FIXME: Consider exposing this method for unit testing. 74 function parseCommitData(responseXML) 75 { 76 var commits = Array.prototype.map.call(responseXML.getElementsByTagName('entry'), function(logentry) { 77 var author = $.trim(logentry.getElementsByTagName('author')[0].textContent); 78 var time = logentry.getElementsByTagName('published')[0].textContent; 79 80 // FIXME: This isn't a very high-fidelity reproduction of the commit message, 81 // but it's good enough for our purposes. 82 var message = parseCommitMessage(logentry.getElementsByTagName('content')[0].textContent); 83 84 return { 85 'revision': message.revision, 86 'title': message.title, 87 'time': time, 88 'summary': message.title, 89 'author': author, 90 'reviewer': message.reviewer, 91 'bugID': message.bugID, 92 'message': message.summary, 93 'revertedRevision': undefined, 94 }; 95 }); 96 return commits; 97 } 98 99 trac.changesetURL = function(revision) 100 { 101 var queryParameters = { 102 view: 'rev', 103 revision: revision, 104 }; 105 return config.kBlinkRevisionURL + '?' + $.param(queryParameters); 106 }; 107 108 trac.recentCommitData = function(path, limit, callback) 109 { 110 net.get('http://blink.lc/blink/atom', function(commitData) { 111 callback(parseCommitData(commitData)); 112 }); 113 }; 114 115 trac.commitDataForRevisionRange = function(path, startRevision, endRevision, callback) 116 { 117 var key = [path, startRevision, endRevision].join('\n'); 118 g_cache.get(key, callback); 119 }; 120 121 })(); 122