Spaces:
Sleeping
Sleeping
| import random | |
| from typing import Any, Dict, List | |
| _LABEL_VARIANTS = { | |
| "bug": ["bug", "defect", "issue", "fault"], | |
| "feature": ["feature", "enhancement", "request", "improvement"], | |
| "docs": ["docs", "documentation", "doc-update", "guide"], | |
| "security": ["security", "vuln", "vulnerability", "sec-issue"], | |
| "performance": ["perf", "performance", "slowness", "optimization"], | |
| } | |
| _PRIORITY_SCHEMES = [ | |
| ["P0", "P1", "P2", "P3"], | |
| ["critical", "high", "medium", "low"], | |
| ["urgent", "high", "normal", "low"], | |
| ["blocker", "major", "minor", "trivial"], | |
| ] | |
| _SERVICES = ["payments", "auth", "search", "notifications", "api-gateway", "checkout", "inventory"] | |
| _TEAM_POOL = ["platform", "growth", "infra", "security", "backend", "frontend", "data"] | |
| _CHANNEL_SUFFIXES = ["-alerts", "-oncall", "-ops", "-team", "-eng"] | |
| _NOISE_CHANNELS = ["#random", "#general", "#water-cooler", "#announcements", "#off-topic", "#hiring"] | |
| _ESCALATION_POLICIES = ["dm-manager", "page-oncall", "post-channel"] | |
| _RELEASE_STYLES = ["terse", "verbose", "bulleted"] | |
| def generate_org_config(seed: int, difficulty: str = "medium") -> Dict[str, Any]: | |
| rng = random.Random(seed) | |
| n_labels = {"easy": 3, "medium": 4, "hard": 5}.get(difficulty, 4) | |
| label_keys = rng.sample(list(_LABEL_VARIANTS.keys()), n_labels) | |
| label_taxonomy = {k: rng.choice(_LABEL_VARIANTS[k]) for k in label_keys} | |
| priority_levels: List[str] = rng.choice(_PRIORITY_SCHEMES) | |
| severity_to_priority = { | |
| "critical": priority_levels[0], | |
| "high": priority_levels[1] if len(priority_levels) > 1 else priority_levels[0], | |
| "medium": priority_levels[2] if len(priority_levels) > 2 else priority_levels[-1], | |
| "low": priority_levels[-1], | |
| } | |
| n_services = {"easy": 2, "medium": 3, "hard": 5}.get(difficulty, 3) | |
| services = rng.sample(_SERVICES, min(n_services, len(_SERVICES))) | |
| teams = rng.sample(_TEAM_POOL, min(len(services), len(_TEAM_POOL))) | |
| team_map: Dict[str, str] = {svc: teams[i % len(teams)] for i, svc in enumerate(services)} | |
| oncall_channels: Dict[str, str] = {} | |
| for svc in services: | |
| team = team_map[svc] | |
| suffix = rng.choice(_CHANNEL_SUFFIXES) | |
| oncall_channels[svc] = f"#{team}{suffix}" | |
| escalation_policy: str = rng.choice(_ESCALATION_POLICIES) | |
| release_notes_style: str = rng.choice(_RELEASE_STYLES) | |
| all_fields = ["summary", "description", "priority", "label", "assignee"] | |
| n_required = {"easy": 2, "medium": 3, "hard": 4}.get(difficulty, 3) | |
| required_ticket_fields = ["summary"] + rng.sample(all_fields[1:], min(n_required - 1, len(all_fields) - 1)) | |
| n_noise = {"easy": 1, "medium": 2, "hard": 3}.get(difficulty, 2) | |
| noise_channels = rng.sample(_NOISE_CHANNELS, min(n_noise, len(_NOISE_CHANNELS))) | |
| return { | |
| "label_taxonomy": label_taxonomy, | |
| "priority_levels": priority_levels, | |
| "severity_to_priority": severity_to_priority, | |
| "team_map": team_map, | |
| "oncall_channels": oncall_channels, | |
| "escalation_policy": escalation_policy, | |
| "release_notes_style": release_notes_style, | |
| "required_ticket_fields": required_ticket_fields, | |
| "noise_channels": noise_channels, | |
| "services": services, | |
| "teams": teams, | |
| } | |