From e90ae5971a4f8152c855023ddaf21e765a533c89 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 22 May 2024 12:14:44 +1200 Subject: [PATCH] NEW Update rulesets --- rulesets/branch-ruleset.json | 46 +++++++++++++++++++++++ rulesets/tag-ruleset.json | 34 +++++++++++++++++ rulesets_command.php | 72 ++++++++++++++++++++++++++++++++++++ run.php | 10 +++++ 4 files changed, 162 insertions(+) create mode 100644 rulesets/branch-ruleset.json create mode 100644 rulesets/tag-ruleset.json create mode 100644 rulesets_command.php diff --git a/rulesets/branch-ruleset.json b/rulesets/branch-ruleset.json new file mode 100644 index 0000000..472759e --- /dev/null +++ b/rulesets/branch-ruleset.json @@ -0,0 +1,46 @@ +{ + "name": "Silverstripe branch ruleset", + "target": "branch", + "enforcement": "active", + "conditions": { + "ref_name": { + "exclude": [], + "include": [ + "refs/heads/main", + "refs/heads/master", + "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" + } + ] +} diff --git a/rulesets/tag-ruleset.json b/rulesets/tag-ruleset.json new file mode 100644 index 0000000..8f8add6 --- /dev/null +++ b/rulesets/tag-ruleset.json @@ -0,0 +1,34 @@ +{ + "name": "Silverstripe tag ruleset", + "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" + } + ] +} diff --git a/rulesets_command.php b/rulesets_command.php new file mode 100644 index 0000000..ea63526 --- /dev/null +++ b/rulesets_command.php @@ -0,0 +1,72 @@ + 'emteknetnz', 'repo' => 'test-thing'], + // ['account' => 'emteknetnz', 'repo' => 'tmp-docblock-annotator'], + ]; + + // 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"); + + print_r($rulesets);die; + + foreach ($rulesets as $key => $label) { + // $label is an array, for example: + // 'id' => 427423377 + // 'node_id' => MDU6TGFiZWw0Mjc0MjMzNzc=" + // 'url' => "https://api.github.com/repos/silverstripe/silverstripe-config/labels/affects/v4" + // 'name' => "affects/v4" + // 'color' => "5319e7" + // 'default' => false + // 'description' => NULL + $url = $label['url']; + $name = $label['name']; // e.g. 'affects/v4' + } + output_repos_with_labels_updated(); + return Command::SUCCESS; +}; diff --git a/run.php b/run.php index 643909d..0fb3748 100644 --- a/run.php +++ b/run.php @@ -5,6 +5,7 @@ include 'funcs_utils.php'; include 'update_command.php'; include 'labels_command.php'; +include 'rulesets_command.php'; use SilverStripe\SupportedModules\MetaData; use Symfony\Component\Console\Application; @@ -26,6 +27,7 @@ $PRS_CREATED = []; $REPOS_WITH_PRS_CREATED = []; $REPOS_WITH_LABELS_UPDATED = []; +$REPOS_WITH_RULESETS_UPDATED = []; $OUT = null; // options @@ -102,6 +104,14 @@ ->addOption(...$optionNoDelete) ->setCode($labelsCommand); +$app->register('rulesets') + ->setDescription('Script to set rulesets on all repos only on the silverstripe account') + ->addOption(...$optionOnly) + ->addOption(...$optionExclude) + ->addOption(...$optionDryRun) + ->addOption(...$optionNoDelete) + ->setCode($labelsCommand); + try { $app->run(); } catch (Error|Exception $e) {