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() {
|
2015-05-22 09:27:56 +02:00
|
|
|
return pht('Retrieve Differential commit messages or message templates.');
|
2011-02-09 18:41:26 +01:00
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected 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
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineReturnType() {
|
2011-02-09 18:41:26 +01:00
|
|
|
return 'nonempty string';
|
|
|
|
}
|
|
|
|
|
2015-04-13 00:59:07 +02:00
|
|
|
protected function defineErrorTypes() {
|
2011-02-09 18:41:26 +01:00
|
|
|
return array(
|
2015-05-22 09:27:56 +02:00
|
|
|
'ERR_NOT_FOUND' => pht('Revision was not found.'),
|
2011-02-09 18:41:26 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2011-02-09 18:41:26 +01:00
|
|
|
}
|
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
$edit_mode = $request->getValue('edit');
|
|
|
|
$is_create = ($edit_mode == 'create');
|
|
|
|
$is_edit = ($edit_mode && !$is_create);
|
2011-02-09 18:41:26 +01:00
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
$field_list = DifferentialCommitMessageField::newEnabledFields($viewer);
|
2013-03-19 17:29:24 +01:00
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
$custom_storage = $this->loadCustomFieldStorage($viewer, $revision);
|
|
|
|
foreach ($field_list as $field) {
|
|
|
|
$field->setCustomFieldStorage($custom_storage);
|
|
|
|
}
|
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
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
// If we're editing the message, remove fields like "Conflicts" and
|
|
|
|
// "git-svn-id" which should not be presented to the user for editing.
|
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) {
|
2016-12-15 19:11:58 +01:00
|
|
|
foreach ($field_list as $field_key => $field) {
|
|
|
|
if (!$field->isFieldEditable()) {
|
|
|
|
unset($field_list[$field_key]);
|
2011-03-05 02:03:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
$overrides = $request->getValue('fields', array());
|
|
|
|
|
|
|
|
$value_map = array();
|
|
|
|
foreach ($field_list as $field_key => $field) {
|
|
|
|
if (array_key_exists($field_key, $overrides)) {
|
|
|
|
$field_value = $overrides[$field_key];
|
|
|
|
} else {
|
|
|
|
$field_value = $field->readFieldValueFromObject($revision);
|
2014-03-08 02:05:00 +01:00
|
|
|
}
|
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
// We're calling this method on the value no matter where we got it
|
|
|
|
// from, so we hit the same validation logic for values which came over
|
|
|
|
// the wire and which we generated.
|
|
|
|
$field_value = $field->readFieldValueFromConduit($field_value);
|
|
|
|
|
|
|
|
$value_map[$field_key] = $field_value;
|
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
|
|
|
}
|
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
$key_title = DifferentialTitleCommitMessageField::FIELDKEY;
|
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();
|
2016-12-15 19:11:58 +01:00
|
|
|
foreach ($field_list as $field_key => $field) {
|
|
|
|
$label = $field->getFieldName();
|
|
|
|
$wire_value = $value_map[$field_key];
|
|
|
|
$value = $field->renderFieldValue($wire_value);
|
2014-03-08 02:05:00 +01:00
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
$is_template = ($is_edit && $field->isTemplateField());
|
2014-03-08 02:05:00 +01:00
|
|
|
|
|
|
|
if (!is_string($value) && !is_null($value)) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
2016-12-15 19:11:58 +01:00
|
|
|
'Commit message field "%s" was expected to render a string or '.
|
|
|
|
'null value, but rendered a "%s" instead.',
|
2014-03-08 02:05:00 +01:00
|
|
|
$field->getFieldKey(),
|
|
|
|
gettype($value)));
|
|
|
|
}
|
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
$is_title = ($field_key == $key_title);
|
2014-03-08 02:05:00 +01:00
|
|
|
|
2011-12-17 01:31:02 +01:00
|
|
|
if (!strlen($value)) {
|
2016-12-15 19:11:58 +01:00
|
|
|
if ($is_template) {
|
|
|
|
$commit_message[] = $label.': ';
|
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_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
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
return implode("\n\n", $commit_message);
|
2014-03-08 02:05:00 +01:00
|
|
|
}
|
2013-03-19 17:29:24 +01:00
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
private function loadCustomFieldStorage(
|
|
|
|
PhabricatorUser $viewer,
|
|
|
|
DifferentialRevision $revision) {
|
|
|
|
$custom_field_list = PhabricatorCustomField::getObjectFields(
|
|
|
|
$revision,
|
|
|
|
DifferentialCustomField::ROLE_COMMITMESSAGE);
|
|
|
|
$custom_field_list
|
|
|
|
->setViewer($viewer)
|
|
|
|
->readFieldsFromStorage($revision);
|
2014-03-08 02:05:00 +01:00
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
$custom_field_map = array();
|
|
|
|
foreach ($custom_field_list->getFields() as $custom_field) {
|
|
|
|
if (!$custom_field->shouldUseStorage()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$custom_field_key = $custom_field->getFieldKey();
|
|
|
|
$custom_field_value = $custom_field->getValueForStorage();
|
|
|
|
$custom_field_map[$custom_field_key] = $custom_field_value;
|
2014-03-08 02:05:00 +01:00
|
|
|
}
|
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
return $custom_field_map;
|
2011-02-09 18:41:26 +01:00
|
|
|
}
|
|
|
|
|
2016-12-15 19:11:58 +01:00
|
|
|
|
2011-02-09 18:41:26 +01:00
|
|
|
}
|