@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<?php
2
3final class PhabricatorRepositoryPublisher
4 extends Phobject {
5
6 private $repository;
7
8 const HOLD_IMPORTING = 'auto/importing';
9 const HOLD_PUBLISHING_DISABLED = 'auto/disabled';
10 const HOLD_REF_NOT_BRANCH = 'not-branch';
11 const HOLD_NOT_REACHABLE_FROM_PERMANENT_REF = 'auto/nobranch';
12 const HOLD_UNTRACKED = 'auto/notrack';
13 const HOLD_NOT_PERMANENT_REF = 'auto/noclose';
14
15 public function setRepository(PhabricatorRepository $repository) {
16 $this->repository = $repository;
17 return $this;
18 }
19
20 public function getRepository() {
21 if (!$this->repository) {
22 throw new PhutilInvalidStateException('setRepository');
23 }
24 return $this->repository;
25 }
26
27/* -( Publishing )--------------------------------------------------------- */
28
29 public function shouldPublishRepository() {
30 return !$this->getRepositoryHoldReasons();
31 }
32
33 public function shouldPublishRef(DiffusionRepositoryRef $ref) {
34 return !$this->getRefHoldReasons($ref);
35 }
36
37 public function shouldPublishCommit(PhabricatorRepositoryCommit $commit) {
38 return !$this->getCommitHoldReasons($commit);
39 }
40
41 public function isPermanentRef(DiffusionRepositoryRef $ref) {
42 return !$this->getRefImpermanentReasons($ref);
43 }
44
45/* -( Hold Reasons )------------------------------------------------------- */
46
47 public function getRepositoryHoldReasons() {
48 $repository = $this->getRepository();
49
50 $reasons = array();
51 if ($repository->isImporting()) {
52 $reasons[] = self::HOLD_IMPORTING;
53 }
54
55 if ($repository->isPublishingDisabled()) {
56 $reasons[] = self::HOLD_PUBLISHING_DISABLED;
57 }
58
59 return $reasons;
60 }
61
62 public function getRefHoldReasons(DiffusionRepositoryRef $ref) {
63 $repository = $this->getRepository();
64 $reasons = $this->getRepositoryHoldReasons();
65
66 foreach ($this->getRefImpermanentReasons($ref) as $reason) {
67 $reasons[] = $reason;
68 }
69
70 return $reasons;
71 }
72
73 public function getCommitHoldReasons(PhabricatorRepositoryCommit $commit) {
74 $repository = $this->getRepository();
75 $reasons = $this->getRepositoryHoldReasons();
76
77 if ($repository->isGit()) {
78 if (!$commit->isPermanentCommit()) {
79 $reasons[] = self::HOLD_NOT_REACHABLE_FROM_PERMANENT_REF;
80 }
81 }
82
83 return $reasons;
84 }
85
86 public function getRefImpermanentReasons(DiffusionRepositoryRef $ref) {
87 $repository = $this->getRepository();
88 $reasons = array();
89
90 if (!$ref->isBranch()) {
91 $reasons[] = self::HOLD_REF_NOT_BRANCH;
92 } else {
93 $branch_name = $ref->getShortName();
94
95 if (!$repository->shouldTrackBranch($branch_name)) {
96 $reasons[] = self::HOLD_UNTRACKED;
97 }
98
99 if (!$repository->isBranchPermanentRef($branch_name)) {
100 $reasons[] = self::HOLD_NOT_PERMANENT_REF;
101 }
102 }
103
104 return $reasons;
105 }
106
107}