Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / query / PhabricatorRepositoryPublisher.php
blobfae1b07f003de44f31793ec215392e8e985ed06f
1 <?php
3 final class PhabricatorRepositoryPublisher
4 extends Phobject {
6 private $repository;
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';
15 public function setRepository(PhabricatorRepository $repository) {
16 $this->repository = $repository;
17 return $this;
20 public function getRepository() {
21 if (!$this->repository) {
22 throw new PhutilInvalidStateException('setRepository');
24 return $this->repository;
27 /* -( Publishing )--------------------------------------------------------- */
29 public function shouldPublishRepository() {
30 return !$this->getRepositoryHoldReasons();
33 public function shouldPublishRef(DiffusionRepositoryRef $ref) {
34 return !$this->getRefHoldReasons($ref);
37 public function shouldPublishCommit(PhabricatorRepositoryCommit $commit) {
38 return !$this->getCommitHoldReasons($commit);
41 public function isPermanentRef(DiffusionRepositoryRef $ref) {
42 return !$this->getRefImpermanentReasons($ref);
45 /* -( Hold Reasons )------------------------------------------------------- */
47 public function getRepositoryHoldReasons() {
48 $repository = $this->getRepository();
50 $reasons = array();
51 if ($repository->isImporting()) {
52 $reasons[] = self::HOLD_IMPORTING;
55 if ($repository->isPublishingDisabled()) {
56 $reasons[] = self::HOLD_PUBLISHING_DISABLED;
59 return $reasons;
62 public function getRefHoldReasons(DiffusionRepositoryRef $ref) {
63 $repository = $this->getRepository();
64 $reasons = $this->getRepositoryHoldReasons();
66 foreach ($this->getRefImpermanentReasons($ref) as $reason) {
67 $reasons[] = $reason;
70 return $reasons;
73 public function getCommitHoldReasons(PhabricatorRepositoryCommit $commit) {
74 $repository = $this->getRepository();
75 $reasons = $this->getRepositoryHoldReasons();
77 if ($repository->isGit()) {
78 if (!$commit->isPermanentCommit()) {
79 $reasons[] = self::HOLD_NOT_REACHABLE_FROM_PERMANENT_REF;
83 return $reasons;
86 public function getRefImpermanentReasons(DiffusionRepositoryRef $ref) {
87 $repository = $this->getRepository();
88 $reasons = array();
90 if (!$ref->isBranch()) {
91 $reasons[] = self::HOLD_REF_NOT_BRANCH;
92 } else {
93 $branch_name = $ref->getShortName();
95 if (!$repository->shouldTrackBranch($branch_name)) {
96 $reasons[] = self::HOLD_UNTRACKED;
99 if (!$repository->isBranchPermanentRef($branch_name)) {
100 $reasons[] = self::HOLD_NOT_PERMANENT_REF;
104 return $reasons;