Skip to content

Instantly share code, notes, and snippets.

@nottrobin
Created August 2, 2022 10:38
Show Gist options
  • Save nottrobin/e956ad3e0287275e74b8ec579f0354d5 to your computer and use it in GitHub Desktop.
Save nottrobin/e956ad3e0287275e74b8ec579f0354d5 to your computer and use it in GitHub Desktop.
Add "web-and-design" topic to all our team's repos
import requests
import json
from github import Github
token = "REPLACE_ME"
g = Github(token)
org = g.get_organization("canonical")
teams = org.get_teams()
team = [team for team in teams if team.slug == "web-and-design"][0]
repos = team.get_repos()
for repo in repos:
topics = repo.get_topics()
if "web-and-design" not in topics:
topics.append("web-and-design")
response = requests.put(
f"https://api.github.com/repos/canonical/{repo.name}/topics",
headers={
"Accept": "application/vnd.github+json",
"Authorization": f"token {token}",
},
data=json.dumps({"names": topics}),
)
print(f"{response.status_code}: {repo.name}: {response.text}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment