Page MenuHomePhabricator
Paste P5745

(An Untitled Masterwork)
ActivePublic

Authored by Paladox on Jul 13 2017, 4:17 PM.
Tags
None
Referenced Files
F8736937:
Jul 13 2017, 8:06 PM
F8736706:
Jul 13 2017, 7:58 PM
F8736669:
Jul 13 2017, 7:55 PM
F8736439:
Jul 13 2017, 7:43 PM
F8736298:
Jul 13 2017, 7:36 PM
F8736226:
Jul 13 2017, 7:34 PM
F8736067:
Jul 13 2017, 7:29 PM
F8735903:
Jul 13 2017, 7:19 PM
Subscribers
None
<?php
class CustomGithubDownloadLinks {
static function getMirrorURI($repo) {
$uris = $repo->getURIs();
foreach ($uris as $uri) {
if ($uri->getIsDisabled()) {
continue;
}
if ($uri->getEffectiveIoType() == PhabricatorRepositoryURI::IO_MIRROR &&
strpos($uri->getDisplayURI(), 'github') !== false) {
return $uri;
}
}
return false;
}
static function AddActionLinksToTop($repository, $identifier, $color) {
global $github_download_zip_button, $github_download_tar_button;
$uri = self::getMirrorURI($repository);
if (!$uri) {
return;
}
$uri = $uri->getURI();
if ($color == 'grey') {
$colors = PHUIButtonView::GREY;
} elseif ($color == 'green') {
$colors = PHUIButtonView::GREEN;
}
$github_download_zip_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Download zip (from Github)'))
->setColor($colors)
->setIcon('fa-download')
->setHref($uri.'/archive/'.$identifier.'.zip');
$github_download_tar_button = id(new PHUIButtonView())
->setTag('a')
->setText(pht('Download gz (from Github)'))
->setColor($colors)
->setIcon('fa-download')
->setHref($uri.'/archive/'.$identifier.'.tar.gz');
}
static function addActionsToTop($drequest, $color) {
$repository = $drequest->getRepository();
try {
if ($drequest->getSymbolicType() == 'tag') {
$download = $drequest->getSymbolicCommit();
} elseif ($drequest->getSymbolicType() == 'commit') {
$download = $drequest->getStableCommit();
} else {
$download = $drequest->getBranch();
}
} catch(Exception $e) {
return '';
}
return self::AddActionLinksToTop($repository, $download, $color);
}
}