blob: 96029f7d78b3d634fe450b954b8de9ce8abd93b1 [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
51
Akron88ddd4a2022-11-08 10:41:35 +010052# Kustvakt
Akron74994cf2022-11-15 14:28:00 +010053if ($project =~ m!^Kustvakt$!i) {
Akron70a26692022-11-15 14:04:01 +010054 _check('cd core && JAVA_HOME="/usr/lib/jvm/java-1.11.0-openjdk-amd64" mvn clean install');
55 _check('cd lite && JAVA_HOME="/usr/lib/jvm/java-1.11.0-openjdk-amd64" mvn clean test');
56 _check('cd full && JAVA_HOME="/usr/lib/jvm/java-1.11.0-openjdk-amd64" mvn clean test');
Akron88ddd4a2022-11-08 10:41:35 +010057}
58
59# KalamarExport-Plugin
Akron74994cf2022-11-15 14:28:00 +010060elsif ($project =~ m!^Kalamar-Plugin-Export$!i) {
Akron88ddd4a2022-11-08 10:41:35 +010061 _check('JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test');
62}
63
Akron39dae912022-11-23 09:41:53 +010064# Koral
65elsif ($project =~ m!^Koral$!i) {
66 _check('JAVA_HOME="/usr/lib/jvm/java-1.11.0-openjdk-amd64" mvn clean test');
67}
68
Akron579efe02023-02-28 09:52:26 +010069# Kalamar-Plugin-ExternalResources
70elsif ($project =~ m!^Kalamar-Plugin-ExternalResources$!i) {
71 _check('go test ./...');
72}
73
Akron88ddd4a2022-11-08 10:41:35 +010074# KorapSRU
Akron74994cf2022-11-15 14:28:00 +010075elsif ($project =~ m!^KorapSRU$!i) {
Akron88ddd4a2022-11-08 10:41:35 +010076 _check('JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test');
77}
78
Akron579efe02023-02-28 09:52:26 +010079# KorapSRU
80elsif ($project =~ m!^Datok$!i) {
81 _check('make test');
82}
83
Akron74994cf2022-11-15 14:28:00 +010084# Unknown Project
Akron88ddd4a2022-11-08 10:41:35 +010085else {
Akron74994cf2022-11-15 14:28:00 +010086 print "Unknown project $project!\n\n";
Akron88ddd4a2022-11-08 10:41:35 +010087 exit(1);
88};
89
90
91
92_check('git commit --amend --no-edit');
93
94{
95 my $ret = `git log -1 --pretty=%B`;
96 my $newret = '';
97 my $change_id = '';
98 my $first = 1;
99 foreach my $line (split "\n", $ret) {
100 if ($first) {
101 chomp $line;
102 $line .= " (closes #$pr)\n";
103 $first = 0;
104 }
105 elsif ($line =~ /^Change-Id: /) {
106 $change_id = $line;
107 next;
108 };
109 $newret .= $line . "\n";
110 };
111
112 if ($change_id) {
113 $newret .= "\n" . $change_id."\n\n";
114 };
115
116 my $msg_file = tempfile();
117 $msg_file->spurt($newret);
118
119 print "===================================\n";
120 print $newret;
121 print "===================================\n";
122
123 _check('git commit -F ' . $msg_file . ' --amend');
124};
125
Akron0e9e5f52022-11-23 09:47:47 +0100126_check('git push origin HEAD:refs/for/master');
Akron88ddd4a2022-11-08 10:41:35 +0100127
128_check('git checkout master');
129_check('git branch -D ' . $branch);
130
131print "\n\nEverything done - thank you!\n\n"
132
133__END__
134
135=pod
136
137This script is an alternative to C<import_github_pull_requests>
138that ignores CI results on github and just requires the
139URL of a specific GH pull request to send it through Gerrit.
Helge4d96c362023-06-21 17:06:32 +0200140
141Prerequisites:
142Remote repository "github"
143For Kustvakt and Koral Java 11 at /usr/lib/jvm/java-1.11.0-openjdk-amd6
144For KorapSRU and KalamarExport-Plugin Java 8 at /usr/lib/jvm/java-1.8.0-openjdk-amd6