Skip to content

Commit

Permalink
FIX Init array, use $oldName, add REPOS_EXCLUDE, check if label exist…
Browse files Browse the repository at this point in the history
…s before rename
  • Loading branch information
emteknetnz committed Jan 28, 2024
1 parent f2a67c6 commit f242581
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
2 changes: 2 additions & 0 deletions funcs_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ function extra_repositories()
{
$importantRepos = [
'silverstripe/markdown-php-codesniffer',
'silverstripe/silverstripe-standards',
'silverstripe/.github',
];
$modules = [];
// iterating to page 10 will be enough to get all the repos well into the future
Expand Down
51 changes: 40 additions & 11 deletions labels_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@
'type/api-change' => 'type/api-break',
];

// Repos that should not have labels updated because of a lack of API permissions because they are on
// non-silverstripe GitHub accounts, or because they are not applicable
// note that akismet is different from silverstripe-akismet
// installers is composer/installers
const REPOS_EXCLUDE = [
'akismet',
'classproxy',
'installers',
'GridFiedBulkEditingTools',
'phockito',
'silverstripe-debugbar',
'silverstripe-elemental-subsites',
'silverstripe-fluent',
'silverstripe-phockito',
'silverstripe-proxy-db',
'sortablegridfield',
];

$labelsCommand = function(InputInterface $input, OutputInterface $output): int {
// This is the code that is executed when running the 'labels' command

Expand All @@ -61,7 +79,7 @@
foreach ([$modulesCurrentMajor, $modulesPreviousMajor] as $modulesList) {
foreach ($modulesList as $module) {
$repo = $module['repo'];
if (in_array($repo, $repos)) {
if (in_array($repo, $repos) || in_array($repo, REPOS_EXCLUDE)) {
continue;
}
$modules[] = $module;
Expand Down Expand Up @@ -93,17 +111,28 @@
// https://docs.github.com/en/rest/issues/labels#update-a-label
if (array_key_exists($name, LABELS_RENAME)) {
$newName = LABELS_RENAME[$name];
info("Updating label $name to $newName in $repo");
if ($input->getOption('dry-run')) {
info('Not updating label on GitHub because --dry-run option is set');
} else {
github_api($url, ['new_name' => $newName], 'PATCH');
// check if label already exists
$alreadyExists = false;
foreach ($labels as $label) {
if ($newName === $label['name']) {
$alreadyExists = true;
break;
}
}
if (!$alreadyExists) {
info("Updating label $name to $newName in $repo");
if ($input->getOption('dry-run')) {
info('Not updating label on GitHub because --dry-run option is set');
} else {
github_api($url, ['new_name' => $newName], 'PATCH');
}
$oldName = $name;
$name = $newName;
// Update $url replacing the $name at the end with $newName
$url = substr($url, 0, strlen($url) - strlen($oldName)) . $newName;
$labels[$key]['name'] = $newName;
$labels[$key]['url'] = $url;
}
$name = $newName;
// Update $url replacing the $name at the end with $newName
$url = substr($url, 0, strlen($url) - strlen($name)) . $newName;
$labels[$key]['name'] = $newName;
$labels[$key]['url'] = $url;
}

// Delete label
Expand Down
1 change: 1 addition & 0 deletions run.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
$MODULE_DIR = '';
$PRS_CREATED = [];
$REPOS_WITH_PRS_CREATED = [];
$REPOS_WITH_LABELS_UPDATED = [];
$OUT = null;

// options
Expand Down

0 comments on commit f242581

Please sign in to comment.