Skip to content

Commit

Permalink
Merge pull request #58 from creative-commoners/pulls/main/unsupported
Browse files Browse the repository at this point in the history
NEW Remove supported badge from unsupported modules
  • Loading branch information
GuySartorelli authored Jun 13, 2024
2 parents da766e5 + b794429 commit e33d114
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ MS_GITHUB_TOKEN=abc123 php run.php update --cms-major=5 --branch=next-minor --dr
| --dry-run | Do not push to github or create pull-requests |
| --account | GitHub account to use for creating pull-requests (default: creative-commoners) |
| --no-delete | Do not delete `_data` and `_modules` directories before running |
| --unsupported-default-branch | Only update unsupported modules that were supported in the previous CMS major. Will use the GitHub default branch for that repository. Can not be used with the `--cms-major` option and will ignore the `--branch` option. |
| --update-prs | Update existing open PRs instead of creating new PRs |

**Note** that using `--branch=github-default` will only run scripts in the `scripts/default-branch` directory.
**Note** that the following flags use non-standard directories for their scripts:
- Using `--branch=github-default` will only run scripts in the `scripts/default-branch` directory.
- Using `--unsupported-default-branch` will only run scripts in the `scripts/cms-unsupported` directory.

### GitHub API secondary rate limit

Expand Down
18 changes: 18 additions & 0 deletions funcs_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,24 @@ function filtered_modules($cmsMajor, $input)
$cmsMajor === MetaData::HIGHEST_STABLE_CMS_MAJOR
);

if ($input->getOption('unsupported-default-branch')) {
$prevCmsMajor = $cmsMajor - 1;
$prevCmsRepos = MetaData::removeReposNotInCmsMajor(
MetaData::getAllRepositoryMetaData(false),
$prevCmsMajor,
false
);
$repoGithubs = array_map(fn($repo) => $repo['github'], $repos);
$unsupportedRepos = [];
foreach ($prevCmsRepos as $prevCmsRepo) {
if (in_array($prevCmsRepo['github'], $repoGithubs)) {
continue;
}
$unsupportedRepos[] = $prevCmsRepo;
}
$repos = $unsupportedRepos;
}

$modules = convert_repos_data_to_modules($repos);

if ($input->getOption('only')) {
Expand Down
7 changes: 7 additions & 0 deletions run.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
InputOption::VALUE_NONE,
'Do not delete _data and _modules directories before running'
];
$optionUnsupported = [
'unsupported-default-branch',
null,
InputOption::VALUE_NONE,
'Only update unsupported modules that were supported in the previous CMS major. Will use the GitHub default branch for each repository. Can not be used with the --cms-major option and will ignore the --branch option.'
];
$optionUpdatePrs = [
'update-prs',
null,
Expand All @@ -98,6 +104,7 @@
->addOption(...$optionDryRun)
->addOption(...$optionAccount)
->addOption(...$optionNoDelete)
->addOption(...$optionUnsupported)
->addOption(...$optionUpdatePrs)
->setCode($updateCommand);

Expand Down
8 changes: 8 additions & 0 deletions scripts/cms-unsupported/readme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

if (check_file_exists('README.md')) {
$contents = read_file('README.md');
$rx = "#(^|\n)\[!\[Silverstripe supported module\].+?\n#si";
$contents = ltrim(preg_replace($rx, "\n", $contents), "\n");
write_file_even_if_exists('README.md', $contents);
}
15 changes: 13 additions & 2 deletions update_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
// setup directories
setup_directories($input);

// unsupported-default-branch option must not be used with cms-major option
if ($input->getOption('unsupported-default-branch') && $input->getOption('cms-major')) {
error('The --unsupported-default-branch option must not be used with the --cms-major option');
}

// unsupported-default-branch automatically sets branch option to github-default
if ($input->getOption('unsupported-default-branch')) {
$input->setOption('branch', 'github-default');
}
// branch
$branchOption = $input->getOption('branch') ?: DEFAULT_BRANCH;
if (!in_array($branchOption, BRANCH_OPTIONS)) {
Expand All @@ -31,7 +40,9 @@
$modules = filtered_modules($cmsMajor, $input);

// script files
if ($branchOption === 'github-default') {
if ($input->getOption('unsupported-default-branch')) {
$scriptFiles = script_files('unsupported');
} elseif ($branchOption === 'github-default') {
$scriptFiles = script_files('default-branch');
} else {
$scriptFiles = array_merge(
Expand Down Expand Up @@ -66,7 +77,7 @@
}
cmd("git remote add pr-remote $prOrigin", $MODULE_DIR);

$useDefaultBranch = has_wildcard_major_version_mapping();
$useDefaultBranch = has_wildcard_major_version_mapping() || $branchOption === 'github-default';

if ($input->getOption('update-prs')) {
// checkout latest existing pr branch
Expand Down

0 comments on commit e33d114

Please sign in to comment.