-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8961f2
commit ceac308
Showing
6 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"name": "<RULESET_NAME>", | ||
"target": "branch", | ||
"enforcement": "active", | ||
"conditions": { | ||
"ref_name": { | ||
"exclude": [], | ||
"include": [ | ||
"refs/heads/[0-9]*" | ||
] | ||
} | ||
}, | ||
"rules": [ | ||
{ | ||
"type": "deletion" | ||
}, | ||
{ | ||
"type": "non_fast_forward" | ||
}, | ||
{ | ||
"type": "creation" | ||
}, | ||
{ | ||
"type": "update" | ||
}, | ||
{ | ||
"type": "pull_request", | ||
"parameters": { | ||
"required_approving_review_count": 2, | ||
"dismiss_stale_reviews_on_push": true, | ||
"require_code_owner_review": false, | ||
"require_last_push_approval": true, | ||
"required_review_thread_resolution": false | ||
} | ||
} | ||
], | ||
"bypass_actors": [ | ||
{ | ||
"actor_id": 5, | ||
"actor_type": "RepositoryRole", | ||
"bypass_mode": "always" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "<RULESET_NAME>", | ||
"target": "tag", | ||
"enforcement": "active", | ||
"conditions": { | ||
"ref_name": { | ||
"exclude": [], | ||
"include": [ | ||
"~ALL" | ||
] | ||
} | ||
}, | ||
"rules": [ | ||
{ | ||
"type": "deletion" | ||
}, | ||
{ | ||
"type": "non_fast_forward" | ||
}, | ||
{ | ||
"type": "creation" | ||
}, | ||
{ | ||
"type": "update" | ||
} | ||
], | ||
"bypass_actors": [ | ||
{ | ||
"actor_id": 5, | ||
"actor_type": "RepositoryRole", | ||
"bypass_mode": "always" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
use SilverStripe\SupportedModules\MetaData; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
|
||
$rulesetsCommand = function(InputInterface $input, OutputInterface $output): int { | ||
// This is the code that is executed when running the 'rulesets' command | ||
|
||
// variables | ||
global $OUT, $REPOS_WITH_RULESETS_UPDATED; | ||
$OUT = $output; | ||
|
||
// validate system is ready | ||
validate_system(); | ||
|
||
// setup directories | ||
setup_directories($input, [DATA_DIR]); | ||
|
||
// modules | ||
$modules = []; | ||
$repos = []; | ||
$modulesCurrentMajor = filtered_modules(MetaData::HIGHEST_STABLE_CMS_MAJOR, $input); | ||
$modulesPreviousMajor = filtered_modules(MetaData::HIGHEST_STABLE_CMS_MAJOR - 1, $input); | ||
foreach ([$modulesCurrentMajor, $modulesPreviousMajor] as $modulesList) { | ||
foreach ($modulesList as $module) { | ||
$repo = $module['repo']; | ||
$ghrepo = $module['ghrepo']; | ||
if (in_array($repo, $repos) || in_array($ghrepo, LABELS_EXCLUDE_GHREPOS)) { | ||
continue; | ||
} | ||
// Important! Only include modules on the "silverstripe" account | ||
if (!preg_match('#^silverstripe/#', $repo)) { | ||
continue; | ||
} | ||
$modules[] = $module; | ||
$repos[] = $repo; | ||
} | ||
} | ||
|
||
// sboyd | ||
$modules = [ | ||
// ['account' => 'emteknetnz', 'repo' => 'test-thing'], | ||
['account' => 'emteknetnz', 'repo' => 'tmp-docblock-annotator'], | ||
]; | ||
|
||
$branchRuleset = file_get_contents('rulesets/branch-ruleset.json'); | ||
$tagRuleset = file_get_contents('rulesets/tag-ruleset.json'); | ||
|
||
// update rulesets | ||
foreach ($modules as $module) { | ||
$account = $module['account']; | ||
$repo = $module['repo']; | ||
|
||
// Fetch existing rulesets | ||
$rulesets = github_api("https://api.github.com/repos/$account/$repo/rulesets"); | ||
$branchRulesetID = 0; | ||
$tagRulesetID = 0; | ||
foreach ($rulesets as $ruleset) { | ||
$id = $ruleset['id']; | ||
$name = $ruleset['name']; | ||
if ($name === BRANCH_RULESET_NAME) { | ||
$branchRulesetID = $id; | ||
} | ||
if ($name === TAG_RULESET_NAME) { | ||
$tagRulesetID = $id; | ||
} | ||
} | ||
|
||
// Get any additional branches to add | ||
// Assumption is that if the current (default) branch is main/master, then the repo uses | ||
// a non-numeric style branching system (e.g. main, master) and that needs to be protected | ||
// [0-9]* branch protection will still be applied, on the chance that the repo is converted | ||
// to uses a numeric style branch system in the future and we would want branch protection | ||
// to start immediately on the new branches | ||
$additionalConditionsInclude = []; | ||
$currentBranch = current_branch_name(); | ||
if (in_array($currentBranch, ['main', 'master'])) { | ||
$additionalConditionsInclude[] = "refs/heads/$currentBranch"; | ||
} | ||
|
||
// Create rulesets | ||
$branchRuleset = create_ruleset('branch', $additionalConditionsInclude); | ||
$tagRuleset = create_ruleset('tag'); | ||
|
||
// Create new rule set | ||
if (!$branchRulesetID) { | ||
$url = "https://api.github.com/repos/$account/$repo/rulesets"; | ||
github_api($url, 'POST', $branchRuleset); | ||
} | ||
if (!$tagRulesetID) { | ||
$url = "https://api.github.com/repos/$account/$repo/rulesets"; | ||
github_api($url, 'POST', $tagRuleset); | ||
} | ||
|
||
// Update existing ruleset - don't bother to check if the ruleset is the same | ||
// this is a fairly quick update so no need to optimise this | ||
if ($branchRulesetID) { | ||
$url = "https://api.github.com/repos/$account/$repo/rulesets/$branchRulesetID"; | ||
github_api($url, 'PUT', $branchRuleset); | ||
} | ||
if ($tagRulesetID) { | ||
$url = "https://api.github.com/repos/$account/$repo/rulesets/$tagRulesetID"; | ||
github_api($url, 'PUT', $tagRuleset); | ||
} | ||
$REPOS_WITH_RULESETS_UPDATED[] = $repo; | ||
} | ||
output_repos_with_rulesets_created_or_updated(); | ||
return Command::SUCCESS; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters