From 3be121a05dcd170854a8dac6437b29f297a6ff4e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:01:11 +0200 Subject: Adding upstream version 2.23.4+deb12u1. Signed-off-by: Daniel Baumann --- lib/Devscripts/Salsa/rename_branch.pm | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/Devscripts/Salsa/rename_branch.pm (limited to 'lib/Devscripts/Salsa/rename_branch.pm') diff --git a/lib/Devscripts/Salsa/rename_branch.pm b/lib/Devscripts/Salsa/rename_branch.pm new file mode 100644 index 0000000..d908080 --- /dev/null +++ b/lib/Devscripts/Salsa/rename_branch.pm @@ -0,0 +1,45 @@ +package Devscripts::Salsa::rename_branch; + +use strict; +use Devscripts::Output; +use Moo::Role; + +with "Devscripts::Salsa::Repo"; + +our $prompt = 1; + +sub rename_branch { + my ($self, @reponames) = @_; + my $res = 0; + my @repos = $self->get_repo($prompt, @reponames); + return @repos unless (ref $repos[0]); # get_repo returns 1 when fails + foreach (@repos) { + my $id = $_->[0]; + ds_verbose "Configuring $_->[1]"; + my $project = $self->api->project($_->[0]); + eval { + $self->api->create_branch( + $id, + { + ref => $self->config->source_branch, + branch => $self->config->dest_branch, + }); + $self->api->delete_branch($id, $self->config->source_branch); + }; + if ($@) { + $res++; + if ($self->config->no_fail) { + ds_verbose $@; + ds_warn +"Branch rename has failed for $_->[1]. Use --verbose to see errors\n"; + next; + } else { + ds_warn $@; + return 1; + } + } + } + return $res; +} + +1; -- cgit v1.2.3