public
Created

Enable, disable or check Travis-CI enabled status for Github repositories.

  • Download Gist
travis-status.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
#!/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 ));
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.