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