2011-02-09 18:41:26 +01:00
|
|
|
<?php
|
|
|
|
|
Rename Conduit classes
Summary: Ref T5655. Rename Conduit classes and provide a `getAPIMethodName` method to declare the API method.
Test Plan:
```
> echo '{}' | arc --conduit-uri='http://phabricator.joshuaspence.com' call-conduit user.whoami
Waiting for JSON parameters on stdin...
{"error":null,"errorMessage":null,"response":{"phid":"PHID-USER-lioqffnwn6y475mu5ndb","userName":"josh","realName":"Joshua Spence","image":"http:\/\/phabricator.joshuaspence.com\/res\/1404425321T\/phabricator\/3eb28cd9\/rsrc\/image\/avatar.png","uri":"http:\/\/phabricator.joshuaspence.com\/p\/josh\/","roles":["admin","verified","approved","activated"]}}
```
Reviewers: epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: epriestley, Korvin, hach-que
Maniphest Tasks: T5655
Differential Revision: https://secure.phabricator.com/D9991
2014-07-25 02:54:15 +02:00
|
|
|
final class DifferentialGetCommitMessageConduitAPIMethod
|
|
|
|
extends DifferentialConduitAPIMethod {
|
|
|
|
|
|
|
|
public function getAPIMethodName() {
|
|
|
|
return 'differential.getcommitmessage';
|
|
|
|
}
|
2011-02-09 18:41:26 +01:00
|
|
|
|
|
|
|
public function getMethodDescription() {
|
2014-06-09 20:36:49 +02:00
|
|
|
return 'Retrieve Differential commit messages or message templates.';
|
2011-02-09 18:41:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function defineParamTypes() {
|
2014-05-15 06:59:03 +02:00
|
|
|
$edit_types = array('edit', 'create');
|
|
|
|
|
2011-02-09 18:41:26 +01:00
|
|
|
return array(
|
2011-12-02 01:01:48 +01:00
|
|
|
'revision_id' => 'optional revision_id',
|
2011-03-05 02:03:59 +01:00
|
|
|
'fields' => 'optional dict<string, wild>',
|
2014-05-15 06:59:03 +02:00
|
|
|
'edit' => 'optional '.$this->formatStringConstants($edit_types),
|
2011-02-09 18:41:26 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineReturnType() {
|
|
|
|
return 'nonempty string';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function defineErrorTypes() {
|
|
|
|
return array(
|
|
|
|
'ERR_NOT_FOUND' => 'Revision was not found.',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(ConduitAPIRequest $request) {
|
|
|
|
$id = $request->getValue('revision_id');
|
2013-10-09 22:58:00 +02:00
|
|
|
$viewer = $request->getUser();
|
2011-02-09 18:41:26 +01:00
|
|
|
|
2011-12-02 01:01:48 +01:00
|
|
|
if ($id) {
|
2013-07-15 12:29:12 +02:00
|
|
|
$revision = id(new DifferentialRevisionQuery())
|
|
|
|
->withIDs(array($id))
|
2013-10-09 22:58:00 +02:00
|
|
|
->setViewer($viewer)
|
2013-07-15 12:29:12 +02:00
|
|
|
->needReviewerStatus(true)
|
2014-03-08 02:05:00 +01:00
|
|
|
->needActiveDiffs(true)
|
2013-07-15 12:29:12 +02:00
|
|
|
->executeOne();
|
2011-12-02 01:01:48 +01:00
|
|
|
if (!$revision) {
|
|
|
|
throw new ConduitException('ERR_NOT_FOUND');
|
|
|
|
}
|
|
|
|
} else {
|
2013-10-09 22:58:00 +02:00
|
|
|
$revision = DifferentialRevision::initializeNewRevision($viewer);
|
2014-03-08 02:05:00 +01:00
|
|
|
$revision->attachReviewerStatus(array());
|
|
|
|
$revision->attachActiveDiff(null);
|
2011-02-09 18:41:26 +01:00
|
|
|
}
|
|
|
|
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
$is_edit = $request->getValue('edit');
|
2012-02-29 01:56:19 +01:00
|
|
|
$is_create = ($is_edit == 'create');
|
2011-02-09 18:41:26 +01:00
|
|
|
|
2014-03-08 02:05:00 +01:00
|
|
|
$field_list = PhabricatorCustomField::getObjectFields(
|
|
|
|
$revision,
|
|
|
|
($is_edit
|
|
|
|
? DifferentialCustomField::ROLE_COMMITMESSAGEEDIT
|
|
|
|
: DifferentialCustomField::ROLE_COMMITMESSAGE));
|
2013-03-19 17:29:24 +01:00
|
|
|
|
2014-03-08 02:05:00 +01:00
|
|
|
$field_list
|
|
|
|
->setViewer($viewer)
|
|
|
|
->readFieldsFromStorage($revision);
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
|
2014-03-08 02:05:00 +01:00
|
|
|
$field_map = mpull($field_list->getFields(), null, 'getFieldKeyForConduit');
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
|
|
|
|
if ($is_edit) {
|
2014-03-08 02:05:00 +01:00
|
|
|
$fields = $request->getValue('fields', array());
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
foreach ($fields as $field => $value) {
|
2014-03-08 02:05:00 +01:00
|
|
|
$custom_field = idx($field_map, $field);
|
|
|
|
if (!$custom_field) {
|
2014-03-13 01:24:58 +01:00
|
|
|
// Just ignore this, these workflows don't make strong distictions
|
|
|
|
// about field editability on the client side.
|
|
|
|
continue;
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
}
|
2012-02-29 01:56:19 +01:00
|
|
|
if ($is_create ||
|
2014-03-08 02:05:00 +01:00
|
|
|
$custom_field->shouldOverwriteWhenCommitMessageIsEdited()) {
|
|
|
|
$custom_field->readValueFromCommitMessage($value);
|
2011-03-05 02:03:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-08 02:05:00 +01:00
|
|
|
$phids = array();
|
|
|
|
foreach ($field_list->getFields() as $key => $field) {
|
|
|
|
$field_phids = $field->getRequiredHandlePHIDsForCommitMessage();
|
|
|
|
if (!is_array($field_phids)) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'Custom field "%s" was expected to return an array of handle '.
|
|
|
|
'PHIDs required for commit message rendering, but returned "%s" '.
|
|
|
|
'instead.',
|
|
|
|
$field->getFieldKey(),
|
|
|
|
gettype($field_phids)));
|
|
|
|
}
|
|
|
|
$phids[$key] = $field_phids;
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
}
|
2014-03-08 02:05:00 +01:00
|
|
|
|
|
|
|
$all_phids = array_mergev($phids);
|
|
|
|
if ($all_phids) {
|
|
|
|
$all_handles = id(new PhabricatorHandleQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withPHIDs($all_phids)
|
|
|
|
->execute();
|
|
|
|
} else {
|
|
|
|
$all_handles = array();
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
}
|
|
|
|
|
2014-03-08 02:05:00 +01:00
|
|
|
$key_title = id(new DifferentialTitleField())->getFieldKey();
|
|
|
|
$default_title = DifferentialTitleField::getDefaultTitle();
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
|
|
|
|
$commit_message = array();
|
2014-03-08 02:05:00 +01:00
|
|
|
foreach ($field_list->getFields() as $key => $field) {
|
|
|
|
$handles = array_select_keys($all_handles, $phids[$key]);
|
|
|
|
|
|
|
|
$label = $field->renderCommitMessageLabel();
|
|
|
|
$value = $field->renderCommitMessageValue($handles);
|
|
|
|
|
|
|
|
if (!is_string($value) && !is_null($value)) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'Custom field "%s" was expected to render a string or null value, '.
|
|
|
|
'but rendered a "%s" instead.',
|
|
|
|
$field->getFieldKey(),
|
|
|
|
gettype($value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
$is_title = ($key == $key_title);
|
|
|
|
|
2011-12-17 01:31:02 +01:00
|
|
|
if (!strlen($value)) {
|
2014-03-08 02:05:00 +01:00
|
|
|
if ($is_title) {
|
|
|
|
$commit_message[] = $default_title;
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
} else {
|
2014-03-08 02:05:00 +01:00
|
|
|
if ($is_edit && $field->shouldAppearInCommitMessageTemplate()) {
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
$commit_message[] = $label.': ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-03-08 02:05:00 +01:00
|
|
|
if ($is_title) {
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
$commit_message[] = $value;
|
|
|
|
} else {
|
|
|
|
$value = str_replace(
|
|
|
|
array("\r\n", "\r"),
|
|
|
|
array("\n", "\n"),
|
|
|
|
$value);
|
2012-03-29 21:23:21 +02:00
|
|
|
if (strpos($value, "\n") !== false || substr($value, 0, 2) === ' ') {
|
Drive commit message rendering from field specifications
Summary:
When rendering commit messages, drive all the logic through field specification
classes instead of the hard-coded DifferentialCommitMessageData class. This
removes DifferentialCommitMessageData and support classes.
Note that this effectively reverts D546, and will cause a minor break for
Facebook (Task IDs will no longer render in commit messages generated by "arc
amend", and will not be editable via "arc diff --edit"). This can be resolved by
implementing the feature as a custom field. While I've been able to preserve the
task ID functionality elsewhere, I felt this implementation was too complex to
reasonably leave hooks for, and the break is pretty minor.
Test Plan:
- Made numerous calls to differential.getcommitmessage across many diffs in
various states, with and without 'edit' and with and without various field
overrides.
- General behavior seems correct (messages look accurate, and have the
expected information). Special fields like "Reviewed By" and "git-svn-id" seem
to work correctly.
- Edit behavior seems correct (edit mode shows all editable fields, hides
fields like "Reviewed By").
- Field overwrite behavior seems correct (overwritable fields show the correct
values when overwritten, ignore provided values otherwise).
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 814
2011-08-16 06:06:58 +02:00
|
|
|
$commit_message[] = "{$label}:\n{$value}";
|
|
|
|
} else {
|
|
|
|
$commit_message[] = "{$label}: {$value}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-19 17:29:24 +01:00
|
|
|
|
|
|
|
if ($is_edit) {
|
2014-03-08 02:05:00 +01:00
|
|
|
$tip = $this->getProTip($field_list);
|
|
|
|
if ($tip !== null) {
|
|
|
|
$commit_message[] = "\n".$tip;
|
|
|
|
}
|
|
|
|
}
|
2013-03-19 17:29:24 +01:00
|
|
|
|
2014-03-08 02:05:00 +01:00
|
|
|
$commit_message = implode("\n\n", $commit_message);
|
2013-03-19 17:29:24 +01:00
|
|
|
|
2014-03-08 02:05:00 +01:00
|
|
|
return $commit_message;
|
|
|
|
}
|
2013-03-19 17:29:24 +01:00
|
|
|
|
2014-03-08 02:05:00 +01:00
|
|
|
private function getProTip() {
|
|
|
|
// Any field can provide tips, whether it normally appears on commit
|
|
|
|
// messages or not.
|
|
|
|
$field_list = PhabricatorCustomField::getObjectFields(
|
|
|
|
new DifferentialRevision(),
|
|
|
|
PhabricatorCustomField::ROLE_DEFAULT);
|
2013-03-19 17:29:24 +01:00
|
|
|
|
2014-03-08 02:05:00 +01:00
|
|
|
$tips = array();
|
|
|
|
foreach ($field_list->getFields() as $key => $field) {
|
|
|
|
$tips[] = $field->getProTips();
|
2013-03-19 17:29:24 +01:00
|
|
|
}
|
2014-03-08 02:05:00 +01:00
|
|
|
$tips = array_mergev($tips);
|
2013-03-19 17:29:24 +01:00
|
|
|
|
2014-03-08 02:05:00 +01:00
|
|
|
if (!$tips) {
|
|
|
|
return null;
|
|
|
|
}
|
2011-02-09 18:41:26 +01:00
|
|
|
|
2014-03-08 02:05:00 +01:00
|
|
|
shuffle($tips);
|
|
|
|
|
|
|
|
$tip = pht('Tip: %s', head($tips));
|
|
|
|
$tip = wordwrap($tip, 78, "\n", true);
|
|
|
|
|
|
|
|
$lines = explode("\n", $tip);
|
|
|
|
foreach ($lines as $key => $line) {
|
2014-06-09 20:36:49 +02:00
|
|
|
$lines[$key] = '# '.$line;
|
2014-03-08 02:05:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return implode("\n", $lines);
|
2011-02-09 18:41:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|