1 <!-- 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. 5 --> 6 7 <script> 8 function CTCommit() {} 9 10 CTCommit.create = function(author, message, baseUrl, repository) { 11 var commit = new CTCommit(); 12 var revision = CTCommit.findRevision(message); 13 commit.complete(author, message, revision); 14 commit.url = commit._url(baseUrl); 15 commit.repository = repository; 16 return commit; 17 } 18 19 // This is for cases where we can't get the commit data off the 20 // repository for some reason. 21 CTCommit.createIncomplete = function(baseUrl, revision, repository) { 22 var commit = new CTCommit(); 23 commit.revision = revision; 24 commit.url = commit._url(baseUrl); 25 commit.repository = repository; 26 return commit; 27 } 28 29 CTCommit.findRevision = function(message) { 30 var svnRegexp = /^git-svn-id:[^@]*@(\d+).*$/m; 31 var gitRegexp = /^Cr-Commit-Position\:\ refs\/heads\/master@\{#(\d+)\}.*$/m; 32 33 var match = svnRegexp.exec(message); 34 if (!match) 35 match = gitRegexp.exec(message); 36 37 if (match) 38 return parseInt(match[1], 10); 39 return null; 40 } 41 42 CTCommit.prototype.complete = function(author, message, revision) { 43 this.author = author; 44 this.message = message; 45 this.revision = revision; 46 this.summary = this._findSummary(); 47 this.isComplete = true; 48 } 49 50 CTCommit.prototype._url = function(baseUrl) { 51 return baseUrl.assign({revision: this.revision}); 52 } 53 54 CTCommit.prototype._findSummary = function() { 55 var index = this.message.indexOf('\n'); 56 return this.message.substring(0, index); 57 } 58 </script> 59