[Git][debian-gis-team/scripts][master] Update service/integration REST API calls for new behavior.
Bas Couwenberg (@sebastic)
gitlab at salsa.debian.org
Thu Apr 28 08:32:09 BST 2022
Bas Couwenberg pushed to branch master at Debian GIS Project / scripts
Commits:
c7ec2167 by Bas Couwenberg at 2022-04-28T09:32:00+02:00
Update service/integration REST API calls for new behavior.
- - - - -
2 changed files:
- salsa-configure-repositories.pl
- salsa-create-repository.pl
Changes:
=====================================
salsa-configure-repositories.pl
=====================================
@@ -169,13 +169,15 @@ foreach my $project (@{$team_projects}) {
exit 1;
}
+ my $services = get_project_services($project);
+
# Configure Emails on push service
- if(!configure_emails_on_push_service($project)) {
+ if(!configure_emails_on_push_service($project, $services)) {
exit 1;
}
# Configure Irker service
- if(!configure_irker_service($project)) {
+ if(!configure_irker_service($project, $services)) {
exit 1;
}
@@ -501,10 +503,10 @@ sub set_ci_config_path {
}
}
-sub configure_emails_on_push_service {
+sub get_project_services {
my ($project) = @_;
- my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/services/emails-on-push';
+ my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/integrations';
my $req = new HTTP::Request(GET => $url);
$req->header('PRIVATE-TOKEN' => $cfg{token});
@@ -515,114 +517,117 @@ sub configure_emails_on_push_service {
my $data = decode_json($content);
- print "Emails on push:\n". Dumper($data) if($cfg{debug});
+ print "Integrations:\n". Dumper($data) if($cfg{debug});
- if(!$data->{active}) {
- print "Activating Emails on push for: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+ return $data;
+ }
+ else {
+ print "Error: Request failed! ($url)\n";
+ print "HTTP Status: ".$res->code." ".$res->message."\n";
+ print $res->content if($res->content);
- my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/services/emails-on-push';
+ return;
+ }
+}
- my %param = (
- recipients => $cfg{email_recipients},
- disable_diffs => 'false',
- send_from_committer_email => 'false',
- push_events => 'true',
- tag_push_events => 'true',
- branches_to_be_notified => 'all',
- );
+sub get_service {
+ my ($services, $slug) = @_;
- print "param:\n".Dumper(\%param) if($cfg{debug});
+ foreach my $service (@{$services}) {
+ return $service if($service->{slug} eq $slug);
+ }
- my $req = HTTP::Request::Common::PUT($url, [ %param ]);
- $req->header('PRIVATE-TOKEN' => $cfg{token});
+ return;
+}
- my $res = $ua->request($req);
- if($res->is_success) {
- my $content = $res->content;
+sub configure_emails_on_push_service {
+ my ($project, $services) = @_;
- print "Content:\n".Dumper($content) if($cfg{debug});
+ my $service = get_service($services, 'emails-on-push');
- print "Activated Emails on push service for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+ print "Emails on push:\n". Dumper($service) if($cfg{debug});
- return 1;
- }
- else {
- print "Error: Request failed! ($url)\n";
- print "HTTP Status: ".$res->code." ".$res->message."\n";
- print $res->content if($res->content);
+ if(!$service || !$service->{active}) {
+ print "Activating Emails on push for: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
- return;
- }
+ my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/integrations/emails-on-push';
+
+ my %param = (
+ recipients => $cfg{email_recipients},
+ disable_diffs => 'false',
+ send_from_committer_email => 'false',
+ push_events => 'true',
+ tag_push_events => 'true',
+ branches_to_be_notified => 'all',
+ );
+
+ print "param:\n".Dumper(\%param) if($cfg{debug});
+
+ my $req = HTTP::Request::Common::PUT($url, [ %param ]);
+ $req->header('PRIVATE-TOKEN' => $cfg{token});
+
+ my $res = $ua->request($req);
+ if($res->is_success) {
+ my $content = $res->content;
+
+ print "Content:\n".Dumper($content) if($cfg{debug});
+
+ print "Activated Emails on push service for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+
+ return 1;
}
else {
- print "Emails on push service already active for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+ print "Error: Request failed! ($url)\n";
+ print "HTTP Status: ".$res->code." ".$res->message."\n";
+ print $res->content if($res->content);
- return 2;
+ return;
}
}
else {
- print "Error: Request failed! ($url)\n";
- print "HTTP Status: ".$res->code." ".$res->message."\n";
- print $res->content if($res->content);
+ print "Emails on push service already active for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
- return;
+ return 2;
}
}
sub configure_irker_service {
- my ($project) = @_;
-
- my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/services/irker';
-
- my $req = new HTTP::Request(GET => $url);
- $req->header('PRIVATE-TOKEN' => $cfg{token});
-
- my $res = $ua->request($req);
- if($res->is_success) {
- my $content = $res->content;
-
- my $data = decode_json($content);
+ my ($project, $services) = @_;
- print "Irker:\n". Dumper($data) if($cfg{debug});
+ my $service = get_service($services, 'irker');
- if($data->{active}) {
- print "Deactivating Irker for: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+ print "Irker:\n". Dumper($service) if($cfg{debug});
- my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/services/irker';
+ if($service && $service->{active}) {
+ print "Deactivating Irker for: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
- my $req = HTTP::Request::Common::DELETE($url);
- $req->header('PRIVATE-TOKEN' => $cfg{token});
+ my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/integrations/irker';
- my $res = $ua->request($req);
- if($res->is_success) {
- my $content = $res->content;
+ my $req = HTTP::Request::Common::DELETE($url);
+ $req->header('PRIVATE-TOKEN' => $cfg{token});
- print "Content:\n".Dumper($content) if($cfg{debug});
+ my $res = $ua->request($req);
+ if($res->is_success) {
+ my $content = $res->content;
- print "Deactivated Irker service for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+ print "Content:\n".Dumper($content) if($cfg{debug});
- return 1;
- }
- else {
- print "Error: Request failed! ($url)\n";
- print "HTTP Status: ".$res->code." ".$res->message."\n";
- print $res->content if($res->content);
+ print "Deactivated Irker service for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
- return;
- }
+ return 1;
}
else {
- print "Irker service already deactivated for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+ print "Error: Request failed! ($url)\n";
+ print "HTTP Status: ".$res->code." ".$res->message."\n";
+ print $res->content if($res->content);
- return 2;
+ return;
}
}
else {
- print "Error: Request failed! ($url)\n";
- print "HTTP Status: ".$res->code." ".$res->message."\n";
- print $res->content if($res->content);
+ print "Irker service already deactivated for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
- return;
+ return 2;
}
}
=====================================
salsa-create-repository.pl
=====================================
@@ -182,13 +182,18 @@ if(!$project) {
exit 1;
}
+my $services = get_project_services($project);
+if(!$services) {
+ exit 1;
+}
+
# Configure Emails on push service
-if($cfg{enable_emails} && !configure_emails_on_push_service($project)) {
+if($cfg{enable_emails} && !configure_emails_on_push_service($project, $services)) {
exit 1;
}
# Configure Irker service
-if($cfg{enable_irker} && !configure_irker_service($project)) {
+if($cfg{enable_irker} && !configure_irker_service($project, $services)) {
exit 1;
}
@@ -383,10 +388,10 @@ sub create_project {
}
}
-sub configure_emails_on_push_service {
+sub get_project_services {
my ($project) = @_;
- my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/services/emails-on-push';
+ my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/integrations';
my $req = new HTTP::Request(GET => $url);
$req->header('PRIVATE-TOKEN' => $cfg{token});
@@ -397,121 +402,124 @@ sub configure_emails_on_push_service {
my $data = decode_json($content);
- print "Emails on push:\n". Dumper($data) if($cfg{debug});
+ print "Integrations:\n". Dumper($data) if($cfg{debug});
- if(!$data->{active}) {
- print "Activating Emails on push for: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+ return $data;
+ }
+ else {
+ print "Error: Request failed! ($url)\n";
+ print "HTTP Status: ".$res->code." ".$res->message."\n";
+ print $res->content if($res->content);
- my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/services/emails-on-push';
+ return;
+ }
+}
- my %param = (
- recipients => $cfg{email_recipients},
- disable_diffs => 'false',
- send_from_committer_email => 'false',
- push_events => 'true',
- tag_push_events => 'true',
- branches_to_be_notified => 'all',
- );
+sub get_service {
+ my ($services, $slug) = @_;
- print "param:\n".Dumper(\%param) if($cfg{debug});
+ foreach my $service (@{$services}) {
+ return $service if($service->{slug} eq $slug);
+ }
- my $req = HTTP::Request::Common::PUT($url, [ %param ]);
- $req->header('PRIVATE-TOKEN' => $cfg{token});
+ return;
+}
- my $res = $ua->request($req);
- if($res->is_success) {
- my $content = $res->content;
+sub configure_emails_on_push_service {
+ my ($project, $services) = @_;
- print "Content:\n".Dumper($content) if($cfg{debug});
+ my $service = get_service($services, 'emails-on-push');
- print "Activated Emails on push service for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+ print "Emails on push:\n". Dumper($service) if($cfg{debug});
- return 1;
- }
- else {
- print "Error: Request failed! ($url)\n";
- print "HTTP Status: ".$res->code." ".$res->message."\n";
- print $res->content if($res->content);
+ if(!$service || !$service->{active}) {
+ print "Activating Emails on push for: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
- return;
- }
+ my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/integrations/emails-on-push';
+
+ my %param = (
+ recipients => $cfg{email_recipients},
+ disable_diffs => 'false',
+ send_from_committer_email => 'false',
+ push_events => 'true',
+ tag_push_events => 'true',
+ branches_to_be_notified => 'all',
+ );
+
+ print "param:\n".Dumper(\%param) if($cfg{debug});
+
+ my $req = HTTP::Request::Common::PUT($url, [ %param ]);
+ $req->header('PRIVATE-TOKEN' => $cfg{token});
+
+ my $res = $ua->request($req);
+ if($res->is_success) {
+ my $content = $res->content;
+
+ print "Content:\n".Dumper($content) if($cfg{debug});
+
+ print "Activated Emails on push service for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+
+ return 1;
}
else {
- print "Emails on push service already active for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+ print "Error: Request failed! ($url)\n";
+ print "HTTP Status: ".$res->code." ".$res->message."\n";
+ print $res->content if($res->content);
- return 2;
+ return;
}
}
else {
- print "Error: Request failed! ($url)\n";
- print "HTTP Status: ".$res->code." ".$res->message."\n";
- print $res->content if($res->content);
+ print "Emails on push service already active for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
- return;
+ return 2;
}
}
sub configure_irker_service {
- my ($project) = @_;
-
- my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/services/irker';
-
- my $req = new HTTP::Request(GET => $url);
- $req->header('PRIVATE-TOKEN' => $cfg{token});
-
- my $res = $ua->request($req);
- if($res->is_success) {
- my $content = $res->content;
+ my ($project, $services) = @_;
- my $data = decode_json($content);
+ my $service = get_service($services, 'irker');
- print "Irker:\n". Dumper($data) if($cfg{debug});
+ print "Irker:\n". Dumper($service) if($cfg{debug});
- if(!$data->{active}) {
- print "Activating Irker for: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+ if(!$service || !$service->{active}) {
+ print "Activating Irker for: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
- my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/services/irker';
+ my $url = $cfg{url}.'/projects/'.uri_escape($project->{id}).'/integrations/irker';
- my %param = (
- recipients => $cfg{irc_recipients},
- colorize_messages => 'true',
- );
-
- print "param:\n".Dumper(\%param) if($cfg{debug});
+ my %param = (
+ recipients => $cfg{irc_recipients},
+ colorize_messages => 'true',
+ );
- my $req = HTTP::Request::Common::PUT($url, [ %param ]);
- $req->header('PRIVATE-TOKEN' => $cfg{token});
+ print "param:\n".Dumper(\%param) if($cfg{debug});
- my $res = $ua->request($req);
- if($res->is_success) {
- my $content = $res->content;
+ my $req = HTTP::Request::Common::PUT($url, [ %param ]);
+ $req->header('PRIVATE-TOKEN' => $cfg{token});
- print "Content:\n".Dumper($content) if($cfg{debug});
+ my $res = $ua->request($req);
+ if($res->is_success) {
+ my $content = $res->content;
- print "Activated Irker service for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+ print "Content:\n".Dumper($content) if($cfg{debug});
- return 1;
- }
- else {
- print "Error: Request failed! ($url)\n";
- print "HTTP Status: ".$res->code." ".$res->message."\n";
- print $res->content if($res->content);
+ print "Activated Irker service for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
- return;
- }
+ return 1;
}
else {
- print "Irker service already active for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
+ print "Error: Request failed! ($url)\n";
+ print "HTTP Status: ".$res->code." ".$res->message."\n";
+ print $res->content if($res->content);
- return 2;
+ return;
}
}
else {
- print "Error: Request failed! ($url)\n";
- print "HTTP Status: ".$res->code." ".$res->message."\n";
- print $res->content if($res->content);
+ print "Irker service already active for project: ". $project->{name} ." (". $project->{id} .")\n" if($cfg{verbose});
- return;
+ return 2;
}
}
View it on GitLab: https://salsa.debian.org/debian-gis-team/scripts/-/commit/c7ec2167ac324c147de03895cf275a52cfcdfb56
--
View it on GitLab: https://salsa.debian.org/debian-gis-team/scripts/-/commit/c7ec2167ac324c147de03895cf275a52cfcdfb56
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20220428/a35b48bd/attachment-0001.htm>
More information about the Pkg-grass-devel
mailing list