| #!/usr/bin/env perl |
| use strict; |
| use warnings; |
| use Mojo::File 'tempfile'; |
| use Mojo::UserAgent; |
| use Cwd qw(); |
| |
| 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!/pull/(\d+?)$!; |
| |
| my $ua = Mojo::UserAgent->new; |
| |
| print "Fetch $url...\n"; |
| |
| my $pr = $1; |
| 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'); |
| |
| |
| my $path = Cwd::abs_path(); |
| |
| # Kustvakt |
| if ($path =~ m!Kustvakt/?$!) { |
| _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 ($path =~ m!KalamarExportPlugin/?$!) { |
| _check('JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test'); |
| } |
| |
| # KorapSRU |
| elsif ($path =~ m!KorapSRU/?$!) { |
| _check('JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64" mvn clean test'); |
| } |
| |
| # Unknown |
| else { |
| print "Unknown directory!\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. |
| The detection paths for the repository specific actions may |
| differ. It's probably beneficial to make this dependent on the |
| GitHub URL instead of the local repository ... |