blob: ab3d201fc9e0f6ae16cc84585477f383bd0c8088 [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) {
Akron88ddd4a2022-11-08 10:41:35 +010029 print 'git-gerrit-pull https://github.com/KorAP/.../pull/..' . "\n";
30 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
Akron88ddd4a2022-11-08 10:41:35 +010069# KorapSRU
Akron74994cf2022-11-15 14:28:00 +010070elsif ($project =~ m!^KorapSRU$!i) {
Akron88ddd4a2022-11-08 10:41:35 +010071 _check('JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test');
72}
73
Akron74994cf2022-11-15 14:28:00 +010074# Unknown Project
Akron88ddd4a2022-11-08 10:41:35 +010075else {
Akron74994cf2022-11-15 14:28:00 +010076 print "Unknown project $project!\n\n";
Akron88ddd4a2022-11-08 10:41:35 +010077 exit(1);
78};
79
80
81
82_check('git commit --amend --no-edit');
83
84{
85 my $ret = `git log -1 --pretty=%B`;
86 my $newret = '';
87 my $change_id = '';
88 my $first = 1;
89 foreach my $line (split "\n", $ret) {
90 if ($first) {
91 chomp $line;
92 $line .= " (closes #$pr)\n";
93 $first = 0;
94 }
95 elsif ($line =~ /^Change-Id: /) {
96 $change_id = $line;
97 next;
98 };
99 $newret .= $line . "\n";
100 };
101
102 if ($change_id) {
103 $newret .= "\n" . $change_id."\n\n";
104 };
105
106 my $msg_file = tempfile();
107 $msg_file->spurt($newret);
108
109 print "===================================\n";
110 print $newret;
111 print "===================================\n";
112
113 _check('git commit -F ' . $msg_file . ' --amend');
114};
115
Akron0e9e5f52022-11-23 09:47:47 +0100116_check('git push origin HEAD:refs/for/master');
Akron88ddd4a2022-11-08 10:41:35 +0100117
118_check('git checkout master');
119_check('git branch -D ' . $branch);
120
121print "\n\nEverything done - thank you!\n\n"
122
123__END__
124
125=pod
126
127This script is an alternative to C<import_github_pull_requests>
128that ignores CI results on github and just requires the
129URL of a specific GH pull request to send it through Gerrit.