From d43bcdc1eece9f02ed07e5ef2532bd916af94679 Mon Sep 17 00:00:00 2001 From: Afaque Hussain Date: Tue, 19 Mar 2013 09:29:24 -0700 Subject: [PATCH] Adding pro tips to Differential commit message Summary: Randomly displaying tips about different features of arc. Test Plan: Will test by running arc diff and seeing if the tips appear in text-based UI of arc Reviewers: epriestley, AnhNhan Reviewed By: AnhNhan CC: aran, Korvin, AnhNhan Differential Revision: https://secure.phabricator.com/D5351 --- ...I_differential_getcommitmessage_Method.php | 23 +++++++++++++++++++ ...ifferentialDependsOnFieldSpecification.php | 7 ++++++ .../DifferentialFieldSpecification.php | 4 ++++ ...entialManiphestTasksFieldSpecification.php | 7 ++++++ 4 files changed, 41 insertions(+) diff --git a/src/applications/differential/conduit/ConduitAPI_differential_getcommitmessage_Method.php b/src/applications/differential/conduit/ConduitAPI_differential_getcommitmessage_Method.php index 9c4e7d7530..7bd90f6ca7 100644 --- a/src/applications/differential/conduit/ConduitAPI_differential_getcommitmessage_Method.php +++ b/src/applications/differential/conduit/ConduitAPI_differential_getcommitmessage_Method.php @@ -48,9 +48,12 @@ final class ConduitAPI_differential_getcommitmessage_Method $aux_fields = DifferentialFieldSelector::newSelector() ->getFieldSpecifications(); + $pro_tips = array(); + foreach ($aux_fields as $key => $aux_field) { $aux_field->setUser($request->getUser()); $aux_field->setRevision($revision); + $pro_tips[] = $aux_field->getCommitMessageTips(); if (!$aux_field->shouldAppearOnCommitMessage()) { unset($aux_fields[$key]); } @@ -125,6 +128,26 @@ final class ConduitAPI_differential_getcommitmessage_Method } } } + + if ($is_edit) { + $pro_tips = array_mergev($pro_tips); + + if (!empty($pro_tips)) { + shuffle($pro_tips); + $pro_tip = "Tip: ".$pro_tips[0]; + $pro_tip = wordwrap($pro_tip, 78, "\n", true); + + $lines = explode("\n", $pro_tip); + + foreach ($lines as $key => $line) { + $lines[$key] = "# ".$line; + } + + $pro_tip = implode("\n", $lines); + $commit_message[] = $pro_tip; + } + } + $commit_message = implode("\n\n", $commit_message); return $commit_message; diff --git a/src/applications/differential/field/specification/DifferentialDependsOnFieldSpecification.php b/src/applications/differential/field/specification/DifferentialDependsOnFieldSpecification.php index 0c312854d4..af57c4a186 100644 --- a/src/applications/differential/field/specification/DifferentialDependsOnFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialDependsOnFieldSpecification.php @@ -47,4 +47,11 @@ final class DifferentialDependsOnFieldSpecification return 'phabricator:depends-on'; } + public function getCommitMessageTips() { + return array( + 'Use "Depends on D123" in your summary to mark '. + 'a dependency between revisions.' + ); + } + } diff --git a/src/applications/differential/field/specification/DifferentialFieldSpecification.php b/src/applications/differential/field/specification/DifferentialFieldSpecification.php index 3521998248..6041f05763 100644 --- a/src/applications/differential/field/specification/DifferentialFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialFieldSpecification.php @@ -667,6 +667,10 @@ abstract class DifferentialFieldSpecification { return; } + public function getCommitMessageTips() { + return array(); + } + /* -( Loading Additional Data )-------------------------------------------- */ diff --git a/src/applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php b/src/applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php index dad5bf54d3..c77a3d3965 100644 --- a/src/applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php @@ -173,4 +173,11 @@ final class DifferentialManiphestTasksFieldSpecification return implode("\n", $body); } + public function getCommitMessageTips() { + return array( + 'Use "Fixes T123" in your summary to mark that the current '. + 'revision completes a given task.' + ); + } + }