Commit d6bfaf81 authored by Robert Lyon's avatar Robert Lyon

Need to check correct branch in json info when querying gerrit

When backporting patches the different branch info comes thru and the
first item in array is not necessarily the one we want to check so we
need to check the object with right branch information.
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent f88cc778
......@@ -7,6 +7,7 @@
$git_commit_id = $argv[2];
$first_commit = $argv[3];
$gerrit_branch = $argv[4];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://reviews.mahara.org/changes/?q=' . $git_commit_id . '&o=LABELS&o=CURRENT_REVISION&pp=0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
......@@ -15,19 +16,26 @@ curl_close($ch);
// We need to fetch the json line from the result
$content = explode("\n", $content);
$content = json_decode($content[1]);
// Find the array hash that relates to this check
$k = 0;
foreach ($content as $key => $item) {
if ($item->branch == $gerrit_branch) {
$k = $key;
}
}
// Doublecheck to see if this has already been merged
if ($content[0]->status == 'MERGED') {
if ($content[$k]->status == 'MERGED') {
echo 2;
exit;
}
if ($content[0]->status == 'ABANDONED') {
if ($content[$k]->status == 'ABANDONED') {
echo 4;
exit;
}
// Check that the patch we are testing is the latest (current) patchset in series
if ($content[0]->current_revision != $git_commit_id) {
if ($content[$k]->current_revision != $git_commit_id) {
echo 3;
exit;
}
......@@ -35,13 +43,13 @@ if ($content[0]->current_revision != $git_commit_id) {
// Now check to see if anyone has rejected this.
// We don't want to reject the patch if auto test has failed as we are re-testing now
// but we do want to reject patch if the parent has failed auto test.
if (!empty($first_commit) && empty($content[0]->labels->{'Verified'}->rejected) &&
empty($content[0]->labels->{'Code-Review'}->rejected)) {
if (!empty($first_commit) && empty($content[$k]->labels->{'Verified'}->rejected) &&
empty($content[$k]->labels->{'Code-Review'}->rejected)) {
echo 0;
}
else if (empty($content[0]->labels->{'Verified'}->rejected) &&
empty($content[0]->labels->{'Code-Review'}->rejected) &&
empty($content[0]->labels->{'Automated-Tests'}->rejected)) {
else if (empty($content[$k]->labels->{'Verified'}->rejected) &&
empty($content[$k]->labels->{'Code-Review'}->rejected) &&
empty($content[$k]->labels->{'Automated-Tests'}->rejected)) {
echo 0;
}
else {
......
......@@ -70,7 +70,7 @@ foreach ($the_list as $line) {
}
# check if the commit or it's parents have been rejected
$outcome = shell_exec_or_die(PHP_BINARY . " $HOME/mahara/mahara-scripts/jenkins/gerrit_query.php -- $line $firstcommit");
$outcome = shell_exec_or_die(PHP_BINARY . " $HOME/mahara/mahara-scripts/jenkins/gerrit_query.php -- $line $firstcommit $GERRIT_BRANCH");
switch ($outcome) {
case 1:
echo "The patch with git commit id $line has been rejected\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment