Skip to content

Commit

Permalink
ENH Add markdown-php-codesniffer repo
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 13, 2023
1 parent a279039 commit ee1a38e
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions funcs_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Output an error to the console and halt progress
*
*
* error() is not intended for use in scripts specificially because it will halt progress
* Instead scripts should be more tolerant though use of functions like check_file_exists() or just
* using warning() instead which output a big warning in the console while still continuing
Expand Down Expand Up @@ -79,12 +79,15 @@ function supported_modules($cmsMajor)

/**
* Hardcoded list of non-supported, additional repositories to standardise (e.g. silverstripe/gha-*)
*
*
* Repositories in this list should only have a single supported major version
* This will only be included if the $cmsMajor is the CURRENT_CMS_MAJOR
*/
function extra_repositories()
{
$importantRepos = [
'silverstripe/markdown-php-codesniffer',
];
$modules = [];
// iterating to page 10 will be enough to get all the repos well into the future
for ($i = 0; $i < 10; $i++) {
Expand All @@ -104,8 +107,8 @@ function extra_repositories()
continue;
}
$ghrepo = $repo['full_name'];
// exclude non gha-* repos
if (strpos($ghrepo, '/gha-') === false) {
// Only include repos we care about
if (!in_array($ghrepo, $importantRepos) && strpos($ghrepo, '/gha-') === false) {
continue;
}
$modules[] = [
Expand Down Expand Up @@ -290,7 +293,7 @@ function output_repos_with_prs_created()

/**
* Works out which branch in a module to checkout before running scripts on it
*
*
* 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)
Expand All @@ -316,7 +319,7 @@ function branch_to_checkout($branches, $currentBranch, $currentBranchCmsMajor, $

/**
* Uses composer.json to workout the current branch cms major version
*
*
* If composer.json does not exist then it's assumed to be CURRENT_CMS_MAJOR
*/
function current_branch_cms_major(
Expand All @@ -325,6 +328,17 @@ function current_branch_cms_major(
) {
global $MODULE_DIR;

// Some repositories don't have a valid matching CMS major
$ignoreCMSMajor = [
'/silverstripe-simple',
'/markdown-php-codesniffer',
];
foreach ($ignoreCMSMajor as $ignore) {
if (strpos($MODULE_DIR, $ignore) !== false) {
return CURRENT_CMS_MAJOR;
}
}

if ($composerJson) {
$contents = $composerJson;
} elseif (check_file_exists('composer.json')) {
Expand All @@ -337,16 +351,11 @@ function current_branch_cms_major(
if (strpos($MODULE_DIR, '/developer-docs') !== false) {
$currentBranch = cmd('git rev-parse --abbrev-ref HEAD', $MODULE_DIR);
if (!preg_match('#^(pulls/)?([0-9]+)(\.[0-9]+)?(/|$)#', $currentBranch, $matches)) {
error("Could work out current major for developer-docs from branch $currentBranch");
error("Could not work out current major for developer-docs from branch $currentBranch");
}
return $matches[2];
}

// special logic for silverstripe-themes/silverstripe-simple
if (strpos($MODULE_DIR, '/silverstripe-simple') !== false) {
return CURRENT_CMS_MAJOR;
}

$json = json_decode($contents);
if (is_null($json)) {
$lastError = json_last_error();
Expand Down Expand Up @@ -390,4 +399,4 @@ function current_branch_cms_major(
error('Could not work out what the current CMS major version is');
}
return (string) $cmsMajor;
}
}

0 comments on commit ee1a38e

Please sign in to comment.