t: modularize test branch configurations in conftest.py #133
@@ -10,83 +10,48 @@ import json
|
||||
import base64
|
||||
from tests.lib.common_test_utils import GiteaAPIClient
|
||||
|
||||
BRANCH_CONFIGS = {
|
||||
BRANCH_CONFIG_COMMON = {
|
||||
"workflow.config": {
|
||||
"Workflows": ["pr"],
|
||||
"Organization": "pool",
|
||||
"Reviewers": ["-autogits_obs_staging_bot"],
|
||||
"GitProjectName": "products/SLFO#{branch}"
|
||||
},
|
||||
"_maintainership.json": {
|
||||
"": ["ownerX", "ownerY"],
|
||||
"pkgA": ["ownerA"],
|
||||
"pkgB": ["ownerB", "ownerBB"]
|
||||
}
|
||||
}
|
||||
|
||||
BRANCH_CONFIG_CUSTOM = {
|
||||
"main": {
|
||||
"workflow.config": {
|
||||
"Workflows": ["pr"],
|
||||
"GitProjectName": "products/SLFO#main",
|
||||
"Organization": "pool",
|
||||
"Branch": "main",
|
||||
"ManualMergeProject": True,
|
||||
"Reviewers": ["-autogits_obs_staging_bot"]
|
||||
"ManualMergeProject": True
|
||||
},
|
||||
"staging.config": {
|
||||
"ObsProject": "openSUSE:Leap:16.0",
|
||||
"StagingProject": "openSUSE:Leap:16.0:PullRequest"
|
||||
},
|
||||
"_maintainership.json": {
|
||||
"": ["ownerX", "ownerY"],
|
||||
"pkgA": ["ownerA"],
|
||||
"pkgB": ["ownerB", "ownerBB"]
|
||||
}
|
||||
},
|
||||
"merge": {
|
||||
"workflow.config": {
|
||||
"Workflows": ["pr"],
|
||||
"GitProjectName": "products/SLFO#merge",
|
||||
"Organization": "pool",
|
||||
"Branch": "merge",
|
||||
"Reviewers": ["+usera", "+userb", "-autogits_obs_staging_bot"]
|
||||
},
|
||||
"_maintainership.json": {
|
||||
"": ["ownerX", "ownerY"],
|
||||
"pkgA": ["ownerA"],
|
||||
"pkgB": ["ownerB", "ownerBB"]
|
||||
}
|
||||
},
|
||||
"maintainer-merge": {
|
||||
"workflow.config": {
|
||||
"Workflows": ["pr"],
|
||||
"GitProjectName": "products/SLFO#maintainer-merge",
|
||||
"Organization": "pool",
|
||||
"Branch": "maintainer-merge",
|
||||
"Reviewers": ["-autogits_obs_staging_bot"]
|
||||
},
|
||||
"_maintainership.json": {
|
||||
"": ["ownerX", "ownerY"],
|
||||
"pkgA": ["ownerA"],
|
||||
"pkgB": ["ownerB", "ownerBB"]
|
||||
}
|
||||
},
|
||||
"review-required": {
|
||||
"workflow.config": {
|
||||
"Workflows": ["pr"],
|
||||
"GitProjectName": "products/SLFO#review-required",
|
||||
"Organization": "pool",
|
||||
"Branch": "review-required",
|
||||
"Reviewers": ["-autogits_obs_staging_bot"],
|
||||
"ReviewRequired": True
|
||||
},
|
||||
"_maintainership.json": {
|
||||
"": ["ownerX", "ownerY"],
|
||||
"pkgA": ["ownerA"],
|
||||
"pkgB": ["ownerB", "ownerBB"]
|
||||
}
|
||||
},
|
||||
"dev": {
|
||||
"workflow.config": {
|
||||
"Workflows": ["pr"],
|
||||
"GitProjectName": "products/SLFO#dev",
|
||||
"Organization": "pool",
|
||||
"Branch": "dev",
|
||||
"ManualMergeProject": True,
|
||||
"Reviewers": ["-autogits_obs_staging_bot"],
|
||||
"NoProjectGitPR": True
|
||||
},
|
||||
"_maintainership.json": {
|
||||
"": ["ownerX", "ownerY"],
|
||||
"pkgA": ["ownerA"],
|
||||
"pkgB": ["ownerB", "ownerBB"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,7 +158,7 @@ def gitea_env():
|
||||
restart_needed = False
|
||||
|
||||
# Setup all branches and configs
|
||||
for branch_name, configs in BRANCH_CONFIGS.items():
|
||||
for branch_name, custom_configs in BRANCH_CONFIG_CUSTOM.items():
|
||||
# Ensure branch exists in all 3 repos
|
||||
for owner, repo in [("products", "SLFO"), ("pool", "pkgA"), ("pool", "pkgB")]:
|
||||
if branch_name != "main":
|
||||
@@ -204,13 +169,30 @@ def gitea_env():
|
||||
if "already exists" not in str(e).lower():
|
||||
raise
|
||||
|
||||
# Merge configs
|
||||
merged_configs = {}
|
||||
for file_name, common_content in BRANCH_CONFIG_COMMON.items():
|
||||
merged_configs[file_name] = common_content.copy()
|
||||
# Dynamically format values containing {branch}
|
||||
if file_name == "workflow.config":
|
||||
if "GitProjectName" in merged_configs[file_name]:
|
||||
merged_configs[file_name]["GitProjectName"] = merged_configs[file_name]["GitProjectName"].format(branch=branch_name)
|
||||
# Inject branch name dynamically
|
||||
merged_configs[file_name]["Branch"] = branch_name
|
||||
|
||||
for file_name, custom_content in custom_configs.items():
|
||||
if file_name in merged_configs:
|
||||
merged_configs[file_name].update(custom_content)
|
||||
else:
|
||||
merged_configs[file_name] = custom_content
|
||||
|
||||
# Ensure config files in products/SLFO
|
||||
for file_name, content_dict in configs.items():
|
||||
for file_name, content_dict in merged_configs.items():
|
||||
if ensure_config_file(client, "products", "SLFO", branch_name, file_name, content_dict):
|
||||
restart_needed = True
|
||||
|
||||
# Setup users (using configs from this branch)
|
||||
setup_users_from_config(client, configs.get("workflow.config", {}), configs.get("_maintainership.json", {}))
|
||||
setup_users_from_config(client, merged_configs.get("workflow.config", {}), merged_configs.get("_maintainership.json", {}))
|
||||
|
||||
if restart_needed:
|
||||
client.restart_service("workflow-pr")
|
||||
|
||||
Reference in New Issue
Block a user