Skip to content

Commit 3c785cd

Browse files
author
mgummelt
committed
include task ids in the commit messages returned by "arc amend"
Summary: when "arc diff" generates a revision, it attaches a task id if one is included. However, "arc amend" did not return a task id, effectively stripping it from the commit message. This diff fixes that. NOTE: This is dependent on revision 549 https://secure.phabricator.com/D549 Test Plan: 0. created a custom class to append Facebook task IDs to commit messages and attached it to the differential.append-commit-message-class config variable 1. created a new diff in the www repot 2. included Task ID: 609350 in the git commit message 3. "arc diff" to generate the revision 4. "arc amend" 5. ensure that the "Task ID:" field remained in the git commit message Reviewed By: epriestley Reviewers: dpepper, jungejason, epriestley CC: aran, epriestley, mgummelt Differential Revision: 546
1 parent ae78ea3 commit 3c785cd

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

conf/default.conf.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@
355355
'/.*/' => 80,
356356
),
357357

358+
// Class for appending custom fields to be included in the commit
359+
// messages generated by "arc amend". Should inherit
360+
// DifferentialCommitMessageModifier
361+
'differential.modify-commit-message-class' => null,
362+
363+
358364
// -- Maniphest ------------------------------------------------------------- //
359365

360366
'maniphest.enabled' => true,

src/__phutil_library_map__.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
'DifferentialCommitMessage' => 'applications/differential/parser/commitmessage',
141141
'DifferentialCommitMessageData' => 'applications/differential/data/commitmessage',
142142
'DifferentialCommitMessageField' => 'applications/differential/data/commitmessage',
143+
'DifferentialCommitMessageModifier' => 'applications/differential/data/commitmessage',
143144
'DifferentialCommitMessageParserException' => 'applications/differential/parser/commitmessage/exception',
144145
'DifferentialController' => 'applications/differential/controller/base',
145146
'DifferentialDAO' => 'applications/differential/storage/base',

src/applications/differential/data/commitmessage/DifferentialCommitMessageData.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ public function prepare() {
154154
$fields[] = new DifferentialCommitMessageField('Differential Revision',
155155
$revision->getID());
156156

157+
// append custom commit message fields
158+
$modify_class = PhabricatorEnv::getEnvConfig(
159+
'differential.modify-commit-message-class');
160+
161+
if ($modify_class) {
162+
$modifier = newv($modify_class, array($revision));
163+
$fields = $modifier->modifyFields($fields);
164+
}
165+
157166
$this->fields = $fields;
158167
}
159168

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2011 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
abstract class DifferentialCommitMessageModifier {
20+
protected $revision;
21+
22+
/**
23+
* @param DifferentialRevision The revision to generate fields for
24+
*/
25+
public function __construct(DifferentialRevision $revision) {
26+
$this->revision = $revision;
27+
}
28+
29+
/**
30+
* Implementation of this function should remove, modify, or append
31+
* fields to the $fields representing the fields for the given
32+
* $revision. It should return the modified dict. These fields are
33+
* included in the commit message generated by 'arc amend'.
34+
*
35+
* @param array The array of fields to modify
36+
* @return array The updated array of fields
37+
*/
38+
abstract public function modifyFields(array $fields);
39+
}

src/applications/differential/data/commitmessage/__init__.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
phutil_require_module('phabricator', 'applications/differential/constants/action');
1010
phutil_require_module('phabricator', 'applications/differential/storage/comment');
1111
phutil_require_module('phabricator', 'applications/phid/handle/data');
12+
phutil_require_module('phabricator', 'infrastructure/env');
1213

14+
phutil_require_module('phutil', 'symbols');
1315
phutil_require_module('phutil', 'utils');
1416

1517

1618
phutil_require_source('DifferentialCommitMessageData.php');
1719
phutil_require_source('DifferentialCommitMessageField.php');
20+
phutil_require_source('DifferentialCommitMessageModifier.php');

0 commit comments

Comments
 (0)