blob: f9ef2b875a4999587585154a997036eaf6374c5d [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;
6use Cwd qw();
7
8our @ARGV;
9
10my $url = $ARGV[0];
11
12sub _check {
13 my $cmd = shift;
14 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;
20 } else {
21 exit;
22 };
23};
24
25unless ($url ) {
26 print 'git-gerrit-pull https://github.com/KorAP/.../pull/..' . "\n";
27 exit;
28};
29
30_check('git checkout master');
31
32_check('git pull origin master');
33
34$url =~ m!/pull/(\d+?)$!;
35
36my $ua = Mojo::UserAgent->new;
37
38print "Fetch $url...\n";
39
40my $pr = $1;
41my $branch = $ua->get($url)->res->dom->at('.commit-ref.head-ref')->all_text;
42
43_check('git fetch github pull/' . $pr . '/head:' . $branch);
44_check('git checkout ' . $branch);
45_check('git rebase master');
46
47
48my $path = Cwd::abs_path();
49
50# Kustvakt
51if ($path =~ m!Kustvakt/?$!) {
52 _check('cd core && JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean install');
53 _check('cd lite && JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test');
54 _check('cd full && JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test');
55}
56
57# KalamarExport-Plugin
58elsif ($path =~ m!KalamarExportPlugin/?$!) {
59 _check('JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test');
60}
61
62# KorapSRU
63elsif ($path =~ m!KorapSRU/?$!) {
64 _check('JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test');
65}
66
67# Unknown
68else {
69 print "Unknown directory!\n\n";
70 exit(1);
71};
72
73
74
75_check('git commit --amend --no-edit');
76
77{
78 my $ret = `git log -1 --pretty=%B`;
79 my $newret = '';
80 my $change_id = '';
81 my $first = 1;
82 foreach my $line (split "\n", $ret) {
83 if ($first) {
84 chomp $line;
85 $line .= " (closes #$pr)\n";
86 $first = 0;
87 }
88 elsif ($line =~ /^Change-Id: /) {
89 $change_id = $line;
90 next;
91 };
92 $newret .= $line . "\n";
93 };
94
95 if ($change_id) {
96 $newret .= "\n" . $change_id."\n\n";
97 };
98
99 my $msg_file = tempfile();
100 $msg_file->spurt($newret);
101
102 print "===================================\n";
103 print $newret;
104 print "===================================\n";
105
106 _check('git commit -F ' . $msg_file . ' --amend');
107};
108
109_check('git-gerrit');
110
111_check('git checkout master');
112_check('git branch -D ' . $branch);
113
114print "\n\nEverything done - thank you!\n\n"
115
116__END__
117
118=pod
119
120This script is an alternative to C<import_github_pull_requests>
121that ignores CI results on github and just requires the
122URL of a specific GH pull request to send it through Gerrit.
123The detection paths for the repository specific actions may
124differ. It's probably beneficial to make this dependent on the
125GitHub URL instead of the local repository ...