Synchronize the GitHub labels to the OS known to be tested.
(
ctx: Context, repository: str = "saltstack/salt", color: str = "C2E0C6"
)
| 35 | }, |
| 36 | ) |
| 37 | def sync_os_labels( |
| 38 | ctx: Context, repository: str = "saltstack/salt", color: str = "C2E0C6" |
| 39 | ): |
| 40 | """ |
| 41 | Synchronize the GitHub labels to the OS known to be tested. |
| 42 | """ |
| 43 | description_prefix = "Run Tests Against" |
| 44 | known_os = { |
| 45 | "test:os:all": { |
| 46 | "name": "test:os:all", |
| 47 | "color": color, |
| 48 | "description": f"{description_prefix} ALL OS'es", |
| 49 | }, |
| 50 | } |
| 51 | for slug in tools.precommit.workflows.slugs(): |
| 52 | name = f"test:os:{slug}" |
| 53 | known_os[name] = { |
| 54 | "name": name, |
| 55 | "color": color, |
| 56 | "description": f"{description_prefix} {slug}", |
| 57 | } |
| 58 | |
| 59 | ctx.info(known_os) |
| 60 | |
| 61 | github_token = tools.utils.gh.get_github_token(ctx) |
| 62 | if github_token is None: |
| 63 | ctx.error("Querying labels requires being authenticated to GitHub.") |
| 64 | ctx.info( |
| 65 | "Either set 'GITHUB_TOKEN' to a valid token, or configure the 'gh' tool such that " |
| 66 | "'gh auth token' returns a token." |
| 67 | ) |
| 68 | ctx.exit(1) |
| 69 | |
| 70 | existing_labels = set() |
| 71 | labels_to_update = [] |
| 72 | labels_to_delete = set() |
| 73 | shared_context = tools.utils.get_cicd_shared_context() |
| 74 | for slug in shared_context["mandatory_os_slugs"]: |
| 75 | label = f"test:os:{slug}" |
| 76 | labels_to_delete.add(label) |
| 77 | |
| 78 | headers = { |
| 79 | "Accept": "application/vnd.github+json", |
| 80 | "Authorization": f"Bearer {github_token}", |
| 81 | "X-GitHub-Api-Version": "2022-11-28", |
| 82 | } |
| 83 | with ctx.web as web: |
| 84 | web.headers.update(headers) |
| 85 | page = 0 |
| 86 | while True: |
| 87 | page += 1 |
| 88 | params = { |
| 89 | "per_page": 100, |
| 90 | "page": page, |
| 91 | } |
| 92 | ret = web.get( |
| 93 | f"https://api.github.com/repos/{repository}/labels", |
| 94 | params=params, |