Retidy
[grml-infrastructure.git] / tools / github
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use v5.10;
5 use File::HomeDir;
6 use File::Slurp qw ( slurp );
7 use Data::Dumper;
8 use Net::GitHub;
9
10 my $token = slurp( File::HomeDir->my_home . "/.github-token" );
11
12 my $gh = Net::GitHub->new(    # Net::GitHub::V3
13     access_token => $token
14 );
15
16 my @repos = $gh->repos->list_org('grml');
17
18 foreach my $repo (@repos) {
19     say $repo->{name};
20     say "-" x length( $repo->{name} );
21     my @hooks = $gh->repos->hooks( 'grml', $repo->{name} );
22     my $found = 0;
23     foreach my $hook (@hooks) {
24
25         #warn Dumper($hook);
26         next unless $hook->{name} eq 'web';
27         next unless $hook->{config}->{url} eq "http://git.grml.org/github";
28         $found = 1;
29     }
30     if ($found) {
31         say "git.grml.org hook already configured";
32     }
33     else {
34         my $rc = $gh->repos->create_hook(
35             'grml',
36             $repo->{name},
37             {
38                 name   => 'web',
39                 active => 1,
40                 config => {
41                     'content_type' => 'form',
42                     'url'          => 'http://git.grml.org/github'
43                 }
44             }
45         );
46         say "Hook created"
47           if $rc->{config}->{url} eq "http://git.grml.org/github";
48     }
49     say;
50 }