|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Copyright BibLibre, 2012 |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 8 |
# terms of the GNU General Public License as published by the Free Software |
| 9 |
# Foundation; either version 2 of the License, or (at your option) any later |
| 10 |
# version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 14 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License along |
| 17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
| 18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 |
|
| 20 |
|
| 21 |
=head1 SYNOPSIS |
| 22 |
|
| 23 |
./testbugzillapatches.pl --u yourlogin --p your password |
| 24 |
./testbugzillapatches.pl --help for detailled help |
| 25 |
|
| 26 |
|
| 27 |
=head1 DESCRIPTION |
| 28 |
|
| 29 |
This script will query Koha bugzilla (http://bugs.koha-community.org/bugzilla3/) for all bugs waiting for patch signoff |
| 30 |
and will test that the patches still apply fine. |
| 31 |
|
| 32 |
if a patch apply, nothing is made |
| 33 |
|
| 34 |
if a patch does not apply, the bug status is set to "Does not apply", with a message saying |
| 35 |
"misc/devel/testbugzillapatches.pl has detected that the patch(es) does not apply anymore |
| 36 |
|
| 37 |
=head1 PARAMETERS |
| 38 |
|
| 39 |
\t-u your bugzilla username |
| 40 |
\t-p your bugzilla password |
| 41 |
\t-h or --help help |
| 42 |
\t-d debug mode, will give you more details about what's done |
| 43 |
\t-t test mode, won't submit any comment to bugzilla, will just report what's applying and what's not. |
| 44 |
|
| 45 |
=head1 PRE-REQUISITE |
| 46 |
|
| 47 |
This script must be run in a directory where your git koha is setup. |
| 48 |
|
| 49 |
Git must be uptodate, the script don't try to pull anything from the git repo |
| 50 |
|
| 51 |
=cut |
| 52 |
|
| 53 |
#read parameters |
| 54 |
# u = bugzilla username |
| 55 |
# p = bugzilla password |
| 56 |
use 5.10.0; |
| 57 |
use strict; |
| 58 |
use warnings; |
| 59 |
use Getopt::Long; |
| 60 |
use Pod::Usage; |
| 61 |
|
| 62 |
my $login=''; |
| 63 |
my $password=''; |
| 64 |
my $help=''; |
| 65 |
my $DEBUG=0; |
| 66 |
my $test=0; |
| 67 |
my $doesnotapplylist=''; |
| 68 |
|
| 69 |
GetOptions( 'u' => \$login, |
| 70 |
'p' => \$password, |
| 71 |
'h|help' => \$help, |
| 72 |
'd' => \$DEBUG, |
| 73 |
't' => \$test, |
| 74 |
); |
| 75 |
|
| 76 |
if ($help or not $login) { |
| 77 |
pod2usage(-verbose => $help?2:1 ); |
| 78 |
exit; |
| 79 |
} |
| 80 |
|
| 81 |
# first, retrieve all bugs that needs signoff |
| 82 |
my @buglist = `bugz -u $login -p $password -b http://bugs.koha-community.org/bugzilla3/ search -s "Needs signoff"`; |
| 83 |
# then parse all bugs and try to apply them |
| 84 |
foreach my $bugtotest (@buglist) { |
| 85 |
$bugtotest =~ /(....)(.*)/; |
| 86 |
my $bugnumber = $1; |
| 87 |
if ($bugnumber =~ /\d{4}/) { |
| 88 |
# next unless $bugnumber eq '7261'; |
| 89 |
# bug to test found, try to apply... |
| 90 |
# first checkout master, remove test branch and recreate it |
| 91 |
my $checkout = `git checkout master 2>/dev/null;git branch -D test >/dev/null 2>/dev/null;git checkout -b test 2>/dev/null`; |
| 92 |
my $gitbz; |
| 93 |
# now apply the patch |
| 94 |
$gitbz = `git bz apply $bugnumber <yyyy`; |
| 95 |
# test if things went well or no: |
| 96 |
if ($gitbz =~ /git am --skip/ or $gitbz =~ /BEGIN failed/ or $gitbz =~ /cannot convert from/ ) { |
| 97 |
# git am --skip is the most common string included if the patch fails |
| 98 |
# BEGIN failed happend when you have pre-applypatch git hook and the script don't compile |
| 99 |
# cannot convert from happend when you have a wrongly encoded patch |
| 100 |
# if things went wrong, rollback ! |
| 101 |
my $cancel = `git am --abort`; |
| 102 |
# if something went wrong, checkout any file modified |
| 103 |
my $checkout = `git status -s`; |
| 104 |
foreach (split /\n/, $checkout) { |
| 105 |
my $file_to_checkout = $_; |
| 106 |
next if $file_to_checkout =~ /^\?\?/; |
| 107 |
$file_to_checkout =~ s/^ M //; |
| 108 |
`git checkout $file_to_checkout`; |
| 109 |
} |
| 110 |
if ($gitbz =~ /CONFLICT \(content\): Merge conflict in installer\/data\/mysql\/updatedatabase.pl/) { |
| 111 |
# just issue that there is a conflict in an updatedatabase.pl, don't change bug status |
| 112 |
say "bug $bugnumber has an updatedatabase and don't apply cleanly"; |
| 113 |
} else { |
| 114 |
# the patch does not apply anymore |
| 115 |
$DEBUG and say "!!!!!!!!!!!!! Bug $bugnumber does not apply anymore"; |
| 116 |
if ($test) { |
| 117 |
say "!!!!!!!!!!! Bug $bugnumber does not apply anymore"; |
| 118 |
} else { |
| 119 |
# bugz doesn't accept the status "Patch doesn't apply". Until it's fixed, just report the patch don't apply |
| 120 |
# `bugz -u $login -p $password -b http://bugs.koha-community.org/bugzilla3/ modify -s "Patch doesn't apply" -c "The script misc/devel/testbugzillapatches.pl has detected that this patch does not apply anymore:\n $gitbz" $bugnumber`; |
| 121 |
print "!!!!!!!!!!! Bug $bugnumber does not apply anymore\n"; |
| 122 |
$doesnotapplylist.=",$bugnumber"; |
| 123 |
} |
| 124 |
} |
| 125 |
} else { |
| 126 |
$test and print "+++++++++++ Bug $bugnumber apply cleanly\n"; |
| 127 |
} |
| 128 |
} else { |
| 129 |
$DEBUG and print "NOT A BUG: $bugtotest\n"; |
| 130 |
} |
| 131 |
} |
| 132 |
say $doesnotapplylist; |
| 133 |
|