diff --git a/build/github_rebase.php b/build/github_rebase.php index 8016fbc1ae2b8..3b58ffd9d050e 100644 --- a/build/github_rebase.php +++ b/build/github_rebase.php @@ -3,9 +3,9 @@ /** * This script rebases Joomla Github Pull Requests to the target branch * - * @package Joomla.Build + * @package Joomla.Build * @copyright (C) 2022 Open Source Matters, Inc. - * @license GNU General Public License version 2 or later; see LICENSE.txt + * @license GNU General Public License version 2 or later; see LICENSE.txt */ // Set defaults @@ -139,53 +139,65 @@ if (!empty($prNumber)) { echo "Retrieving Pull Request " . $prNumber . "...\n"; - $cmd = $gh . ' pr view ' . $prNumber . ' --json ' . implode(',', $fieldList); + $cmdList = $gh . ' pr view ' . $prNumber . ' --json ' . implode(',', $fieldList); } else { echo "Retrieving Pull Request list...\n"; - $cmd = $gh . ' pr list --limit 1000 --json ' . implode(',', $fieldList) . ' --search "is:pr is:open ' . $branches . '"'; + $cmdList = $gh . ' pr list --limit 20 --json ' . implode(',', $fieldList) . ' --search "is:pr is:open ' . $branches . '"'; } -$output = []; -exec($cmd, $output, $result); -if ($result !== 0) { - var_dump([$cmd, $output, $result]); - die('Unable to retrieve PR list.'); -} +while (true) { + $outputList = []; + $result = null; -$json = $output[0]; + exec($cmdList, $outputList, $result); -if (!empty($prNumber)) { - $json = '[' . $json . ']'; -} + if ($result !== 0) { + var_dump([$cmdList, $outputList, $result]); + die('Unable to retrieve PR list.'); + } -$list = json_decode($json, true); + $json = $outputList[0]; -echo "\nFound " . \count($list) . " pull request(s).\n"; + if (!empty($prNumber)) { + $json = '[' . $json . ']'; + } -foreach ($list as $pr) { - echo "Rebase #" . $pr['number'] . "\n"; + $list = json_decode($json, true); - $cmd = $gh . ' pr edit ' . $pr['url'] . ' --base ' . $targetBranch; - $output = []; - if (!$tryRun) { - exec($cmd, $output, $result); - if ($result !== 0) { - var_dump([$cmd, $output, $result]); - die('Unable to set target branch for pr #' . $pr['number']); - } - } else { - echo "TRY RUN: " . $cmd . "\n"; + echo "\nFound " . \count($list) . " pull request(s).\n"; + + if (\count($list) === 0) { + break; } - $cmd = $gh . ' pr comment ' . $pr['url'] . ' --body "' . $reason . '"'; - $output = []; - if (!$tryRun) { - exec($cmd, $output, $result); - if ($result !== 0) { - var_dump([$cmd, $output, $result]); - die('Unable to create a comment for pr #' . $pr['number']); + foreach ($list as $pr) { + echo "Rebase #" . $pr['number'] . "\n"; + + $cmd = $gh . ' pr edit ' . $pr['url'] . ' --base ' . $targetBranch; + $output = []; + $result = null; + + if (!$tryRun) { + exec($cmd, $output, $result); + if ($result !== 0) { + var_dump([$cmd, $output, $result]); + die('Unable to set target branch for pr #' . $pr['number']); + } + } else { + echo "TRY RUN: " . $cmd . "\n"; + } + + $cmd = $gh . ' pr comment ' . $pr['url'] . ' --body "' . $reason . '"'; + $output = []; + + if (!$tryRun) { + exec($cmd, $output, $result); + if ($result !== 0) { + var_dump([$cmd, $output, $result]); + die('Unable to create a comment for pr #' . $pr['number']); + } + } else { + echo "TRY RUN: " . $cmd . "\n"; } - } else { - echo "TRY RUN: " . $cmd . "\n"; } } diff --git a/build/github_update_title.php b/build/github_update_title.php index de220ab77837a..b37d37d5cde99 100644 --- a/build/github_update_title.php +++ b/build/github_update_title.php @@ -118,7 +118,8 @@ "labels", ]; -$branches = 'base:' . implode(' base:', explode(',', $baseBranches)); +$branches = 'base:' . implode(' base:', explode(',', $baseBranches)); +$singleBranch = substr($baseBranches, 0, strpos($baseBranches, '-')); if (!empty($label)) { $branches .= ' label:' . $label; @@ -126,58 +127,79 @@ if (!empty($prNumber)) { echo "Retrieving Pull Request " . $prNumber . "...\n"; - $cmd = $gh . ' pr view ' . $prNumber . ' --json ' . implode(',', $fieldList); + $cmdList = $gh . ' pr view ' . $prNumber . ' --json ' . implode(',', $fieldList); } else { - echo "Retrieving Pull Request list...\n"; - $cmd = $gh . ' pr list --limit 1000 --json ' . implode(',', $fieldList) . ' --search "is:pr is:open ' . $branches . '"'; -} + $notInTitle = 'NOT in:title [' . $singleBranch . ']'; -$output = []; -exec($cmd, $output, $result); -if ($result !== 0) { - var_dump([$cmd, $output, $result]); - die('Unable to retrieve PR list.'); + echo "Retrieving Pull Request list...\n"; + $cmdList = $gh . ' pr list --limit 20 --json ' . implode(',', $fieldList) . ' --search "' . $notInTitle .' is:pr is:open ' . $branches . '"'; } -$json = $output[0]; +while (true) { + $outputList = []; + $result = null; -if (!empty($prNumber)) { - $json = '[' . $json . ']'; -} + exec($cmdList, $outputList, $result); -$list = json_decode($json, true); + if ($result !== 0) { + var_dump([$cmdList, $outputList, $result]); + die('Unable to retrieve PR list.'); + } -echo "\nFound " . \count($list) . " pull request(s).\n"; + $json = $outputList[0]; -foreach ($list as $pr) { - echo "Change Title for PR #" . $pr['number'] . "\n"; + if (!empty($prNumber)) { + $json = '[' . $json . ']'; + } - $branch = substr($pr['baseRefName'], 0, strpos($pr['baseRefName'], '-')); + $list = json_decode($json, true); - $title = $pr['title']; + echo "\nFound " . \count($list) . " pull request(s).\n"; - if (str_contains($title, ']') && strpos($title, ']') < 10) { - $title = substr($title, strpos($title, ']') + 1); + if (\count($list) === 0) { + break; } - $newTitle = '[' . $branch . '] ' . trim($title); + foreach ($list as $pr) { + echo "Change Title for PR #" . $pr['number'] . "\n"; - if ($newTitle === $pr['title']) { - continue; - } + $branch = substr($pr['baseRefName'], 0, strpos($pr['baseRefName'], '-')); - echo 'OLD: ' . trim($pr['title']) ."\n"; - echo 'NEW: ' . $newTitle ."\n"; + $title = $pr['title']; - $cmd = $gh . ' pr edit ' . $pr['url'] . ' --title "' . str_replace('"', '\"', $newTitle) . '"'; - $output = []; - if (!$tryRun) { - exec($cmd, $output, $result); - if ($result !== 0) { - var_dump([$cmd, $output, $result]); - die('Unable to set target branch for pr #' . $pr['number']); + if (str_contains($title, ']') && strpos($title, ']') < 10) { + $title = substr($title, strpos($title, ']') + 1); + } + + $title = trim($title); + + if (!str_starts_with($title, '[')) { + $title = ' ' . $title; + } + + $newTitle = '[' . $branch . ']' . $title; + + if ($newTitle === $pr['title']) { + continue; + } + + $newTitleEscaped = escapeShellArg($newTitle); + + echo 'OLD: ' . trim($pr['title']) . "\n"; + echo 'NEW: ' . $newTitle . "\n"; + + $cmd = $gh . ' pr edit ' . $pr['url'] . ' --title ' . $newTitleEscaped; + $output = []; + $result = null; + + if (!$tryRun) { + exec($cmd, $output, $result); + if ($result !== 0) { + var_dump([$cmd, $output, $result]); + die('Unable to set target branch for pr #' . $pr['number']); + } + } else { + echo "TRY RUN: " . $cmd . "\n"; } - } else { - echo "TRY RUN: " . $cmd . "\n"; } }