OLD | NEW |
| (Empty) |
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 return parseInt(findUsingRegExp(message, regexp), 10); | |
49 } | |
50 | |
51 function parseCommitMessage(message) { | |
52 var lines = message.split('\n'); | |
53 var title = lines.shift(); | |
54 var summary = lines.join('\n').trim(); | |
55 return { | |
56 title: title, | |
57 summary: summary, | |
58 bugID: findBugID(summary), | |
59 reviewer: findReviewer(summary), | |
60 } | |
61 } | |
62 | |
63 // FIXME: Consider exposing this method for unit testing. | |
64 function parseCommitData(responseXML) | |
65 { | |
66 var commits = Array.prototype.map.call(responseXML.getElementsByTagName('log
entry'), function(logentry) { | |
67 var author = logentry.getElementsByTagName('author')[0].textContent; | |
68 var time = logentry.getElementsByTagName('date')[0].textContent; | |
69 | |
70 // FIXME: This isn't a very high-fidelity reproduction of the commit mes
sage, | |
71 // but it's good enough for our purposes. | |
72 var message = parseCommitMessage(logentry.getElementsByTagName('msg')[0]
.textContent); | |
73 | |
74 return { | |
75 'revision': logentry.getAttribute('revision'), | |
76 'title': message.title, | |
77 'time': time, | |
78 'summary': message.title, | |
79 'author': author, | |
80 'reviewer': message.reviewer, | |
81 'bugID': message.bugID, | |
82 'message': message.summary, | |
83 'revertedRevision': undefined, | |
84 }; | |
85 }); | |
86 return commits; | |
87 } | |
88 | |
89 trac.changesetURL = function(revision) | |
90 { | |
91 var queryParameters = { | |
92 view: 'rev', | |
93 revision: revision, | |
94 }; | |
95 return config.kBlinkRevisionURL + '?' + $.param(queryParameters); | |
96 }; | |
97 | |
98 trac.recentCommitData = function(path, limit, callback) | |
99 { | |
100 var lastCommitURL = config.kSvnLogURL + '?' + $.param({ | |
101 'url': config.kBlinkSvnURL, | |
102 'range': 'HEAD', | |
103 }); | |
104 | |
105 net.get(lastCommitURL, function(commitData) { | |
106 // FIXME: Factor this function out! | |
107 var lastCommitData = parseCommitData(commitData); | |
108 if (!lastCommitData.length) | |
109 throw new Error("svn-log did not return last commit data"); | |
110 var lastCommit = Number(lastCommitData[0].revision); | |
111 var earlierCommit = lastCommit - config.kNumberOfRecentCommits; | |
112 var url = config.kSvnLogURL + '?' + $.param({ | |
113 'url': config.kBlinkSvnURL, | |
114 'range': lastCommit + ':' + earlierCommit, | |
115 }); | |
116 | |
117 net.get(url, function(commitData) { | |
118 callback(parseCommitData(commitData)); | |
119 }); | |
120 | |
121 }); | |
122 }; | |
123 | |
124 trac.commitDataForRevisionRange = function(path, startRevision, endRevision, cal
lback) | |
125 { | |
126 var key = [path, startRevision, endRevision].join('\n'); | |
127 g_cache.get(key, callback); | |
128 }; | |
129 | |
130 })(); | |
OLD | NEW |