MCPcopy Index your code
hub / github.com/saltstack/salt / sync_os_labels

Function sync_os_labels

tools/gh.py:37–171  ·  view source on GitHub ↗

Synchronize the GitHub labels to the OS known to be tested.

(
    ctx: Context, repository: str = "saltstack/salt", color: str = "C2E0C6"
)

Source from the content-addressed store, hash-verified

35 },
36)
37def 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,

Callers

nothing calls this directly

Calls 12

exitMethod · 0.80
setFunction · 0.50
infoMethod · 0.45
errorMethod · 0.45
addMethod · 0.45
updateMethod · 0.45
getMethod · 0.45
popMethod · 0.45
itemsMethod · 0.45
appendMethod · 0.45
deleteMethod · 0.45
postMethod · 0.45

Tested by

no test coverage detected