[pkg-perl-tools] 02/04: Add dpt-alsa: manage team repos and members on salsa.debian.org.

gregor herrmann gregoa at debian.org
Thu Jan 25 20:58:33 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 6a28eb2d48670a899f95af1154970f97eff97f49
Author: gregor herrmann <gregoa at debian.org>
Date:   Thu Jan 25 21:54:02 2018 +0100

    Add dpt-alsa: manage team repos and members on salsa.debian.org.
    
    (Just a first draft for now.)
---
 bin/dpt          |   4 ++
 debian/control   |   2 +
 debian/copyright |   4 ++
 scripts/salsa    | 197 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 207 insertions(+)

diff --git a/bin/dpt b/bin/dpt
index 7a32e00..d45b0b6 100755
--- a/bin/dpt
+++ b/bin/dpt
@@ -159,6 +159,10 @@ See L<dpt-rename-uploader(1)>.
 
 See L<dpt-repack.sh(1)>.
 
+=item B<salsa> - manage repos and members on salsa.debian.org
+
+See L<dpt-salsa(1)>.
+
 =item B<shell-lib> - shell integration
 
 See L<dpt-shell-lib(1)>
diff --git a/debian/control b/debian/control
index c9e21c4..b97c341 100644
--- a/debian/control
+++ b/debian/control
@@ -16,6 +16,7 @@ Build-Depends-Indep: dpkg-dev (>= 1.17.0),
                      libdpkg-perl,
                      libfile-slurp-perl,
                      libgit-repository-perl,
+                     libgitlab-api-v4-perl,
                      libipc-run-perl,
                      libjson-xs-perl,
                      libmime-lite-perl,
@@ -54,6 +55,7 @@ Depends: ${misc:Depends},
          libdatetime-perl,
          libdpkg-perl,
          libgit-repository-perl,
+         libgitlab-api-v4-perl,
          libipc-run-perl,
          libjson-xs-perl,
          libparse-debianchangelog-perl,
diff --git a/debian/copyright b/debian/copyright
index 1b95a9c..1819cff 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -174,6 +174,10 @@ Files: scripts/uscan
 Copyright: 2017, Damyan Ivanov <dam at debian.org>
 License: Artistic or GPL-1+
 
+File: scripts/salsa
+Copyright: 2018, gregor herrmann <gregoa at debian.org>
+License: Artistic or GPL-1+
+
 Files: lib/*
 Copyright: 2016, Alex Muntada <alexm at alexm.org>
 License: Artistic or GPL-1+
diff --git a/scripts/salsa b/scripts/salsa
new file mode 100755
index 0000000..7cfb778
--- /dev/null
+++ b/scripts/salsa
@@ -0,0 +1,197 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use 5.010;
+use Getopt::Long;
+use Pod::Usage qw( pod2usage );
+use GitLab::API::v4;
+use JSON;
+
+#use utf8::all;   # XXX
+#use App::Cmd;    # XXX
+
+# config
+## defaults
+my %config = (
+    api_url       => 'https://salsa.debian.org/api/v4',
+    private_token => '',
+    pkg_perl_path => 'pkg-perl-team',
+    pkg_perl_id   => 42,
+);
+
+## update from environment / config file
+## this is also exported by dpt(1) from ~/.dpt.conf / ~/.config/dpt.conf
+## use DPT_SALSA_FOO as $config{foo}
+foreach ( keys %config ) {
+    my $KEY = 'DPT_SALSA_' . uc($_);
+    $config{$_} = $ENV{$KEY} if $ENV{$KEY};
+}
+
+# commandline
+## options
+my %opts;
+GetOptions( \%opts, 'help|?', 'man', 'json', ) 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
+    -msg      => "E: DPT_SALSA_PRIVATE_TOKEN not set.\n",
+    -exitval  => 2,
+    -verbose  => 99,
+    -sections => "SYNOPSIS|CONFIGURATION",
+) unless $config{private_token};
+
+## subcommand and arguments
+my $command = shift @ARGV;
+pod2usage("E: No subcommand given.\n") unless $command;
+my @args = @ARGV;
+
+# our API object
+my $api = GitLab::API::v4->new(
+    url           => $config{api_url},
+    private_token => $config{private_token},
+);
+
+
+# run command
+if ( $command eq 'version' ) {
+    &version;
+} elsif ( $command eq 'current_user' ) {
+    &current_user;
+} elsif ( $command eq 'help' ) {
+    pod2usage(1);
+} elsif ( $command eq 'XXX' ) {
+    ...;
+} else {
+    pod2usage("E: Unknown subcommand: $command.\n");
+}
+exit;
+
+# subcommand implementations
+## version()
+sub version {
+    my $version = $api->version();
+    if ($opts{json}) {
+        say prettyjson($version);
+    } else {
+        say "Version:  " . $version->{version};
+        say "Revision: " . $version->{revision};
+    }
+}
+
+## current_user()
+sub current_user {
+    my $current_user = $api->current_user();
+    if ($opts{json}) {
+        say prettyjson($current_user);
+    } else {
+        say "Username: " . $current_user->{username};
+        say "Name:     " . $current_user->{name};
+        say "Email:    " . $current_user->{email};
+    }
+}
+
+# helper functions
+## prettyjson($data)
+sub prettyjson {
+    my $data = shift;
+    my $json = JSON->new->utf8->pretty->canonical->allow_nonref();
+    $json->encode($data);
+}
+
+__END__
+
+=head1 NAME
+
+B<dpt-salsa> - manage repositories and members of the I<pkg-perl-team> group on I<salsa.debian.org>
+
+=head1 SYNOPSIS
+
+B<dpt salsa>  [--help|--man|--json] I<subcommand> [parameters]
+
+=head1 DESCRIPTION
+
+B<dpt-salsa> is basically a wrapper around L<GitLab::API::v4>, similar to
+L<gitlab-api-v4(1)>, with various variables regarding I<salsa.debian.org> and
+the I<pkg-perl-team> group there already preset and typical method calls
+encapsulated.
+
+It offers subcommands to manage repositories and members of the group with
+hopefully less typing then calling the API manually each time.
+
+Make sure to check the L</CONFIGURATION> section below if you use
+B<dpt-salsa> for the first time.
+
+=head1 SUBCOMMANDS
+
+=head2 for managing repositories
+
+=head2 for managing users
+
+=head2 others
+
+=head3 I<current_user>
+
+Outputs information about the user whose I<GitLab> token is used.
+
+=head3 I<help>
+
+Same as option B<--help>.
+
+=head3 I<version>
+
+Returns the version of the I<GitLab> instance running on I<salsa.debian.org>.
+
+This subcommand is pretty useless, the only excuse for its existence is the
+ability to test if everything is working fine.
+
+=head1 OPTIONS
+
+=over
+
+=item --help
+
+Show short help.
+
+=item --man
+
+Show complete manpage.
+
+=item --json
+
+Format output as JSON instead of human-targetted text.
+
+=back
+
+=head1 CONFIGURATION
+
+B<dpt-salsa> uses the following environment variables, set either directly
+or via F<~/.dpt.conf> / F<~/.config/dpt.conf>:
+
+=over
+
+=item DPT_SALSA_PRIVATE_TOKEN
+
+required, no default, obviously
+
+=item DPT_SALSA_API_URL
+
+optional, default: https://salsa.debian.org/api/v4
+
+=item DPT_SALSA_PKG_PERL_PATH
+
+optional, default: debian-pkg-perl-team
+
+=item DPT_SALSA_PKG_PERL_ID
+
+optional, default: 42
+
+=back
+
+Cf. L<dpt-config(5)>.
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2018, gregor herrmann E<lt>gregoa at debian.orgE<gt>
+
+Released under the same terms as Perl itself, i.e. Artistic or GPL-1+.

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