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.
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;
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;
29 CTCommit.findRevision = function(message) {
30 var svnRegexp = /^git-svn-id:[^@]*@(\d+).*$/m;
31 var gitRegexp = /^Cr-Commit-Position\:\ refs\/heads\/master@\{#(\d+)\}.*$/m;
33 var match = svnRegexp.exec(message);
35 match = gitRegexp.exec(message);
38 return parseInt(match[1], 10);
42 CTCommit.prototype.complete = function(author, message, revision) {
44 this.message = message;
45 this.revision = revision;
46 this.summary = this._findSummary();
47 this.isComplete = true;
50 CTCommit.prototype._url = function(baseUrl) {
51 return baseUrl.assign({revision: this.revision});
54 CTCommit.prototype._findSummary = function() {
55 var index = this.message.indexOf('\n');
56 return this.message.substring(0, index);