Skip to content

Commit

Permalink
NEW Update rulesets
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed May 22, 2024
1 parent b8961f2 commit e90ae59
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 0 deletions.
46 changes: 46 additions & 0 deletions rulesets/branch-ruleset.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
34 changes: 34 additions & 0 deletions rulesets/tag-ruleset.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
72 changes: 72 additions & 0 deletions rulesets_command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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'],
];

// 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;
};
10 changes: 10 additions & 0 deletions run.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@
$PRS_CREATED = [];
$REPOS_WITH_PRS_CREATED = [];
$REPOS_WITH_LABELS_UPDATED = [];
$REPOS_WITH_RULESETS_UPDATED = [];
$OUT = null;

// options
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e90ae59

Please sign in to comment.