Skip to content

Commit

Permalink
Add dagoldens travis-enable script
Browse files Browse the repository at this point in the history
  • Loading branch information
kentfredric committed Dec 21, 2013
1 parent 14e48d8 commit b7aea38
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions travis_enable.pl
@@ -0,0 +1,85 @@
#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;
use Carp;
use Net::GitHub;
use Getopt::Lucid ':all';
use Path::Tiny;

my $opts = Getopt::Lucid->getopt(
[
#<<< No perltidy
Param('repo|r'),
#>>>
]
);

$opts->validate;

sub _detect_repo {
my ($origin) = grep { /origin/ } `git remote -v`;

die "Couldn't determine origin\n" unless $origin;

chomp $origin;
$origin =~ s/^origin\s+//;
$origin =~ s/\s+\(.*$//;
if ( $origin =~ m{^.+?://github.com/([^/]+)/(.+)\.git$} ) {
return [ $1, $2 ];
}
elsif ( $origin =~ m{^git\@github\.com:([^/]+)/(.+)\.git$} ) {
return [ $1, $2 ];
}
else {
die "Can't determine repo name from '$origin'. Try manually with -r REPO\n";
}
}

sub _git_config {
my $key = shift;
chomp( my $value = `git config --get $key` );
croak "Unknown $key" unless $value;
return $value;
}

my $github_user = _git_config("github.user");
my $github_token = _git_config("github.token");
my $travis_token = _git_config("travis.token");

my $gh = Net::GitHub->new( access_token => $github_token );

my @repos;

if ( $opts->get_repo ) {
@repos = $opts->get_repo;
}
else {
( $github_user, @repos ) = @{ _detect_repo() };
}

my $hook_hash = {
name => 'travis',
config => {
token => $travis_token,
user => $github_user,
domain => '',
},
events => [ qw/push pull_request issue_comment public member/ ],
active => 1,
};

my $repos = $gh->repos;
$repos->set_default_user_repo( $github_user, $repos[0] );
my $hook = eval { $repos->create_hook($hook_hash) };
if( $@ ) {
say "Failed: $@";
}
else {
say "Enabled travis for $repos[0]";
}

unless ( -f 'travis.yml' ) {
path("~/.dzil/master/template/.travis.yml")->copy(".travis.yml");
say "copied .travis.yml to current directory";
}

0 comments on commit b7aea38

Please sign in to comment.