Skip to content

Commit

Permalink
NEW Update issue/PR templates on default branches
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Dec 20, 2023
1 parent d4c6f4f commit 28ebe37
Show file tree
Hide file tree
Showing 8 changed files with 360 additions and 30 deletions.
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,39 @@ MS_GITHUB_TOKEN=abc123 php run.php update --cms-major=5 --branch=next-minor --dr
| Flag | Description |
| ---- | ------------|
| --cms-major=[version] | The major version of CMS to use (default: 5) |
| --branch=[type] | The branch type to use - next-minor\|next-patch (default: next-patch) |
| --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 |
| --branch=[type] | The branch type to use - `next-minor`\|`next-patch`\|`github-default` (default: `next-patch`) |
| --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 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 |
| --no-delete | Do not delete `_data` and `modules` directories before running |
| --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.

## 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
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

Simply add new scripts to either `scripts/cms-<version>` to run on a specific cms-major or `scripts/cms-any` to run
on any cms-major and they will be automatically picked up and run when the tool is run. Code in the script will be
### Where to add your script

- `scripts/cms-<version>` to run on a specific cms-major
- `scripts/cms-any` to run on any cms-major
- `scripts/default-branch` to only run on the default branch in GitHub

Scripts will be automatically picked up and run when the tool is run. Code in the script will be
passed through `eval()` on the module that is currently being processed.

Make use of functions in `funcs_scripts.php` such as `write_file_if_not_exist()` and `read_file()` to access the
Make use of functions in `funcs_scripts.php` such as `write_file_if_not_exist()` and `read_file()` to access the
correct files in the module that is currently being processed and also to ensure that console output is consistent.

Do not use functions in `funcs_utils.php` as they are not intended to be used in scripts.

Scripts will be automatically wrapped in an anoymous function so you do not need to worry about variables crossing
Scripts will be automatically wrapped in an anoymous function so you do not need to worry about variables crossing
over into different scripts.

## Updating the tool when a new major version of CMS is updated
Expand Down
12 changes: 12 additions & 0 deletions funcs_scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ function is_module()
&& strpos($MODULE_DIR, '/webpack-config') === false;
}

/**
* Determine if the module being processed is a source of documentation
*
* Example usage:
* is_docs()
*/
function is_docs()
{
$moduleName = module_name();
return $moduleName === 'developer-docs' || $moduleName === 'silverstripe-userhelp-content';
}

/**
* Determine if the module being processed is a gha-* repository e.g. gha-ci
*
Expand Down
17 changes: 12 additions & 5 deletions funcs_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,15 @@ function extra_repositories()
*/
function script_files($cmsMajor)
{
if (!ctype_digit($cmsMajor)) {
$cmsMajor = "-$cmsMajor";
if ($cmsMajor === 'default-branch') {
$dir = 'scripts/default-branch';
} else {
if (!ctype_digit($cmsMajor)) {
$cmsMajor = "-$cmsMajor";
}
$scriptFiles = [];
$dir = "scripts/cms$cmsMajor";
}
$scriptFiles = [];
$dir = "scripts/cms$cmsMajor";
if (!file_exists($dir)) {
warning("$dir does not exist, no CMS $cmsMajor specific scripts will be run");
return $scriptFiles;
Expand Down Expand Up @@ -296,14 +300,17 @@ function output_repos_with_prs_created()
*
* Assumes that for each module there is only a single major version per cms-major version
*/
function branch_to_checkout($branches, $currentBranch, $currentBranchCmsMajor, $cmsMajor, $branchOption)
function branch_to_checkout($branches, $defaultBranch, $currentBranch, $currentBranchCmsMajor, $cmsMajor, $branchOption)
{
$offset = (int) $cmsMajor - (int) $currentBranchCmsMajor;
$majorTarget = (int) $currentBranch + $offset;
$branches = array_filter($branches, fn($branch) => preg_match('#^[0-9\.]+$#', $branch));
usort($branches, 'version_compare');
$branches = array_reverse($branches);
switch ($branchOption) {
case 'github-default':
$branchToCheckout = $defaultBranch;
break;
case 'next-patch':
$branchToCheckout = array_values(array_filter(
$branches,
Expand Down
2 changes: 1 addition & 1 deletion run.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// consts
const CURRENT_CMS_MAJOR = '5';
const BRANCH_OPTIONS = ['next-minor', 'next-patch'];
const BRANCH_OPTIONS = ['next-minor', 'next-patch', 'github-default'];
const DEFAULT_BRANCH = 'next-patch';
const DEFAULT_ACCOUNT = 'creative-commoners';
const DATA_DIR = '_data';
Expand Down
106 changes: 106 additions & 0 deletions scripts/default-branch/issue-pr-templates-docs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

// The template used for pull requests
$pullRequestTemplate = <<<EOT
<!--
Thanks for contributing, you're awesome! ⭐
Please read https://docs.silverstripe.org/en/contributing/documentation/ if you haven't contributed to this project recently.
-->
## Description
<!--
Please describe the changes you're making, and the reason for making them.
For visual fixes, please include tested browsers and screenshots.
-->
## Issues
<!--
List all issues here that this pull request fixes/resolves.
If there is no issue already, create a new one! You must link your pull request to at least one issue.
-->
- #
## Pull request checklist
<!--
PLEASE check each of these to ensure you have done everything you need to do!
If there's something in this list you need help with, please ask so that we can assist you.
-->
- [ ] The target branch is correct
- See [branches and commit messages](https://docs.silverstripe.org/en/contributing/documentation#branches-and-commit-messages)
- [ ] All commits are relevant to the purpose of the PR (e.g. no TODO comments, unrelated rewording/restructuring, or arbitrary changes)
- Small amounts of additional changes are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
- [ ] The commit messages follow our [commit message guidelines](https://docs.silverstripe.org/en/contributing/code/#commit-messages)
- [ ] The PR follows our [contribution guidelines](https://docs.silverstripe.org/en/contributing/documentation/)
- [ ] The changes follow our [writing style guide](https://docs.silverstripe.org/en/contributing/documentation/#writing-style)
- [ ] Code examples follow our [coding conventions](https://docs.silverstripe.org/en/contributing/coding_conventions/)
- [ ] CI is green
EOT;

// The template used when clicking "Open a blank issue"
$defaultIssueTemplate = "<!-- Blank templates are for use by maintainers only! If you aren't a maintainer, please go back and pick one of the issue templates. -->";

// Defines configuration for form-style issue templates
$config = <<<EOT
blank_issues_enabled: true
contact_links:
- name: Security Vulnerability
url: https://docs.silverstripe.org/en/contributing/issues_and_bugs/#reporting-security-issues
about: ⚠️ We do not use GitHub issues to track security vulnerability reports. Click "open" on the right to see how to report security vulnerabilities.
- name: Support Question
url: https://www.silverstripe.org/community/
about: We use GitHub issues only to discuss bugs and new features. For support questions, please use one of the support options available in our community channels.
EOT;

// The template used for documentation issues
$documentationIssueTemplate = <<<EOT
# This will be in the developer-docs and user help repos only
name: 📖 Documentation issue
description: Report an issue regarding the documentation content
body:
- type: markdown
attributes:
value: |
We strongly encourage you to [submit a pull request](https://docs.silverstripe.org/en/contributing/documentation/) which resolves the issue.
Issues which are accompanied with a pull request are a lot more likely to be resolved quickly.
- type: textarea
id: pages-affected
attributes:
label: Pages affected
description: A list of links of pages which are affected by this issue
placeholder: |
- [Getting Started](https://docs.silverstripe.org/en/5/getting_started/)
validations:
required: true
- type: textarea
id: description
attributes:
label: Description
description: A clear and concise description of the problem you've found in the documentation
validations:
required: true
- type: checkboxes
id: validations
attributes:
label: Validations
description: "Before submitting the issue, please make sure you do the following:"
options:
- label: Check that there isn't already an issue that reports the same problem
required: true
EOT;

$files = [
'.github/PULL_REQUEST_TEMPLATE.md' => $pullRequestTemplate,
'.github/ISSUE_TEMPLATE.md' => $defaultIssueTemplate,
'.github/ISSUE_TEMPLATE/config.yml' => $config,
'.github/ISSUE_TEMPLATE/1_docs_issue.yml' => $documentationIssueTemplate,
];

// See issue-pr-templates.php for the non-docs equivalent
if (!is_docs()) {
return;
}

foreach ($files as $path => $contents) {
write_file_even_if_exists($path, $contents);
}
Loading

0 comments on commit 28ebe37

Please sign in to comment.