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 parseCommitMessage(message) { 54 var lines = message.split('\n'); 55 var title = lines.shift(); 56 var summary = lines.join('\n').trim(); 57 return { 58 title: title, 59 summary: summary, 60 bugID: findBugID(summary), 61 reviewer: findReviewer(summary), 62 } 63 } 64 65 // FIXME: Consider exposing this method for unit testing. 66 function parseCommitData(responseXML) 67 { 68 var commits = Array.prototype.map.call(responseXML.getElementsByTagName('logentry'), function(logentry) { 69 var author = logentry.getElementsByTagName('author')[0].textContent; 70 var time = logentry.getElementsByTagName('date')[0].textContent; 71 72 // FIXME: This isn't a very high-fidelity reproduction of the commit message, 73 // but it's good enough for our purposes. 74 var message = parseCommitMessage(logentry.getElementsByTagName('msg')[0].textContent); 75 76 return { 77 'revision': logentry.getAttribute('revision'), 78 'title': message.title, 79 'time': time, 80 'summary': message.title, 81 'author': author, 82 'reviewer': message.reviewer, 83 'bugID': message.bugID, 84 'message': message.summary, 85 'revertedRevision': undefined, 86 }; 87 }); 88 return commits; 89 } 90 91 trac.changesetURL = function(revision) 92 { 93 var queryParameters = { 94 view: 'rev', 95 revision: revision, 96 }; 97 return config.kBlinkRevisionURL + '?' + $.param(queryParameters); 98 }; 99 100 trac.recentCommitData = function(path, limit, callback) 101 { 102 net.get('/svnlog', function(commitData) { 103 callback(parseCommitData(commitData)); 104 }); 105 }; 106 107 trac.commitDataForRevisionRange = function(path, startRevision, endRevision, callback) 108 { 109 var key = [path, startRevision, endRevision].join('\n'); 110 g_cache.get(key, callback); 111 }; 112 113 })(); 114