App-GitHubUtils
view release on metacpan or search on metacpan
lib/App/GitHubUtils.pm view on Meta::CPAN
use Log::ger;
our %SPEC;
$SPEC{':package'} = {
v => 1.1,
summary => 'Utilities related to GitHub',
};
$SPEC{create_this_repo_on_github} = {
v => 1.1,
summary => 'Create this repo on github',
description => <<'_',
This is a convenient no-argument-needed command to create GitHub repository of
the current ("this") repo. Will use <prog:github-cmd> from <pm:App::github::cmd>
to create the repository. To find out the repo name to be created, will first
check .git/config if it exists. Otherwise, will just use the name of the current
directory.
_
args => {
github_cmd_config_profile=>{
schema => 'str*',
},
},
deps => {
prog => 'github-cmd',
},
};
sub create_this_repo_on_github {
require App::GitUtils;
require Cwd;
require IPC::System::Options;
my %args = @_;
my $repo;
SET_REPO_NAME:
{
my $res = App::GitUtils::info();
if ($res->[0] == 200) {
my $content = do {
local $/;
my $path = "$res->[2]{git_dir}/config";
open my $fh, "<", $path or die "Can't open $path: $!";
<$fh>;
};
if ($content =~ m!^\s*url\s*=\s*.+/([^/]+)\.git\s*$!m) {
$repo = $1;
last;
}
}
$repo = Cwd::getcwd();
$repo =~ s!.+/!!;
}
log_info "Creating repo '%s' ...", $repo;
my ($out, $err);
IPC::System::Options::system(
{log=>1, capture_stdout=>\$out, capture_stderr=>\$err},
"github-cmd",
defined($args{github_cmd_config_profile}) ? ("--config-profile", $args{github_cmd_config_profile}) : (),
"create-repo", $repo);
my $exit = $?;
if ($exit) {
if ($out =~ /name already exists/) {
return [412, "Failed: Repo already exists"];
} else {
return [500, "Failed: $out"];
}
} else {
return [200, "OK", undef, {'func.repo'=>$repo}];
}
}
$SPEC{git_clone_from_github} = {
v => 1.1,
summary => 'git clone, with some conveniences',
description => <<'_',
Instead of having to type:
% git clone git@github.com:USER/PREFIX-NAME.git
you can just type:
% git-clone-from-github NAME
The utility will try the `users` specified in config file, as well as
`prefixes` and clone the first repo that exists. You can put something like this
in `githubutils.conf`:
[prog=git-clone-from-github]
users = ["perlancar", "perlancar2"]
prefixes = ["perl5-", "perl-"]
suffixes = ["-p5"]
The utility will check whether repo in these URLs exist:
git@github.com:perlancar/perl5-NAME.git
git@github.com:perlancar/perl-NAME.git
git@github.com:perlancar/NAME-p5.git
git@github.com:perlancar2/perl5-NAME.git
git@github.com:perlancar2/perl-NAME.git
git@github.com:perlancar2/NAME-p5.git
_
args => {
name => {
schema => 'str*',
req => 1,
pos => 0,
},
users => {
schema => ['array*', of=>'str*'],
description => <<'_',
If not specified, will use `login` from `github-cmd.conf` file.
( run in 1.879 second using v1.01-cache-2.11-cpan-39bf76dae61 )