3 final class PhabricatorRepositoryPublisher
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;
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();
51 if ($repository->isImporting()) {
52 $reasons[] = self
::HOLD_IMPORTING
;
55 if ($repository->isPublishingDisabled()) {
56 $reasons[] = self
::HOLD_PUBLISHING_DISABLED
;
62 public function getRefHoldReasons(DiffusionRepositoryRef
$ref) {
63 $repository = $this->getRepository();
64 $reasons = $this->getRepositoryHoldReasons();
66 foreach ($this->getRefImpermanentReasons($ref) as $reason) {
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
;
86 public function getRefImpermanentReasons(DiffusionRepositoryRef
$ref) {
87 $repository = $this->getRepository();
90 if (!$ref->isBranch()) {
91 $reasons[] = self
::HOLD_REF_NOT_BRANCH
;
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
;