Skip to content

Instantly share code, notes, and snippets.

@lmazuel
Created September 2, 2022 18:23
Show Gist options
  • Save lmazuel/d6417ee99013223f089bac28a40b08b4 to your computer and use it in GitHub Desktop.
Save lmazuel/d6417ee99013223f089bac28a40b08b4 to your computer and use it in GitHub Desktop.
Push labels on Github
import sys
from github import Github, GithubException
REPOS = [
"Azure/azure-sdk-for-python",
"Azure/azure-sdk-for-net",
"Azure/azure-sdk-for-js",
"Azure/azure-sdk-for-java",
"Azure/autorest.python",
"Azure/autorest.csharp",
"Azure/autorest.typescript",
"Azure/autorest.java",
"Azure/autorest",
"Azure/cadl-azure",
"Azure/cadl-ranch",
]
COLOR = "6633ff"
LABELS = {
"Epic: Coordinate Client Customizations": "https://github.com/Azure/cadl-azure/issues/1953",
"Epic: Recreate API Contracts and SDKs": "https://github.com/Azure/cadl-azure/issues/1948",
"Epic: Packaging": "https://github.com/Azure/cadl-azure/issues/1947",
"Epic: Generate tests and samples": "https://github.com/Azure/cadl-azure/issues/1946",
"Epic: Version resiliency and multiapi": "https://github.com/Azure/cadl-azure/issues/1945",
"Epic: Model Generation": "https://github.com/Azure/cadl-azure/issues/1944",
"Epic: Convenience methods with models": "https://github.com/Azure/cadl-azure/issues/1943",
"Epic: Parity with DPG 1.0": "https://github.com/Azure/cadl-azure/issues/1942",
"Epic: Test scenarios definition": "https://github.com/Azure/cadl-azure/issues/1941",
"Epic: Create test infrastructure": "https://github.com/Azure/cadl-azure/issues/1939",
"WS: Code Generation": None
}
def main(gh_token):
github_con = Github(gh_token)
for repo in REPOS:
gh_repo = github_con.get_repo(repo)
try:
for label, description in LABELS.items():
try:
if description:
gh_repo.create_label(label, COLOR, description)
else:
gh_repo.create_label(label, COLOR)
except GithubException as err:
err_message = err.data["errors"][0].get("code", None)
if err.status == 422 and err_message == "already_exists":
print(f"Label {label} already exists in {repo}, skipping.")
continue
raise
except Exception:
print(f"Seems I don't have permissions for {repo}")
raise
else:
print(f"Done with {repo}")
if __name__ == "__main__":
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment