Skip to content

Instantly share code, notes, and snippets.

@tobyink
Last active September 29, 2020 12:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tobyink/dfe92f717d4fea6ecc51352e311b82b9 to your computer and use it in GitHub Desktop.
Script to switch off the "issues" feature for all my Perl repos. (Issues for my Perl repos should be reported to rt.cpan.org.)
#!/usr/bin/env perl
use Z;
my $app = app sub {
class 'Visitor' => sub {
constant 'USER' => 'tobyink'; # Your username!
constant 'TOKEN' => 'XXXXXXX'; # https://github.com/settings/tokens
has 'code' => ( type => CodeRef, required => true );
has 'repos' => ( is => 'lazy', init_arg => undef );
has 'github' => ( type => Object, is => 'lazy' );
method '_build_github' => sub {
my ( $self ) = ( shift );
require Pithub;
return 'Pithub'->new(
'token' => $self->TOKEN,
'user' => $self->USER,
);
};
method '_build_repos' => sub {
my ( $self ) = ( shift );
my $r = $self->github->repos->list( 'user' => $self->USER );
$r->auto_pagination( true );
return $r;
};
method 'run' => sub {
my ( $self ) = ( shift );
while ( my $row = $self->repos->next ) {
$self->code->( $self, $row );
}
};
};
};
$app->new_visitor(
'code' => sub {
my ( $visitor, $repo ) = @_;
return unless $repo->{'name'} =~ /^p5-/;
return unless $repo->{'owner'}{'login'} eq $visitor->USER;
if ( $repo->{has_issues} ) {
say "Disabling issues for ", $repo->{html_url};
$visitor->github->repos->update(
'user' => $visitor->USER,
'repo' => $repo->{name},
'data' => { 'has_issues' => \0 },
);
}
},
)->run;
@tobyink
Copy link
Author

tobyink commented Sep 29, 2020

Note line 41. My convention is to name Perl project repos with names matching /^p5-/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment