@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.

Support "changed filename" and "file content" fields for commit content Herald rules

Summary: Ref T4195. Adds support for diff content rules.

Test Plan: Pushed SVN and Git changes through, saw them generate reasonable transcripts. Mercurial still isn't hooked up to this phase.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4195

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

+103 -2
+39
src/applications/diffusion/engine/DiffusionCommitHookEngine.php
··· 885 885 ->setRejectDetails(null); 886 886 } 887 887 888 + public function loadChangesetsForCommit($identifier) { 889 + $vcs = $this->getRepository()->getVersionControlSystem(); 890 + switch ($vcs) { 891 + case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: 892 + case PhabricatorRepositoryType::REPOSITORY_TYPE_MERCURIAL: 893 + // For git and hg, we can use normal commands. 894 + $drequest = DiffusionRequest::newFromDictionary( 895 + array( 896 + 'repository' => $this->getRepository(), 897 + 'user' => $this->getViewer(), 898 + 'commit' => $identifier, 899 + )); 900 + $raw_diff = DiffusionRawDiffQuery::newFromDiffusionRequest($drequest) 901 + ->setTimeout(5 * 60) 902 + ->setLinesOfContext(0) 903 + ->loadRawDiff(); 904 + break; 905 + case PhabricatorRepositoryType::REPOSITORY_TYPE_SVN: 906 + // TODO: This diff has 3 lines of context, which produces slightly 907 + // incorrect "added file content" and "removed file content" results. 908 + // This may also choke on binaries, but "svnlook diff" does not support 909 + // the "--diff-cmd" flag. 910 + 911 + // For subversion, we need to use `svnlook`. 912 + list($raw_diff) = execx( 913 + 'svnlook diff -t %s %s', 914 + $this->subversionTransaction, 915 + $this->subversionRepository); 916 + break; 917 + default: 918 + throw new Exception(pht("Unknown VCS '%s!'", $vcs)); 919 + } 920 + 921 + $parser = new ArcanistDiffParser(); 922 + $changes = $parser->parseDiff($raw_diff); 923 + $diff = DifferentialDiff::newFromRawChanges($changes); 924 + return $diff->getChangesets(); 925 + } 926 + 888 927 }
+63 -1
src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
··· 4 4 5 5 private $log; 6 6 private $hookEngine; 7 + private $changesets; 7 8 8 9 public function setPushLog(PhabricatorRepositoryPushLog $log) { 9 10 $this->log = $log; ··· 35 36 public function getFields() { 36 37 return array_merge( 37 38 array( 39 + self::FIELD_BODY, 40 + self::FIELD_DIFF_FILE, 41 + self::FIELD_DIFF_CONTENT, 42 + self::FIELD_DIFF_ADDED_CONTENT, 43 + self::FIELD_DIFF_REMOVED_CONTENT, 38 44 self::FIELD_REPOSITORY, 39 45 self::FIELD_PUSHER, 40 46 self::FIELD_PUSHER_PROJECTS, ··· 78 84 public function getHeraldField($field) { 79 85 $log = $this->getObject(); 80 86 switch ($field) { 87 + case self::FIELD_DIFF_FILE: 88 + return $this->getDiffContent('name'); 89 + case self::FIELD_DIFF_CONTENT: 90 + return $this->getDiffContent('*'); 91 + case self::FIELD_DIFF_ADDED_CONTENT: 92 + return $this->getDiffContent('+'); 93 + case self::FIELD_DIFF_REMOVED_CONTENT: 94 + return $this->getDiffContent('-'); 81 95 case self::FIELD_REPOSITORY: 82 96 return $this->hookEngine->getRepository()->getPHID(); 83 97 case self::FIELD_PUSHER: ··· 88 102 89 103 return parent::getHeraldField($field); 90 104 } 91 - 92 105 93 106 public function applyHeraldEffects(array $effects) { 94 107 assert_instances_of($effects, 'HeraldEffect'); ··· 111 124 break; 112 125 default: 113 126 throw new Exception(pht('No rules to handle action "%s"!', $action)); 127 + } 128 + } 129 + 130 + return $result; 131 + } 132 + 133 + private function getDiffContent($type) { 134 + if ($this->changesets === null) { 135 + try { 136 + $this->changesets = $this->hookEngine->loadChangesetsForCommit( 137 + $this->log->getRefNew()); 138 + } catch (Exception $ex) { 139 + $this->changesets = $ex; 140 + } 141 + } 142 + 143 + if ($this->changesets instanceof Exception) { 144 + $ex_class = get_class($this->changesets); 145 + $ex_message = $this->changesets->getmessage(); 146 + if ($type === 'name') { 147 + return array("<{$ex_class}: {$ex_message}>"); 148 + } else { 149 + return array("<{$ex_class}>" => $ex_message); 150 + } 151 + } 152 + 153 + $result = array(); 154 + if ($type === 'name') { 155 + foreach ($this->changesets as $change) { 156 + $result[] = $change->getFilename(); 157 + } 158 + } else { 159 + foreach ($this->changesets as $change) { 160 + $lines = array(); 161 + foreach ($change->getHunks() as $hunk) { 162 + switch ($type) { 163 + case '-': 164 + $lines[] = $hunk->makeOldFile(); 165 + break; 166 + case '+': 167 + $lines[] = $hunk->makeNewFile(); 168 + break; 169 + case '*': 170 + default: 171 + $lines[] = $hunk->makeChanges(); 172 + break; 173 + } 174 + } 175 + $result[$change->getFilename()] = implode('', $lines); 114 176 } 115 177 } 116 178
+1 -1
src/applications/herald/storage/HeraldRule.php
··· 16 16 protected $ruleType; 17 17 protected $isDisabled = 0; 18 18 19 - protected $configVersion = 17; 19 + protected $configVersion = 18; 20 20 21 21 // phids for which this rule has been applied 22 22 private $ruleApplied = self::ATTACHABLE;