-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Detect duplicate labels in label-sync validation #79376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-bot
merged 2 commits into
openshift:main
from
petr-muller:pm2602-label-sync-dup-check
May 18, 2026
+26
−8
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,45 +1,63 @@ | ||
| #!/usr/bin/env python3 | ||
| """Validate GitHub label descriptions don't exceed 100 characters.""" | ||
| """Validate GitHub label configuration.""" | ||
|
|
||
| import sys | ||
| import yaml | ||
|
|
||
| MAX_LENGTH = 100 | ||
| LABELS_FILE = "core-services/prow/02_config/_labels.yaml" | ||
|
|
||
| def label_names(labels): | ||
| return {label["name"] for label in labels} | ||
|
|
||
| def main(): | ||
| with open(LABELS_FILE, encoding="utf-8") as f: | ||
| data = yaml.safe_load(f) | ||
|
|
||
| errors = [] | ||
|
|
||
| default_labels = data.get("default", {}).get("labels", []) | ||
| default_names = label_names(default_labels) | ||
|
|
||
| # Check default labels | ||
| for label in data.get("default", {}).get("labels", []): | ||
| for label in default_labels: | ||
| desc = label.get("description", "") | ||
| if len(desc) > MAX_LENGTH: | ||
| errors.append(f"default/{label['name']}: {len(desc)} chars - {desc}") | ||
| errors.append(f"default/{label['name']}: description is {len(desc)} chars (max {MAX_LENGTH})") | ||
|
|
||
| # Check org-level labels | ||
| for org, config in data.get("orgs", {}).items(): | ||
| for label in config.get("labels", []): | ||
| org_labels = config.get("labels", []) | ||
| for label in org_labels: | ||
| name = label["name"] | ||
| desc = label.get("description", "") | ||
| if len(desc) > MAX_LENGTH: | ||
| errors.append(f"orgs/{org}/{label['name']}: {len(desc)} chars - {desc}") | ||
| errors.append(f"orgs/{org}/{name}: description is {len(desc)} chars (max {MAX_LENGTH})") | ||
| if name in default_names: | ||
| errors.append(f"orgs/{org}/{name}: duplicates default label") | ||
|
|
||
| # Check repo-specific labels | ||
| for repo, config in data.get("repos", {}).items(): | ||
| org = repo.split("/")[0] if "/" in repo else None | ||
| org_names = label_names(data.get("orgs", {}).get(org, {}).get("labels", [])) if org else set() | ||
|
|
||
| for label in config.get("labels", []): | ||
| name = label["name"] | ||
| desc = label.get("description", "") | ||
| if len(desc) > MAX_LENGTH: | ||
| errors.append(f"repos/{repo}/{label['name']}: {len(desc)} chars - {desc}") | ||
| errors.append(f"repos/{repo}/{name}: description is {len(desc)} chars (max {MAX_LENGTH})") | ||
| if name in default_names: | ||
| errors.append(f"repos/{repo}/{name}: duplicates default label") | ||
| if name in org_names: | ||
| errors.append(f"repos/{repo}/{name}: duplicates org-level label from {org}") | ||
|
|
||
| if errors: | ||
| print(f"Labels with descriptions exceeding {MAX_LENGTH} characters:") | ||
| print(f"Label validation errors:") | ||
| for err in errors: | ||
| print(f" {err}") | ||
| sys.exit(1) | ||
|
|
||
| print("All label descriptions are within limits.") | ||
| print("All labels are valid.") | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.