[pkg-perl-tools] 01/01: dpt-salsa: new functions, notably adduser and removeuser

gregor herrmann gregoa at debian.org
Fri Jan 26 22:48:26 UTC 2018


This is an automated email from the git hooks/post-receive script.

gregoa pushed a commit to branch master
in repository pkg-perl-tools.

commit e8dd7ef055f7ccc87a8887080a9876a301b662f6
Author: gregor herrmann <gregoa at debian.org>
Date:   Fri Jan 26 23:47:53 2018 +0100

    dpt-salsa: new functions, notably adduser and removeuser
    
    Gbp-Dch: Ignore
---
 scripts/salsa | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 96 insertions(+), 3 deletions(-)

diff --git a/scripts/salsa b/scripts/salsa
index 7cfb778..bed40f4 100755
--- a/scripts/salsa
+++ b/scripts/salsa
@@ -6,6 +6,7 @@ use 5.010;
 use Getopt::Long;
 use Pod::Usage qw( pod2usage );
 use GitLab::API::v4;
+use GitLab::API::v4::Constants qw( :all );
 use JSON;
 
 #use utf8::all;   # XXX
@@ -55,9 +56,16 @@ my $api = GitLab::API::v4->new(
 
 # run command
 if ( $command eq 'version' ) {
-    &version;
+    version();
 } elsif ( $command eq 'current_user' ) {
-    &current_user;
+    current_user();
+} elsif ( $command eq 'adduser' ) {
+    adduser();
+} elsif ( $command eq 'removeuser'
+    or $command eq 'rmuser'
+    or $command eq 'deluser' )
+{
+    removeuser();
 } elsif ( $command eq 'help' ) {
     pod2usage(1);
 } elsif ( $command eq 'XXX' ) {
@@ -91,6 +99,38 @@ sub current_user {
     }
 }
 
+## adduser()
+sub adduser {
+    my ( $user, $level ) = @args;
+    die 'Required parameter username|userid missing.' unless $user;
+    $level ||= 'master';
+
+    my $user_id = user2userid($user);
+
+    my %levels = (
+        guest     => $GITLAB_ACCESS_LEVEL_GUEST,
+        reporter  => $GITLAB_ACCESS_LEVEL_REPORTER,
+        developer => $GITLAB_ACCESS_LEVEL_DEVELOPER,
+        master    => $GITLAB_ACCESS_LEVEL_MASTER,
+        owner     => $GITLAB_ACCESS_LEVEL_OWNER,
+    );
+    my $access_level = $levels{ lc($level) };
+    die "Unknown access level '$level'." unless $access_level;
+
+    ...;
+    $api->add_group_member( $config{'pkg_perl_id'},
+        { user_id => $user_id, access_level => $access_level } );
+}
+
+## removeuser()
+sub removeuser {
+    my ($user) = @args;
+    die 'Required parameter username|userid missing.' unless $user;
+    my $user_id = user2userid($user);
+    ...;
+    $api->remove_group_member( $config{'pkg_perl_id'}, $user_id );
+}
+
 # helper functions
 ## prettyjson($data)
 sub prettyjson {
@@ -99,6 +139,24 @@ sub prettyjson {
     $json->encode($data);
 }
 
+## username2userid($username)
+sub username2userid {
+    my $username = shift;
+    my $users = $api->users( { username => $username } );
+    die "More than one user with username '$username'."
+        if scalar @{$users} > 1;
+    die "Username '$username' not found." if scalar @{$users} < 1;
+    return $users->[0]->{id};
+}
+
+## user2userid($string)
+sub user2userid {
+    my $user = shift;
+    return $user if $user =~ /^\d+$/;
+    return username2userid($user) if $user =~ /^\w+$/;
+    die "Parameter '$user' doesn't look like a userid or a username.";
+}
+
 __END__
 
 =head1 NAME
@@ -128,6 +186,41 @@ B<dpt-salsa> for the first time.
 
 =head2 for managing users
 
+=head3 I<adduser> I<username|userid> [access_level]
+
+Adds a user to the I<pkg-perl-team> group.
+
+Parameters:
+
+=over
+
+=item username|userid
+
+The user to be added. Either their id (\d+) or their username (\w+).
+Required.
+
+=item access_level
+
+One of I<GitLab>'s access levels: guest, reporter, developer, master, owner.
+Optional, defaults to C<master>.
+
+=back
+
+=head3 I<removeuser> I<username|userid>
+
+Removes a user from the I<pkg-perl-team> group.
+
+Parameters:
+
+=over
+
+=item username|userid
+
+The user to be removed. Either their id (\d+) or their username (\w+).
+Required.
+
+=back
+
 =head2 others
 
 =head3 I<current_user>
@@ -180,7 +273,7 @@ optional, default: https://salsa.debian.org/api/v4
 
 =item DPT_SALSA_PKG_PERL_PATH
 
-optional, default: debian-pkg-perl-team
+optional, default: pkg-perl-team
 
 =item DPT_SALSA_PKG_PERL_ID
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/pkg-perl-tools.git



More information about the Pkg-perl-cvs-commits mailing list