From 72c73d644b0ef5d5cf0b776c1b5c47681ac04605 Mon Sep 17 00:00:00 2001 From: epriestley <git@epriestley.com> Date: Fri, 20 Dec 2013 12:39:13 -0800 Subject: [PATCH] Add an "Accepted Differential revision" field to Commit and pre-commit Content Herald rules Summary: Refs T4195. Fixes T3936. You can't currently write rules like "block commits unless they're attached to an **accepted** revision"; allow that. Test Plan: Pushed commits into a rule with this field, saw it work / not crash. Reviewers: btrahan Reviewed By: btrahan CC: aran, mbishopim3 Maniphest Tasks: T3936, T4195 Differential Revision: https://secure.phabricator.com/D7807 --- .../herald/HeraldPreCommitContentAdapter.php | 11 +++++++++++ src/applications/herald/adapter/HeraldAdapter.php | 4 ++++ .../herald/adapter/HeraldCommitAdapter.php | 10 ++++++++++ 3 files changed, 25 insertions(+) diff --git a/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php b/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php index db9f478b34..50793ac941 100644 --- a/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php +++ b/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php @@ -50,6 +50,7 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter { self::FIELD_PUSHER, self::FIELD_PUSHER_PROJECTS, self::FIELD_DIFFERENTIAL_REVISION, + self::FIELD_DIFFERENTIAL_ACCEPTED, self::FIELD_DIFFERENTIAL_REVIEWERS, self::FIELD_DIFFERENTIAL_CCS, self::FIELD_RULE, @@ -118,6 +119,16 @@ final class HeraldPreCommitContentAdapter extends HeraldAdapter { return null; } return $revision->getPHID(); + case self::FIELD_DIFFERENTIAL_ACCEPTED: + $revision = $this->getRevision(); + if (!$revision) { + return null; + } + $status_accepted = ArcanistDifferentialRevisionStatus::ACCEPTED; + if ($revision->getStatus() != $status_accepted) { + return null; + } + return $revision->getPHID(); case self::FIELD_DIFFERENTIAL_REVIEWERS: $revision = $this->getRevision(); if (!$revision) { diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index 00cdb5e1de..d0eb235414 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -30,6 +30,7 @@ abstract class HeraldAdapter { const FIELD_DIFFERENTIAL_REVISION = 'differential-revision'; const FIELD_DIFFERENTIAL_REVIEWERS = 'differential-reviewers'; const FIELD_DIFFERENTIAL_CCS = 'differential-ccs'; + const FIELD_DIFFERENTIAL_ACCEPTED = 'differential-accepted'; const CONDITION_CONTAINS = 'contains'; const CONDITION_NOT_CONTAINS = '!contains'; @@ -169,6 +170,8 @@ abstract class HeraldAdapter { self::FIELD_DIFFERENTIAL_REVISION => pht('Differential revision'), self::FIELD_DIFFERENTIAL_REVIEWERS => pht('Differential reviewers'), self::FIELD_DIFFERENTIAL_CCS => pht('Differential CCs'), + self::FIELD_DIFFERENTIAL_ACCEPTED + => pht('Accepted Differential revision'), ); } @@ -284,6 +287,7 @@ abstract class HeraldAdapter { self::CONDITION_INCLUDE_NONE, ); case self::FIELD_DIFFERENTIAL_REVISION: + case self::FIELD_DIFFERENTIAL_ACCEPTED: return array( self::CONDITION_EXISTS, self::CONDITION_NOT_EXISTS, diff --git a/src/applications/herald/adapter/HeraldCommitAdapter.php b/src/applications/herald/adapter/HeraldCommitAdapter.php index ecc80ee264..8e30e855de 100644 --- a/src/applications/herald/adapter/HeraldCommitAdapter.php +++ b/src/applications/herald/adapter/HeraldCommitAdapter.php @@ -336,6 +336,16 @@ final class HeraldCommitAdapter extends HeraldAdapter { return null; } return $revision->getID(); + case self::FIELD_DIFFERENTIAL_ACCEPTED: + $revision = $this->loadDifferentialRevision(); + if (!$revision) { + return null; + } + $status_accepted = ArcanistDifferentialRevisionStatus::ACCEPTED; + if ($revision->getStatus() != $status_accepted) { + return null; + } + return $revision->getPHID(); case self::FIELD_DIFFERENTIAL_REVIEWERS: $revision = $this->loadDifferentialRevision(); if (!$revision) {