Skip to content

Instantly share code, notes, and snippets.

@tobyink
Created November 14, 2013 10:21
Show Gist options
  • Save tobyink/7464553 to your computer and use it in GitHub Desktop.
Save tobyink/7464553 to your computer and use it in GitHub Desktop.
Enable, disable or check Travis-CI enabled status for Github repositories.
#!/usr/bin/env perl
use v5.16;
use constant {
GH_USER => 'bob',
GH_PASS => 'secret',
TRAVIS_CONFIG => { user => 'bob', token => 'ABfrht2s82J93AyGBNfq' , domain =>'' },
};
use Acme::Constructor::Pythonic qw(
Pithub Path::Class::File Path::Class::Dir Pithub::Repos::Hooks
);
use Cwd;
use Data::Dumper;
BEGIN {
package PithubX::Base;
use Pithub::Base ();
use Moo::Role;
around _request_for => sub {
my ($orig, $self, @args) = @_;
my $req = $self->$orig(@args);
$req->headers->remove_header('Authorization');
$req->headers->authorization_basic(::GH_USER, ::GH_PASS);
return $req;
};
'Moo::Role'->apply_roles_to_package(
'Pithub::Base',
'PithubX::Base',
);
};
if ( Dir(cwd)->file('.no-github')->stat )
{
say "no github!";
exit 0;
}
my $name = (Dir(cwd)->dir_list)[-1];
my $gh = Hooks(user => GH_USER, repo => $name, token => 1);
if (@ARGV and $ARGV[0])
{
warn "Switching on Travis!\n";
$gh->create(
user => GH_USER,
repo => $name,
data => {
name => 'travis',
active => 1,
config => TRAVIS_CONFIG,
events => [qw/ push pull_request issue_comment public member /],
},
);
}
elsif (@ARGV and not $ARGV[0])
{
warn "Switching off Travis!\n";
my $r = $gh->list;
my @hooks = @{ $r->content };
for my $h (@hooks)
{
next unless $h->{name} eq 'travis';
warn "Deleting hook $h->{id}.\n";
$gh->delete(
user => GH_USER,
repo => $name,
hook_id => $h->{id},
);
}
}
else
{
my $r = $gh->list;
print(Dumper( $r->content ));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment