@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a "branches" rule for Herald commit rules

Summary:
Fixes T4195. Allows you to write a rule against a commit's branches.

This completes outstanding work on T4195.

Test Plan: Pushed to Git and Mercurial repositories and verified branches were selected correctly by examining transcripts.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4195

Differential Revision: https://secure.phabricator.com/D7820

+39
+29
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
··· 26 26 private $transactionKey; 27 27 private $mercurialHook; 28 28 private $mercurialCommits = array(); 29 + private $gitCommits = array(); 29 30 30 31 private $heraldViewerProjects; 31 32 ··· 427 428 $merge_base = rtrim($stdout, "\n"); 428 429 } 429 430 431 + $ref_update = $ref_updates[$key]; 430 432 $ref_update->setMergeBase($merge_base); 431 433 } 432 434 ··· 525 527 526 528 $commits = phutil_split_lines($stdout, $retain_newlines = false); 527 529 530 + // If we're looking at a branch, mark all of the new commits as on that 531 + // branch. It's only possible for these commits to be on updated branches, 532 + // since any other branch heads are necessarily behind them. 533 + $branch_name = null; 534 + $ref_update = $ref_updates[$key]; 535 + $type_branch = PhabricatorRepositoryPushLog::REFTYPE_BRANCH; 536 + if ($ref_update->getRefType() == $type_branch) { 537 + $branch_name = $ref_update->getRefName(); 538 + } 539 + 528 540 foreach ($commits as $commit) { 541 + if ($branch_name) { 542 + $this->gitCommits[$commit][] = $branch_name; 543 + } 529 544 $content_updates[$commit] = $this->newPushLog() 530 545 ->setRefType(PhabricatorRepositoryPushLog::REFTYPE_COMMIT) 531 546 ->setRefNew($commit) ··· 970 985 break; 971 986 default: 972 987 throw new Exception(pht("Unknown VCS '%s!'", $vcs)); 988 + } 989 + } 990 + 991 + public function loadBranches($identifier) { 992 + $repository = $this->getRepository(); 993 + $vcs = $repository->getVersionControlSystem(); 994 + switch ($vcs) { 995 + case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 996 + return idx($this->gitCommits, $identifier, array()); 997 + case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: 998 + return idx($this->mercurialCommits, $identifier, array()); 999 + case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 1000 + // Subversion doesn't have branches. 1001 + return array(); 973 1002 } 974 1003 } 975 1004
+7
src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
··· 42 42 self::FIELD_BODY, 43 43 self::FIELD_AUTHOR, 44 44 self::FIELD_COMMITTER, 45 + self::FIELD_BRANCHES, 45 46 self::FIELD_DIFF_FILE, 46 47 self::FIELD_DIFF_CONTENT, 47 48 self::FIELD_DIFF_ADDED_CONTENT, ··· 100 101 return $this->getAuthorPHID(); 101 102 case self::FIELD_COMMITTER: 102 103 return $this->getCommitterPHID(); 104 + case self::FIELD_BRANCHES: 105 + return $this->getBranches(); 103 106 case self::FIELD_DIFF_FILE: 104 107 return $this->getDiffContent('name'); 105 108 case self::FIELD_DIFF_CONTENT: ··· 327 330 // ancestry is in Git/Mercurial. 328 331 return false; 329 332 } 333 + } 334 + 335 + private function getBranches() { 336 + return $this->hookEngine->loadBranches($this->log->getRefNew()); 330 337 } 331 338 332 339 }
+3
src/applications/herald/adapter/HeraldAdapter.php
··· 33 33 const FIELD_DIFFERENTIAL_CCS = 'differential-ccs'; 34 34 const FIELD_DIFFERENTIAL_ACCEPTED = 'differential-accepted'; 35 35 const FIELD_IS_MERGE_COMMIT = 'is-merge-commit'; 36 + const FIELD_BRANCHES = 'branches'; 36 37 37 38 const CONDITION_CONTAINS = 'contains'; 38 39 const CONDITION_NOT_CONTAINS = '!contains'; ··· 178 179 self::FIELD_DIFFERENTIAL_ACCEPTED 179 180 => pht('Accepted Differential revision'), 180 181 self::FIELD_IS_MERGE_COMMIT => pht('Commit is a merge'), 182 + self::FIELD_BRANCHES => pht('Commit\'s branches'), 181 183 ); 182 184 } 183 185 ··· 255 257 self::CONDITION_NOT_EXISTS, 256 258 ); 257 259 case self::FIELD_DIFF_FILE: 260 + case self::FIELD_BRANCHES: 258 261 return array( 259 262 self::CONDITION_CONTAINS, 260 263 self::CONDITION_REGEXP,