[pkg-perl-tools] 01/01: dpt-salsa: factor out configurerepo()

gregor herrmann gregoa at debian.org
Sun Jan 28 14:57:08 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 d1474f73bf34a8f71f41ffcc6b50b2be24c17e5c
Author: gregor herrmann <gregoa at debian.org>
Date:   Sun Jan 28 15:35:56 2018 +0100

    dpt-salsa: factor out configurerepo()
    
    problems:
    - warnings from Role::REST::Client
    - sharing with the Debian group:
      + dead slow
      + everyone is a project_user then (not a project_member)
        (aesthetical)
      + fails on share if shared, fails on unshare of not shared, but no way to
        check? as a proxy check if salsa admin is a group user
    
    Gbp-Dch: Ignore
---
 scripts/salsa | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
 t/spelling.st |  1 +
 2 files changed, 75 insertions(+), 12 deletions(-)

diff --git a/scripts/salsa b/scripts/salsa
index ed27122..90f2c55 100755
--- a/scripts/salsa
+++ b/scripts/salsa
@@ -27,6 +27,7 @@ my %config = (
     perl_team_modules_attic_id      => 2667,
     debian_path                     => 'debian',
     debian_id                       => 2,
+    administrator_id                => 1,
 );
 
 ## update from environment / config file
@@ -104,6 +105,8 @@ if ( $command eq 'version' ) {
     listrepos();
 } elsif ( $command eq 'createrepo' ) {
     createrepo();
+} elsif ( $command eq 'configurerepo' ) {
+    configurerepo();
 } elsif ( $command eq 'help' ) {
     pod2usage(1);
 } elsif ( $command eq 'XXX' ) {
@@ -196,7 +199,7 @@ sub listrepos {
     }
 }
 
-# createrepo
+## createrepo
 sub createrepo {
     my ($reponame) = @args;
     die 'Required parameter repositoryname missing.' unless $reponame;
@@ -208,21 +211,34 @@ sub createrepo {
             visibility   => 'public',
         }
     );
-    my $repoid = $repo->{id};
+    configurerepo();
+}
+
+## configurerepo
+sub configurerepo {
+    my ($repo) = @args;
+    die 'Required parameter reponame|repoid missing.' unless $repo;
+    my $repo_id   = repo2repoid($repo);
+    my $repo_name = $api->project($repo_id)->{name};
+
+    # webhooks: cleanup; tagpending
+    my $hooks = $api->project_hooks($repo_id);
+    $api->delete_project_hook( $repo_id, $_->{id} ) foreach @{$hooks};
 
-    # webhooks: tagpending
     $api->create_project_hook(
-        $repoid,
-        {   url => "https://webhook.salsa.debian.org/tagpending/$reponame",
+        $repo_id,
+        {   url => "https://webhook.salsa.debian.org/tagpending/$repo_name",
             push_events => 1,
         }
     );
 
-    # services: emails-on-push, irker
-    $api->edit_project_service( $repoid, 'emails-on-push',
+    # services: cleanup; emails-on-push, irker
+    $api->delete_project_service( $repo_id, 'emails-on-push' );
+    $api->delete_project_service( $repo_id, 'irker' );
+    $api->edit_project_service( $repo_id, 'emails-on-push',
         { recipients => 'pkg-perl-cvs-commits at lists.alioth.debian.org' } );
     $api->edit_project_service(
-        $repoid, 'irker',
+        $repo_id, 'irker',
         {
 
             server_host       => 'ruprecht.snow-crash.org',
@@ -234,9 +250,18 @@ sub createrepo {
         }
     );
 
-    # allow access to debian group
+    # take/give access to debian group
+    # check if Administrator is a project user as a proxy to find
+    # if the project is shared with the Debian group
+    my $project_users = $api->project_users($repo_id);
+    foreach ( @{$project_users} ) {
+        if ( $_->{id} == $config{administrator_id} ) {
+            $api->unshare_project_with_group( $repo_id, $config{debian_id}, );
+            last;
+        }
+    }
     $api->share_project_with_group(
-        $repoid,
+        $repo_id,
         {   group_id     => $config{debian_id},
             group_access => $levels_name{developer},
         }
@@ -269,6 +294,25 @@ sub user2userid {
     die "Parameter '$user' doesn't look like a userid or a username.";
 }
 
+## reponame2repoid($reponame)
+sub reponame2repoid {
+    my $reponame = shift;
+    my $repos = $api->projects( { search => $reponame } );
+    die "More than one repository with name '$reponame'."
+        if scalar @{$repos} > 1;
+    die "Repository name '$reponame' not found." if scalar @{$repos} < 1;
+    return $repos->[0]->{id};
+}
+
+## repo2repoid($string)
+sub repo2repoid {
+    my $repo = shift;
+    return $repo if $repo =~ /^\d+$/;
+    return reponame2repoid($repo) if $repo =~ /^\w+$/;
+    die
+        "Parameter '$repo' doesn't look like a repositoryid or a repositoryname.";
+}
+
 __END__
 
 =head1 NAME
@@ -298,8 +342,7 @@ B<dpt-salsa> for the first time.
 
 =head3 I<createrepo> I<repositoryname>
 
-Creates a new repository in the I<modules> subgroup and sets up the default
-webhooks, services, and permissions.
+Creates a new repository in the I<modules> subgroup and calls C<configurerepo()>.
 
 Parameters:
 
@@ -312,6 +355,21 @@ Required.
 
 =back
 
+=head3 I<configurerepo> I<repositoryid|repositoryname>
+
+Sets up the default webhooks, services, and permissions for a repository.
+
+Parameters:
+
+=over
+
+=item repositoryid|repositoryname
+
+The repository to be configured. Either its id (\d+) or name (\w+).
+Required.
+
+=back
+
 =head3 I<listrepos>
 
 Show all repositories in the I<modules> subgroup.
@@ -455,6 +513,10 @@ optional, default: debian
 
 optional, default: 2
 
+=item DPT_SALSA_ADMINISTRATOR_ID
+
+optional, default: 1
+
 =back
 
 Cf. L<dpt-config(5)>.
diff --git a/t/spelling.st b/t/spelling.st
index fade8a3..a5a6ca0 100644
--- a/t/spelling.st
+++ b/t/spelling.st
@@ -54,6 +54,7 @@ anonscm
 bts
 bzip
 conf
+configurerepo
 createrepo
 dch
 debian

-- 
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