blob: 9492f6104dafb5988630521b2e81cd7729ccdc95 [file] [log] [blame]
Akron88ddd4a2022-11-08 10:41:35 +01001#!/usr/bin/env perl
2use strict;
3use warnings;
4use Mojo::File 'tempfile';
5use Mojo::UserAgent;
Akron88ddd4a2022-11-08 10:41:35 +01006
7our @ARGV;
8
9my $url = $ARGV[0];
10
11sub _check {
12 my $cmd = shift;
Akron53d18212022-11-15 15:25:17 +010013 CHECK:
Akron88ddd4a2022-11-08 10:41:35 +010014 print "\n\n" . 'Do "' . $cmd . '"? (y/n)', "\n";
15
16 my $x = <STDIN>;
17 chomp($x);
18 if ($x eq 'y' || $x eq 'Y') {
19 system $cmd;
Akron53d18212022-11-15 15:25:17 +010020 } elsif ($x eq 'n' || $x eq 'N') {
Akron88ddd4a2022-11-08 10:41:35 +010021 exit;
Akron53d18212022-11-15 15:25:17 +010022 } else {
23 print "Please answer with 'y' or 'n'.\n";
24 goto CHECK;
Akron88ddd4a2022-11-08 10:41:35 +010025 };
26};
27
Akron74994cf2022-11-15 14:28:00 +010028unless ($url) {
Helge4d96c362023-06-21 17:06:32 +020029 print 'git_gerrit_pull https://github.com/KorAP/.../pull/..' . "\n";
Akron88ddd4a2022-11-08 10:41:35 +010030 exit;
31};
32
33_check('git checkout master');
34
35_check('git pull origin master');
36
Akron74994cf2022-11-15 14:28:00 +010037$url =~ m!KorAP/([^/]+?)/pull/(\d+?)$!;
Akron88ddd4a2022-11-08 10:41:35 +010038
39my $ua = Mojo::UserAgent->new;
40
41print "Fetch $url...\n";
42
Akron74994cf2022-11-15 14:28:00 +010043my $project = $1;
44my $pr = $2;
Akron88ddd4a2022-11-08 10:41:35 +010045my $branch = $ua->get($url)->res->dom->at('.commit-ref.head-ref')->all_text;
46
47_check('git fetch github pull/' . $pr . '/head:' . $branch);
48_check('git checkout ' . $branch);
49_check('git rebase master');
50
margarethaef4275e2023-11-14 10:49:03 +010051my $JAVA17_HOME="/opt/java/jdk-17.0.2";
Akron88ddd4a2022-11-08 10:41:35 +010052
Akron88ddd4a2022-11-08 10:41:35 +010053# Kustvakt
Akron74994cf2022-11-15 14:28:00 +010054if ($project =~ m!^Kustvakt$!i) {
margarethaef4275e2023-11-14 10:49:03 +010055 _check('cd full && JAVA_HOME='.$JAVA17_HOME.' mvn clean test');
Akron88ddd4a2022-11-08 10:41:35 +010056}
57
58# KalamarExport-Plugin
Akron74994cf2022-11-15 14:28:00 +010059elsif ($project =~ m!^Kalamar-Plugin-Export$!i) {
Akron88ddd4a2022-11-08 10:41:35 +010060 _check('JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test');
61}
62
Akron39dae912022-11-23 09:41:53 +010063# Koral
64elsif ($project =~ m!^Koral$!i) {
65 _check('JAVA_HOME="/usr/lib/jvm/java-1.11.0-openjdk-amd64" mvn clean test');
66}
67
Akron579efe02023-02-28 09:52:26 +010068# Kalamar-Plugin-ExternalResources
69elsif ($project =~ m!^Kalamar-Plugin-ExternalResources$!i) {
70 _check('go test ./...');
71}
72
Akron88ddd4a2022-11-08 10:41:35 +010073# KorapSRU
Akron74994cf2022-11-15 14:28:00 +010074elsif ($project =~ m!^KorapSRU$!i) {
Akron88ddd4a2022-11-08 10:41:35 +010075 _check('JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test');
76}
77
Akron579efe02023-02-28 09:52:26 +010078# KorapSRU
79elsif ($project =~ m!^Datok$!i) {
80 _check('make test');
81}
82
Akron74994cf2022-11-15 14:28:00 +010083# Unknown Project
Akron88ddd4a2022-11-08 10:41:35 +010084else {
Akron74994cf2022-11-15 14:28:00 +010085 print "Unknown project $project!\n\n";
Akron88ddd4a2022-11-08 10:41:35 +010086 exit(1);
87};
88
89
90
91_check('git commit --amend --no-edit');
92
93{
94 my $ret = `git log -1 --pretty=%B`;
95 my $newret = '';
96 my $change_id = '';
97 my $first = 1;
98 foreach my $line (split "\n", $ret) {
99 if ($first) {
100 chomp $line;
101 $line .= " (closes #$pr)\n";
102 $first = 0;
103 }
104 elsif ($line =~ /^Change-Id: /) {
105 $change_id = $line;
106 next;
107 };
108 $newret .= $line . "\n";
109 };
110
111 if ($change_id) {
112 $newret .= "\n" . $change_id."\n\n";
113 };
114
115 my $msg_file = tempfile();
116 $msg_file->spurt($newret);
117
118 print "===================================\n";
119 print $newret;
120 print "===================================\n";
121
122 _check('git commit -F ' . $msg_file . ' --amend');
123};
124
Akron0e9e5f52022-11-23 09:47:47 +0100125_check('git push origin HEAD:refs/for/master');
Akron88ddd4a2022-11-08 10:41:35 +0100126
127_check('git checkout master');
128_check('git branch -D ' . $branch);
129
130print "\n\nEverything done - thank you!\n\n"
131
132__END__
133
134=pod
135
136This script is an alternative to C<import_github_pull_requests>
137that ignores CI results on github and just requires the
138URL of a specific GH pull request to send it through Gerrit.
Helge4d96c362023-06-21 17:06:32 +0200139
140Prerequisites:
141Remote repository "github"
142For Kustvakt and Koral Java 11 at /usr/lib/jvm/java-1.11.0-openjdk-amd6
143For KorapSRU and KalamarExport-Plugin Java 8 at /usr/lib/jvm/java-1.8.0-openjdk-amd6