| #!/usr/bin/env perl |
| use strict; |
| use warnings; |
| use Mojo::File 'tempfile'; |
| use Mojo::UserAgent; |
| |
| our @ARGV; |
| |
| my $url = $ARGV[0]; |
| |
| sub _check { |
| my $cmd = shift; |
| print "\n\n" . 'Do "' . $cmd . '"? (y/n)', "\n"; |
| |
| my $x = <STDIN>; |
| chomp($x); |
| if ($x eq 'y' || $x eq 'Y') { |
| system $cmd; |
| } else { |
| exit; |
| }; |
| }; |
| |
| unless ($url) { |
| print 'git-gerrit-pull https://github.com/KorAP/.../pull/..' . "\n"; |
| exit; |
| }; |
| |
| _check('git checkout master'); |
| |
| _check('git pull origin master'); |
| |
| $url =~ m!KorAP/([^/]+?)/pull/(\d+?)$!; |
| |
| my $ua = Mojo::UserAgent->new; |
| |
| print "Fetch $url...\n"; |
| |
| my $project = $1; |
| my $pr = $2; |
| my $branch = $ua->get($url)->res->dom->at('.commit-ref.head-ref')->all_text; |
| |
| _check('git fetch github pull/' . $pr . '/head:' . $branch); |
| _check('git checkout ' . $branch); |
| _check('git rebase master'); |
| |
| |
| # Kustvakt |
| if ($project =~ m!^Kustvakt$!i) { |
| _check('cd core && JAVA_HOME="/usr/lib/jvm/java-1.11.0-openjdk-amd64" mvn clean install'); |
| _check('cd lite && JAVA_HOME="/usr/lib/jvm/java-1.11.0-openjdk-amd64" mvn clean test'); |
| _check('cd full && JAVA_HOME="/usr/lib/jvm/java-1.11.0-openjdk-amd64" mvn clean test'); |
| } |
| |
| # KalamarExport-Plugin |
| elsif ($project =~ m!^Kalamar-Plugin-Export$!i) { |
| _check('JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test'); |
| } |
| |
| # KorapSRU |
| elsif ($project =~ m!^KorapSRU$!i) { |
| _check('JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test'); |
| } |
| |
| # Unknown Project |
| else { |
| print "Unknown project $project!\n\n"; |
| exit(1); |
| }; |
| |
| |
| |
| _check('git commit --amend --no-edit'); |
| |
| { |
| my $ret = `git log -1 --pretty=%B`; |
| my $newret = ''; |
| my $change_id = ''; |
| my $first = 1; |
| foreach my $line (split "\n", $ret) { |
| if ($first) { |
| chomp $line; |
| $line .= " (closes #$pr)\n"; |
| $first = 0; |
| } |
| elsif ($line =~ /^Change-Id: /) { |
| $change_id = $line; |
| next; |
| }; |
| $newret .= $line . "\n"; |
| }; |
| |
| if ($change_id) { |
| $newret .= "\n" . $change_id."\n\n"; |
| }; |
| |
| my $msg_file = tempfile(); |
| $msg_file->spurt($newret); |
| |
| print "===================================\n"; |
| print $newret; |
| print "===================================\n"; |
| |
| _check('git commit -F ' . $msg_file . ' --amend'); |
| }; |
| |
| _check('git-gerrit'); |
| |
| _check('git checkout master'); |
| _check('git branch -D ' . $branch); |
| |
| print "\n\nEverything done - thank you!\n\n" |
| |
| __END__ |
| |
| =pod |
| |
| This script is an alternative to C<import_github_pull_requests> |
| that ignores CI results on github and just requires the |
| URL of a specific GH pull request to send it through Gerrit. |