Skip to content

Commit

Permalink
NEW Update GitHub labels
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jan 25, 2024
1 parent 0e8f7c3 commit 98c0cf6
Show file tree
Hide file tree
Showing 5 changed files with 450 additions and 83 deletions.
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ relevant branch e.g. `5` will be used depending on the command-line `--branch` o
It will run all scripts in the `scripts/any` folder and then run all scripts in the applicable
`scripts/<cms-version>` folder depending on the command-line `--branch` option that's passed in.

This tool can also be used to standardise GitHub labels on all supported repositories.

## GitHub Token

This tool creates pull-request via the GitHub API. You need to set the `MS_GITHUB_TOKEN` environment variable in order
Expand All @@ -22,12 +24,17 @@ then you will get a 404 error when attempting to create pull-requests.

Delete this token once you have finished.

## Usage
## Installation

```bash
git clone [email protected]:silverstripe/module-standardiser.git
cd module-standardiser
composer install
```

## Usage - Standardising module files

```bash
MS_GITHUB_TOKEN=<token> php run.php update <options>
```

Expand All @@ -36,7 +43,7 @@ MS_GITHUB_TOKEN=<token> php run.php update <options>
MS_GITHUB_TOKEN=abc123 php run.php update --cms-major=5 --branch=next-minor --dry-run --only=silverstripe-config,silverstripe-assets
```

## Command line options:
### Command line options:

| Flag | Description |
| ---- | ------------|
Expand All @@ -51,15 +58,15 @@ MS_GITHUB_TOKEN=abc123 php run.php update --cms-major=5 --branch=next-minor --dr

**Note** that using `--branch=github-default` will only run scripts in the `scripts/default-branch` directory.

## GitHub API secondary rate limit
### GitHub API secondary rate limit

You may hit a secondary GitHub rate limit because this tool may create too many pull-requests in a short space of time.
To help with this the tool will always output the urls of all pull-requests updated and also the repos that were
updated so you can add them to the --exclude flag on subsequent re-runs.

## Adding new scripts
### Adding new scripts

### Where to add your script
#### Where to add your script

- `scripts/cms-<version>` to run on a specific cms-major
- `scripts/cms-any` to run on any cms-major
Expand All @@ -76,6 +83,28 @@ Do not use functions in `funcs_utils.php` as they are not intended to be used in
Scripts will be automatically wrapped in an anoymous function so you do not need to worry about variables crossing
over into different scripts.

## Usage - Standardising GitHub labels

```bash
#
MS_GITHUB_TOKEN=<token> php run.php labels <options>
```

**Example usage:**
```bash
MS_GITHUB_TOKEN=abc123 php run.php labels --dry-run --only=silverstripe-config,silverstripe-assets
```

### Command line options:

| Flag | Description |
| ---- | ------------|
| --cms-major=[version] | The major version of CMS to use (default: 5) |
| --only=[modules] | Only include the specified modules (without account prefix) separated by commas e.g. `silverstripe-config,silverstripe-assets` |
| --exclude=[modules] | Exclude the specified modules (without account prefix) separated by commas e.g. `silverstripe-mfa,silverstripe-totp` |
| --dry-run | Do not update labels in GitHub, output to terminal only |
| --no-delete | Do not delete `_data` and `modules` directories before running |

## Updating the tool when a new major version of CMS is updated

Update the `CURRENT_CMS_MAJOR` constant in `run.php`
53 changes: 53 additions & 0 deletions funcs_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,24 @@ function output_repos_with_prs_created()
$io->writeln('');
}

/**
* Ouputs a list of repos that that had labels updated
* This is intended to be used when there was an error with a run (probably a secondary rate limit) and then
* copy pasted into the --exclude option for the next run
*/
function output_repos_with_labels_updated()
{
if (running_unit_tests()) {
return;
}
global $REPOS_WITH_LABELS_UPDATED;
$io = io();
$io->writeln('');
$io->writeln('Repos with labels created (add to --exclude if you need to re-run):');
$io->writeln(implode(',', $REPOS_WITH_LABELS_UPDATED));
$io->writeln('');
}

/**
* Works out which branch in a module to checkout before running scripts on it
*
Expand Down Expand Up @@ -407,3 +425,38 @@ function current_branch_cms_major(
}
return (string) $cmsMajor;
}

function setup_directories($input) {
if (!$input->getOption('no-delete')) {
remove_dir(DATA_DIR);
remove_dir(MODULES_DIR);
}
if (!file_exists(DATA_DIR)) {
mkdir(DATA_DIR);
}
if (!file_exists(MODULES_DIR)) {
mkdir(MODULES_DIR);
}
}

function filtered_modules($cmsMajor, $input) {
$modules = supported_modules($cmsMajor);
if ($cmsMajor === CURRENT_CMS_MAJOR) {
// only include extra_repositories() when using the current CMS major version because the extra rexpositories
// don't have multi majors branches supported e.g. gha-generate-matrix
$modules = array_merge($modules, extra_repositories());
}
if ($input->getOption('only')) {
$only = explode(',', $input->getOption('only'));
$modules = array_filter($modules, function ($module) use ($only) {
return in_array($module['repo'], $only);
});
}
if ($input->getOption('exclude')) {
$exclude = explode(',', $input->getOption('exclude'));
$modules = array_filter($modules, function ($module) use ($exclude) {
return !in_array($module['repo'], $exclude);
});
}
return $modules;
}
Loading

0 comments on commit 98c0cf6

Please sign in to comment.