Differential D25028 Diff 81 src/applications/differential/conduit/DifferentialGetCommitMessageConduitAPIMethod.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/conduit/DifferentialGetCommitMessageConduitAPIMethod.php
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | foreach ($field_list as $field_key => $field) { | ||||
// from, so we hit the same validation logic for values which came over | // from, so we hit the same validation logic for values which came over | ||||
// the wire and which we generated. | // the wire and which we generated. | ||||
$field_value = $field->readFieldValueFromConduit($field_value); | $field_value = $field->readFieldValueFromConduit($field_value); | ||||
$value_map[$field_key] = $field_value; | $value_map[$field_key] = $field_value; | ||||
} | } | ||||
$key_title = DifferentialTitleCommitMessageField::FIELDKEY; | $key_title = DifferentialTitleCommitMessageField::FIELDKEY; | ||||
$key_co_authors = DifferentialCoAuthorsCommitMessageField::FIELDKEY; | |||||
$commit_message = array(); | $commit_message = array(); | ||||
foreach ($field_list as $field_key => $field) { | foreach ($field_list as $field_key => $field) { | ||||
$label = $field->getFieldName(); | $label = $field->getFieldName(); | ||||
$wire_value = $value_map[$field_key]; | $wire_value = $value_map[$field_key]; | ||||
$value = $field->renderFieldValue($wire_value); | $value = $field->renderFieldValue($wire_value); | ||||
$is_template = ($is_create && $field->isTemplateField()); | $is_template = ($is_create && $field->isTemplateField()); | ||||
if (!is_string($value) && !is_null($value)) { | if (!is_string($value) && !is_null($value)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Commit message field "%s" was expected to render a string or '. | 'Commit message field "%s" was expected to render a string or '. | ||||
'null value, but rendered a "%s" instead.', | 'null value, but rendered a "%s" instead.', | ||||
$field->getFieldKey(), | $field->getFieldKey(), | ||||
gettype($value))); | gettype($value))); | ||||
} | } | ||||
$is_title = ($field_key == $key_title); | $is_title = ($field_key == $key_title); | ||||
$is_co_authors = ($field_key == $key_co_authors); | |||||
if (!strlen($value)) { | if (!strlen($value)) { | ||||
if ($is_template) { | if ($is_template) { | ||||
$commit_message[] = $label.': '; | $commit_message[] = $label.': '; | ||||
} | } | ||||
} else { | } else { | ||||
if ($is_title) { | if ($is_title || $is_co_authors) { | ||||
avivey: Can we have the `Co-authored-by` title as the `label` for the field, and let this field go… | |||||
$commit_message[] = $value; | $commit_message[] = $value; | ||||
} else { | } else { | ||||
$value = str_replace( | $value = str_replace( | ||||
array("\r\n", "\r"), | array("\r\n", "\r"), | ||||
array("\n", "\n"), | array("\n", "\n"), | ||||
$value); | $value); | ||||
if (strpos($value, "\n") !== false || substr($value, 0, 2) === ' ') { | if (strpos($value, "\n") !== false || substr($value, 0, 2) === ' ') { | ||||
$commit_message[] = "{$label}:\n{$value}"; | $commit_message[] = "{$label}:\n{$value}"; | ||||
Show All 37 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0
Can we have the Co-authored-by title as the label for the field, and let this field go through the regular code-path her (the else)?
I'd like to avoid special cases as much as possible, to allow more extensions - ideally, I want installs to be able to add other footers based on the same logic as custom extensions.
That probably means we need to allow (1) multiple instances of the same CommitMessageField and (2) make sure we somehow control the order of fields in $field_list (which we might already do? It looks like something is forcing title to be first).