Page MenuHomePhabricator
Paste P1199

add-a-repo.php
ActivePublic

Authored by avivey on Jul 11 2014, 12:33 AM.
Tags
None
Referenced Files
F176210: add-a-repo.php
Jul 11 2014, 12:33 AM
Subscribers
None
<?php
// use: arc import-github-repo --callsign <newcallsign> --name <human-redable-name> <git repo uri>
class importGithubRepo extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'import-github-repo';
}
public function run() {
$uri = $this->getArgument('uri');
$uri = idx($uri, 0);
$callsign = $this->getArgument('callsign');
$name = $this->getArgument('name');
if (!$uri || !$callsign || !$name)
throw new ArcanistUsageException("uri, callsign, name are all required");
$uri = $this->fixUri($uri);
$arguments = array(
'name' => $name,
'callsign'=> $callsign,
'uri' => $uri,
'closeCommitsFilter' => array('master'), // TODO serverside default
'vcs' => 'git',
);
var_dump($arguments);
$response = $this->getConduit()->callMethodSynchronous(
'repository.create',
$arguments);
$console = PhutilConsole::getConsole();
$console->writeOut("%s\n", json_encode($response, JSON_PRETTY_PRINT));
}
function fixUri($input) {
$uri = preg_replace('/\.git$/', '', $input);
$uri = preg_replace(',^https?://,', '', $uri);
$uri = preg_replace(',^github.com/,', '', $uri);
if (strpos($uri, ':') === FALSE)
$uri = 'github:'.$uri;
$uri = new PhutilGitURI($uri);
if (!$uri->getDomain()) {
throw new Exception("can't parse uri: {$input}");
}
$uri = $uri->getPath();
return "git://github/{$uri}";
}
public function getArguments() {
return array(
'name' =>array(
'param' => 'repo name',
),
'callsign' =>array(
'param' => 'callsign',
),
'*' => 'uri',
);
}
public function requiresConduit() {
return true;
}
public function requiresAuthentication() {
return true;
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
EOTEXT
);
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**import-github-repo** [options] __uri__
EOTEXT
);
}
}

Event Timeline

avivey changed the title of this paste from untitled to add-a-repo.php.
avivey updated the paste's language from autodetect to autodetect.

The fix-uri part is probably not working.

dump in arcanist/src/extensions/