[pkg-perl-tools] 02/04: dpt-salsa: add --all (for configurerepo and changeuser)
gregor herrmann
gregoa at debian.org
Wed Jan 31 20:37:48 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 a60b3b1eca7dfcb53621b22bf5ce6ec332e2d637
Author: gregor herrmann <gregoa at debian.org>
Date: Wed Jan 31 20:11:47 2018 +0100
dpt-salsa: add --all (for configurerepo and changeuser)
Gbp-Dch: Ignore
---
scripts/salsa | 161 ++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 106 insertions(+), 55 deletions(-)
diff --git a/scripts/salsa b/scripts/salsa
index 89f5924..2d05ac1 100755
--- a/scripts/salsa
+++ b/scripts/salsa
@@ -41,7 +41,7 @@ foreach ( keys %config ) {
# commandline
## options
my %opts;
-GetOptions( \%opts, 'help|?', 'man', 'json', ) or pod2usage(2);
+GetOptions( \%opts, 'help|?', 'man', 'json', 'all', ) or pod2usage(2);
pod2usage(1) if $opts{help};
pod2usage( -exitval => 0, -verbose => 2 ) if $opts{man};
pod2usage( # don't check earlier to allow for --help/--man
@@ -161,19 +161,23 @@ sub adduser {
## changeuser()
sub changeuser {
- my ( $user, $level ) = @args;
- die 'Required parameter username|userid missing.' unless $user;
- die 'Required parameter "access level" missing.' unless $level;
-
- my $user_id = user2userid($user);
-
- my $access_level = $levels_name{ lc($level) };
- die "Unknown access level '$level'." unless $access_level;
-
- $api->update_group_member(
- $config{perl_team_modules_id},
- $user_id, { access_level => $access_level },
- );
+ my ( $level, $user ) = @args;
+ die 'Required parameter "access level" missing.' unless $level;
+ die 'Required parameter username|userid missing.'
+ unless ( $user or $opts{all} );
+ my @userids = $opts{all} ? listmembers() : $user;
+
+ foreach (@userids) {
+ my $user_id = user2userid($_);
+
+ my $access_level = $levels_name{ lc($level) };
+ die "Unknown access level '$level'." unless $access_level;
+
+ $api->update_group_member(
+ $config{perl_team_modules_id},
+ $user_id, { access_level => $access_level },
+ );
+ }
}
## removeuser()
@@ -189,7 +193,10 @@ sub listmembers {
my $members
= $api->paginator( 'group_members', $config{perl_team_modules_id} )
->all();
+ my @userids;
foreach ( @{$members} ) {
+ push @userids, $_->{id};
+ next if $opts{all};
if ( $opts{json} ) {
say prettyjson($_);
} else {
@@ -200,6 +207,7 @@ sub listmembers {
say "Access level: " . $access_level;
}
}
+ return @userids;
}
## listrepos()
@@ -209,7 +217,10 @@ sub listrepos {
$config{perl_team_modules_packages_id},
{ order_by => 'name', sort => 'asc' }
)->all();
+ my @repoids;
foreach ( @{$repos} ) {
+ push @repoids, $_->{id};
+ next if $opts{all};
if ( $opts{json} ) {
say prettyjson($_);
} else {
@@ -218,6 +229,7 @@ sub listrepos {
say "URL: " . $_->{web_url};
}
}
+ return @repoids;
}
## createrepo
@@ -238,39 +250,46 @@ sub createrepo {
## configurerepo
sub configurerepo {
my ($repo) = @args;
- die 'Required parameter reponame|repoid missing.' unless $repo;
- my $repo_path = repo2repopath($repo);
- my $repo_name = $api->project($repo_path)->{name};
-
- # webhooks: cleanup; tagpending
- my $hooks = $api->project_hooks($repo_path);
- $api->delete_project_hook( $repo_path, $_->{id} ) foreach @{$hooks};
-
- $api->create_project_hook(
- $repo_path,
- { url => "https://webhook.salsa.debian.org/tagpending/$repo_name",
- push_events => 1,
- }
- );
-
- # services: cleanup; emails-on-push, irker
- $api->delete_project_service( $repo_path, 'emails-on-push' );
- $api->delete_project_service( $repo_path, 'irker' );
- $api->edit_project_service( $repo_path, 'emails-on-push',
- { recipients => 'pkg-perl-cvs-commits at lists.alioth.debian.org' } );
- $api->edit_project_service(
- $repo_path,
- 'irker',
- {
-
- server_host => 'ruprecht.snow-crash.org',
- server_port => '6659',
- default_irc_uri => 'irc://irc.oftc.net:6667/',
- recipients => 'debian-perl',
- colorize_messages => 1,
-
- }
- );
+ die 'Required parameter reponame|repoid missing.'
+ unless ( $repo or $opts{all} );
+ my @repoids = $opts{all} ? listrepos() : $repo;
+
+ foreach (@repoids) {
+ my $repo_path = repo2repopath($_);
+ my $repo_name = $api->project($repo_path)->{name};
+
+ # webhooks: cleanup; tagpending
+ my $hooks = $api->project_hooks($repo_path);
+ $api->delete_project_hook( $repo_path, $_->{id} ) foreach @{$hooks};
+
+ $api->create_project_hook(
+ $repo_path,
+ { url =>
+ "https://webhook.salsa.debian.org/tagpending/$repo_name",
+ push_events => 1,
+ }
+ );
+
+ # services: cleanup; emails-on-push, irker
+ $api->delete_project_service( $repo_path, 'emails-on-push' );
+ $api->delete_project_service( $repo_path, 'irker' );
+ $api->edit_project_service( $repo_path, 'emails-on-push',
+ { recipients => 'pkg-perl-cvs-commits at lists.alioth.debian.org' }
+ );
+ $api->edit_project_service(
+ $repo_path,
+ 'irker',
+ {
+
+ server_host => 'ruprecht.snow-crash.org',
+ server_port => '6659',
+ default_irc_uri => 'irc://irc.oftc.net:6667/',
+ recipients => 'debian-perl',
+ colorize_messages => 1,
+
+ }
+ );
+ }
}
## changerepo
@@ -367,7 +386,7 @@ B<dpt-salsa> - manage repositories and members of the I<perl-team> on I<salsa.de
=head1 SYNOPSIS
-B<dpt salsa> [--help|--man|--json] I<subcommand> [parameters]
+B<dpt salsa> [--help|--man|--json|--all] I<subcommand> [parameters]
=head1 DESCRIPTION
@@ -403,7 +422,7 @@ Required.
=head3 I<configurerepo> I<repositoryid|repositoryname>
-Sets up the default webhooks and services for a repository.
+Sets up the default webhooks and services for one repository.
Parameters:
@@ -416,6 +435,10 @@ Required.
=back
+=head3 I<configurerepo> I<--all>
+
+Sets up the default webhooks and services for all active repositories.
+
=head3 I<changerepo> I<repositoryid|repositoryname> I<name|description> C<"parameter">
Changes the name (and the path) or the description of a repository.
@@ -441,10 +464,13 @@ Required.
=back
-=head3 I<listrepos>
+=head3 I<listrepos> [--json]
Show all repositories in the I<modules> subgroup.
+If used with C<--all>, returns repository ids and does not output anything;
+for internal use.
+
=head2 for managing users
=head3 I<adduser> I<username|userid> [access_level]
@@ -482,21 +508,37 @@ Required.
=back
-=head3 I<changeuser> I<username|userid> I<access_level>
+=head3 I<changeuser> I<access_level> I<username|userid>
-Change the access level of a user in the I<modules> subgroup of the
+Change the access level of one user in the I<modules> subgroup of the
I<perl-team> group.
Parameters:
=over
+=item access_level
+
+One of I<GitLab>'s access levels: guest, reporter, developer, master, owner.
+Required.
+
=item username|userid
The user whose access level is to be changed. Either their id (\d+) or their
username (\w+).
Required.
+=back
+
+=head3 I<changeuser> I<access_level> I<--all>
+
+Change the access level of all users in the I<modules> subgroup of the
+I<perl-team> group.
+
+Parameters:
+
+=over
+
=item access_level
One of I<GitLab>'s access levels: guest, reporter, developer, master, owner.
@@ -504,13 +546,16 @@ Required.
=back
-=head3 I<listmembers>
+=head3 I<listmembers> [--json]
Show all members of the I<modules> subgroup of the I<perl-team> group.
+If used with C<--all>, returns user ids and does not output anything; for
+internal use.
+
=head2 others
-=head3 I<current_user>
+=head3 I<current_user> [--json]
Outputs information about the user whose I<GitLab> token is used.
@@ -518,7 +563,7 @@ Outputs information about the user whose I<GitLab> token is used.
Same as option B<--help>.
-=head3 I<version>
+=head3 I<version> [--json]
Returns the version of the I<GitLab> instance running on I<salsa.debian.org>.
@@ -537,9 +582,15 @@ Show short help.
Show complete manpage.
+=item --all
+
+Act on all users or repositories, not a single named one.
+Only for specific subcommands, as noted in their description.
+
=item --json
Format output as JSON instead of human-targeted text.
+Only for specific subcommands, as noted in their description.
=back
--
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