Changeset View
Standalone View
src/applications/harbormaster/integration/circleci/HarbormasterCircleCIBuildStepImplementation.php
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | switch ($domain) { | ||||
case 'github.com': | case 'github.com': | ||||
case 'www.github.com': | case 'www.github.com': | ||||
return $uri_object->getPath(); | return $uri_object->getPath(); | ||||
default: | default: | ||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
public static function loadRepository( | |||||
HarbormasterExternalBuildableInterface $buildable) { | |||||
$repository = $buildable->getRepository(); | |||||
if (!$repository) { | |||||
throw new Exception( | |||||
pht( | |||||
'Object ("%s") is not associated with a repository or the '. | |||||
'repository could not be loaded.', | |||||
$buildable->getPHID())); | |||||
} | |||||
return $repository; | |||||
} | |||||
public static function searchGitHubPathForRevision( | |||||
HarbormasterExternalBuildableInterface $buildable) { | |||||
$repository = self::loadRepository($buildable); | |||||
$buildable_phid = $buildable->getPHID(); | |||||
$repository_phid = $repository->getPHID(); | |||||
if ($repository->isHosted()) { | |||||
throw new Exception( | |||||
pht( | |||||
'This commit ("%s") is associated with a hosted repository '. | |||||
'("%s"). Repositories must be imported from GitHub to be built '. | |||||
'with CircleCI.', | |||||
$buildable_phid, | |||||
$repository_phid)); | |||||
} | |||||
$remote_uri = $repository->getRemoteURI(); | |||||
$path = self::getGitHubPath($remote_uri); | |||||
if (!$path) { | |||||
throw new Exception( | |||||
pht( | |||||
'This commit ("%s") is associated with a repository ("%s") '. | |||||
speck: This was the original error text but it seems like the word `that` at the end of this line is… | |||||
Done Inline ActionsGood catch, will fix. deadalnix: Good catch, will fix. | |||||
Not Done Inline ActionsNote that I recently landed several typos (including this) upstream in https://secure.phabricator.com/D21675. If/when we merge or re-fork from upstream (primarily for https://secure.phabricator.com/T13658) the changes/refactoring here might have issues. It might help in the future if the same text change from https://secure.phabricator.com/D21675#change-F1OaF05EWVSC was applied here during this move. speck: Note that I recently landed several typos (including this) upstream in https://secure. | |||||
Done Inline ActionsI'll rebase when it makes its way to phorge. deadalnix: I'll rebase when it makes its way to phorge. | |||||
'with a remote URI ("%s") that does not appear to be hosted on '. | |||||
'GitHub. Repositories must be hosted on GitHub to be built with '. | |||||
'CircleCI.', | |||||
$buildable_phid, | |||||
$repository_phid, | |||||
$remote_uri)); | |||||
} | |||||
return $remote_uri; | |||||
} | |||||
public static function searchGitHubPathForTag( | |||||
HarbormasterExternalBuildableInterface $buildable) { | |||||
$repository = self::loadRepository($buildable); | |||||
$buildable_phid = $buildable->getPHID(); | |||||
$repository_phid = $repository->getPHID(); | |||||
$staging_uri = $repository->getStagingURI(); | |||||
if (!$staging_uri) { | |||||
throw new Exception( | |||||
pht( | |||||
'This diff ("%s") is associated with a repository ("%s") that '. | |||||
'does not have a Staging Area configured. You must configure a '. | |||||
'Staging Area to use CircleCI integration.', | |||||
$buildable_phid, | |||||
$repository_phid)); | |||||
} | |||||
$path = self::getGitHubPath($staging_uri); | |||||
if (!$path) { | |||||
throw new Exception( | |||||
pht( | |||||
'This diff ("%s") is associated with a repository ("%s") that '. | |||||
'does not have a Staging Area ("%s") that is hosted on GitHub. '. | |||||
'CircleCI can only build from GitHub, so the Staging Area for '. | |||||
'the repository must be hosted there.', | |||||
$buildable_phid, | |||||
$repository_phid, | |||||
$staging_uri)); | |||||
} | |||||
return $staging_uri; | |||||
} | |||||
public function execute( | public function execute( | ||||
HarbormasterBuild $build, | HarbormasterBuild $build, | ||||
HarbormasterBuildTarget $build_target) { | HarbormasterBuildTarget $build_target) { | ||||
$viewer = PhabricatorUser::getOmnipotentUser(); | $viewer = PhabricatorUser::getOmnipotentUser(); | ||||
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) { | if (PhabricatorEnv::getEnvConfig('phabricator.silent')) { | ||||
$this->logSilencedCall($build, $build_target, pht('CircleCI')); | $this->logSilencedCall($build, $build_target, pht('CircleCI')); | ||||
throw new HarbormasterBuildFailureException(); | throw new HarbormasterBuildFailureException(); | ||||
} | } | ||||
$buildable = $build->getBuildable(); | $buildable = $build->getBuildable(); | ||||
$object = $buildable->getBuildableObject(); | $object = $buildable->getBuildableObject(); | ||||
$object_phid = $object->getPHID(); | $object_phid = $object->getPHID(); | ||||
if (!($object instanceof HarbormasterCircleCIBuildableInterface)) { | if (!($object instanceof HarbormasterExternalBuildableInterface)) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Object ("%s") does not implement interface "%s". Only objects '. | 'Object ("%s") does not implement interface "%s". Only objects '. | ||||
'which implement this interface can be built with CircleCI.', | 'which implement this interface can be built with CircleCI.', | ||||
$object_phid, | $object_phid, | ||||
'HarbormasterCircleCIBuildableInterface')); | 'HarbormasterExternalBuildableInterface')); | ||||
} | } | ||||
$github_uri = $object->getCircleCIGitHubRepositoryURI(); | list($type, $ref) = $object->getExternalBuildableRef(); | ||||
$build_type = $object->getCircleCIBuildIdentifierType(); | switch ($type) { | ||||
$build_identifier = $object->getCircleCIBuildIdentifier(); | case HarbormasterExternalBuildableInterface::COMMIT: | ||||
$build_type = 'revision'; | |||||
$build_identifier = $ref; | |||||
$github_uri = self::searchGitHubPathForRevision($object); | |||||
break; | |||||
case HarbormasterExternalBuildableInterface::TAG: | |||||
$build_type = 'tag'; | |||||
$build_identifier = $ref; | |||||
$github_uri = self::searchGitHubPathForTag($object); | |||||
break; | |||||
default: | |||||
throw new Exception( | |||||
pht( | |||||
'Object ("%s") use ref %s of type %d, which is not supported.', | |||||
Not Done Inline ActionsBah it looks like PHP only introduced enums in 8.1 - this error message might be a bit cryptic to interpret since $type will just be a number, but that's probably fine for now and this case is unlikely to occur. speck: Bah it looks like PHP only introduced enums in 8.1 - this error message might be a bit cryptic… | |||||
Done Inline ActionsLast time I tried, xhpast, which is heavily relied on by phabricator, was not able to handle them. Maybe newer version of it can, I have not tried, but even if they do, do we want to break compatibility with older xhpast? What's the policy we want to adopt here? deadalnix: Last time I tried, xhpast, which is heavily relied on by phabricator, was not able to handle… | |||||
Not Done Inline ActionsI think supporting PHP 8 will be a large effort, likely needs to be done in a separate task altogether. I was mostly just lamenting that the versions of PHP this code is for doesn't support enums. speck: I think supporting PHP 8 will be a large effort, likely needs to be done in a separate task… | |||||
$object_phid, | |||||
$ref, | |||||
$type)); | |||||
} | |||||
$path = self::getGitHubPath($github_uri); | $path = self::getGitHubPath($github_uri); | ||||
if ($path === null) { | if ($path === null) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Object ("%s") claims "%s" is a GitHub repository URI, but the '. | 'Object ("%s") claims "%s" is a GitHub repository URI, but the '. | ||||
'domain does not appear to be GitHub.', | 'domain does not appear to be GitHub.', | ||||
$object_phid, | $object_phid, | ||||
▲ Show 20 Lines • Show All 143 Lines • Show Last 20 Lines |
This was the original error text but it seems like the word that at the end of this line is erroneous. We can probably omit this.
Looking at some of the other error messages below I'm guessing it was a copy paste and never updated