This is an automated email from the git hooks/post-receive script. alexm-guest pushed a commit to branch master in repository pkg-perl-tools.
commit 0c2671de6de27134e67857ad523f52cbb847b748 Author: Alex Muntada <al...@alexm.org> Date: Sun Dec 4 03:23:39 2016 +0100 Add invite-github script --- debian/copyright | 4 ++ scripts/invite-github | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/debian/copyright b/debian/copyright index d2a7215..b2945af 100644 --- a/debian/copyright +++ b/debian/copyright @@ -170,6 +170,10 @@ Copyright: 2013, Jonas Smedegaard <d...@jones.dk> 2013, gregor herrmann <gre...@debian.org> License: Artistic or GPL-1+ +Files: scripts/invite-github +Copyright: 2016, Alex Muntada <al...@alexm.org> +License: Artistic or GPL-1+ + Files: lib/* Copyright: 2016, Alex Muntada <al...@alexm.org> License: Artistic or GPL-1+ diff --git a/scripts/invite-github b/scripts/invite-github new file mode 100755 index 0000000..1b44eb4 --- /dev/null +++ b/scripts/invite-github @@ -0,0 +1,114 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +use Getopt::Long; +use LWP::UserAgent; +use JSON::XS; + +=head1 NAME + +invite-github - Invite someone to a GitHub organization + +=head1 SYNOPSIS + + invite-github [option...] {github-username} + +=head1 DESCRIPTION + +B<dpt invite-github> can be used for inviting people to become members +of a GitHub organization. You can set the organization name through +C<DPT_GUTHUB_ORGNAME> environment variable (defaults to I<pkg-perl-tools>). + +You need to have write access to the C<admin:org> scope to be able to +manage organization memberships. Please, make sure the token you use +has that scope in L<https://github.com/settings/tokens>. + +=head1 OPTIONS + +=over + +=item B<--role> I<name> + +This option sets the role for the user. Valid roles are I<admin> or I<member>, +which is the default. + +=item B<--force> + +Use this option if the GitHub user is already a member of the organization +and you want to change their role anyway. + +=back + +=cut + +my $opt_force; +my $opt_role; + +GetOptions( + 'role=s' => \$opt_role, + 'force!' => \$opt_force, +) or exit 1; + +my ($gh_user) = @ARGV; +die "GitHub user name is required\n" unless defined $gh_user; + +die "DPT_GITHUB_OAUTH environment variable must be set\n" + unless defined $ENV{DPT_GITHUB_OAUTH} + and $ENV{DPT_GITHUB_OAUTH} =~ /\w+/; + +my $orgname = $ENV{DPT_GITHUB_ORGNAME} || 'pkg-perl-tools'; +my $api = "https://api.github.com/orgs/$orgname/memberships/$gh_user"; +my $content_type = 'application/vnd.github.v3+json'; +my %headers = ( + 'Authorization' => "token $ENV{DPT_GITHUB_OAUTH}", + 'Content-Type' => $content_type, + 'Accept' => $content_type, +); + +sub check_membership { + my ($res) = @_; + + my $json = decode_json($res->decoded_content); + if ( $res->is_success ) { + my $state = $json->{state}; + my $role = $json->{role}; + print "User $gh_user is already a member of $orgname with state $state and role $role\n"; + } + else { + my $message = $json->{message}; + die "Failed $gh_user membership status: $message\n"; + } +} + +my $ua = LWP::UserAgent->new(); +my $res = $ua->get( $api, %headers ); + +print "User $gh_user is not a member of $orgname yet...\n" + if $res->code == 404; + +$headers{Content} = encode_json({ role => $opt_role }) + if $opt_role; + +$res = $ua->put( $api, %headers ) + if $res->code == 404 or $opt_force; + +check_membership($res); + + +=head1 LICENSE AND COPYRIGHT + +=over + +=item Copyright 2016 Alex Muntada. + +=back + +This program is free software; you can redistribute it and/or modify it +under the terms of either: the GNU General Public License as published +by the Free Software Foundation; or the Artistic License. + +See http://dev.perl.org/licenses/ for more information. + +=cut -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/pkg-perl-tools.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits