From 81e2a1cf6b22eccfec1a41ff07195352445bb050 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 1 Jan 2017 08:23:42 -0800 Subject: [PATCH] Always parse the first line of a commit message as a title Summary: Fixes T10312. If your first line is "Reviewers: xyz", it's a title, not a "Reviewers" field. Test Plan: Added unit test. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10312 Differential Revision: https://secure.phabricator.com/D17122 --- .../DifferentialCommitMessageParser.php | 28 +++++++++++++------ .../__tests__/messages/title-with-label.txt | 11 ++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 src/applications/differential/parser/__tests__/messages/title-with-label.txt diff --git a/src/applications/differential/parser/DifferentialCommitMessageParser.php b/src/applications/differential/parser/DifferentialCommitMessageParser.php index 4a5bf6a27b..7e5a50e61f 100644 --- a/src/applications/differential/parser/DifferentialCommitMessageParser.php +++ b/src/applications/differential/parser/DifferentialCommitMessageParser.php @@ -161,17 +161,27 @@ final class DifferentialCommitMessageParser extends Phobject { $field_map = array(); foreach ($lines as $key => $line) { - $match = null; - if (preg_match($label_regexp, $line, $match)) { - $lines[$key] = trim($match['text']); - $field = $label_map[self::normalizeFieldLabel($match['field'])]; - if (!empty($seen[$field])) { - $this->errors[] = pht( - 'Field "%s" occurs twice in commit message!', - $field); - } + // We always parse the first line of the message as a title, even if it + // contains something we recognize as a field header. + if (!isset($seen[$key_title])) { + $field = $key_title; + + $lines[$key] = trim($line); $seen[$field] = true; + } else { + $match = null; + if (preg_match($label_regexp, $line, $match)) { + $lines[$key] = trim($match['text']); + $field = $label_map[self::normalizeFieldLabel($match['field'])]; + if (!empty($seen[$field])) { + $this->errors[] = pht( + 'Field "%s" occurs twice in commit message!', + $match['field']); + } + $seen[$field] = true; + } } + $field_map[$key] = $field; } diff --git a/src/applications/differential/parser/__tests__/messages/title-with-label.txt b/src/applications/differential/parser/__tests__/messages/title-with-label.txt new file mode 100644 index 0000000000..dfbba96d14 --- /dev/null +++ b/src/applications/differential/parser/__tests__/messages/title-with-label.txt @@ -0,0 +1,11 @@ +color: orange +~~~~~~~~~~ +{ + "color": "color" +} +~~~~~~~~~~ +{ + "title": "color: orange" +} +~~~~~~~~~~ +[]