[pkg-perl-tools] 01/01: dpt-salsa: use the repository path instead of the repository id

gregor herrmann gregoa at debian.org
Mon Jan 29 17:34:36 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 7791f3d3f02db3333391dff04a1a4ecacfa089fd
Author: gregor herrmann <gregoa at debian.org>
Date:   Mon Jan 29 18:28:54 2018 +0100

    dpt-salsa: use the repository path instead of the repository id
    
    the id was found by 'search' on projects which does a substring match and
    might yield too many results. now we construct the path and see if the
    project exists.
    
    Gbp-Dch: Ignore
---
 scripts/salsa | 59 ++++++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 44 insertions(+), 15 deletions(-)

diff --git a/scripts/salsa b/scripts/salsa
index ca2b85d..d318cd8 100755
--- a/scripts/salsa
+++ b/scripts/salsa
@@ -239,27 +239,28 @@ sub createrepo {
 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};
+    my $repo_path = repo2repopath($repo);
+    my $repo_name = $api->project($repo_path)->{name};
 
     # webhooks: cleanup; tagpending
-    my $hooks = $api->project_hooks($repo_id);
-    $api->delete_project_hook( $repo_id, $_->{id} ) foreach @{$hooks};
+    my $hooks = $api->project_hooks($repo_path);
+    $api->delete_project_hook( $repo_path, $_->{id} ) foreach @{$hooks};
 
     $api->create_project_hook(
-        $repo_id,
+        $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_id, 'emails-on-push' );
-    $api->delete_project_service( $repo_id, 'irker' );
-    $api->edit_project_service( $repo_id, 'emails-on-push',
+    $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_id, 'irker',
+        $repo_path,
+        'irker',
         {
 
             server_host       => 'ruprecht.snow-crash.org',
@@ -274,15 +275,16 @@ sub configurerepo {
     # 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);
+    my $project_users = $api->project_users($repo_path);
     foreach ( @{$project_users} ) {
         if ( $_->{id} == $config{administrator_id} ) {
-            $api->unshare_project_with_group( $repo_id, $config{debian_id}, );
+            $api->unshare_project_with_group( $repo_path, $config{debian_id},
+            );
             last;
         }
     }
     $api->share_project_with_group(
-        $repo_id,
+        $repo_path,
         {   group_id     => $config{debian_id},
             group_access => $levels_name{developer},
         }
@@ -298,9 +300,10 @@ sub changerepo {
         unless ( $property eq 'name' or $property eq 'description' );
     die 'Required paramter "new value" missing.' unless $value;
 
-    my $repo_id = repo2repoid($repo);
-    $api->edit_project( $repo_id, { $property => $value } );
-    $api->edit_project( $repo_id, { path => $value } ) if $property eq 'name';
+    my $repo_path = repo2repopath($repo);
+    $api->edit_project( $repo_path, { $property => $value } );
+    $api->edit_project( $repo_path, { path      => $value } )
+        if $property eq 'name';
 }
 
 # helper functions
@@ -330,6 +333,7 @@ sub user2userid {
 }
 
 ## reponame2repoid($reponame)
+## XXX unused
 sub reponame2repoid {
     my $reponame = shift;
     my $repos = $api->projects( { search => $reponame } );
@@ -340,6 +344,7 @@ sub reponame2repoid {
 }
 
 ## repo2repoid($string)
+## XXX unused
 sub repo2repoid {
     my $repo = shift;
     return $repo if $repo =~ /^\d+$/;
@@ -348,6 +353,30 @@ sub repo2repoid {
         "Parameter '$repo' doesn't look like a repositoryid or a repositoryname.";
 }
 
+## reponame2repopath($reponame)
+sub reponame2repopath {
+    my $reponame = shift;
+    my $repopath_packages
+        = $config{perl_team_modules_packages_path} . '/' . $reponame;
+    my $repopath_attic
+        = $config{perl_team_modules_attic_path} . '/' . $reponame;
+    my $repo
+        = $api->project($repopath_packages) || $api->project($repopath_attic);
+    die
+        "Repository name '$reponame' not found in '$config{perl_team_modules_packages_path}' or '$config{perl_team_modules_attic_path}'."
+        unless $repo;
+    return $repo->{path_with_namespace};
+}
+
+## repo2repopath($string)
+sub repo2repopath {
+    my $repo = shift;
+    return $repo if $repo =~ /^\d+$/;
+    return reponame2repopath($repo) if $repo =~ /^\w+$/;
+    die
+        "Parameter '$repo' doesn't look like a repositoryid or a repositoryname.";
+}
+
 __END__
 
 =head1 NAME

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