Commit 6a28eb2d authored by gregor herrmann's avatar gregor herrmann

Add dpt-alsa: manage team repos and members on salsa.debian.org.

(Just a first draft for now.)
parent 3d999353
......@@ -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)>
......
......@@ -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,
......
......@@ -174,6 +174,10 @@ Files: scripts/uscan
Copyright: 2017, Damyan Ivanov <dam@debian.org>
License: Artistic or GPL-1+
File: scripts/salsa
Copyright: 2018, gregor herrmann <gregoa@debian.org>
License: Artistic or GPL-1+
Files: lib/*
Copyright: 2016, Alex Muntada <alexm@alexm.org>
License: Artistic or GPL-1+
......
#!/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@debian.orgE<gt>
Released under the same terms as Perl itself, i.e. Artistic or GPL-1+.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment