Skip to content

Commit

Permalink
added script for updating labels
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Sep 12, 2024
1 parent 7bfc8e4 commit 2404e3c
Show file tree
Hide file tree
Showing 3 changed files with 551 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,5 @@ dmypy.json

# Cython debug symbols
cython_debug/

.vscode
43 changes: 43 additions & 0 deletions label-update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import json
import sys
import requests

# Constants
REPO_OWNER = "brainhackorg"
REPO_NAME = "global2024"
API_URL = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/labels"
TOKEN = sys.argv[1]
HEADERS = {
"Authorization": f"token {TOKEN}",
"Accept": "application/vnd.github.v3+json",
}

# Read labels from JSON file
with open("labels.json", "r") as file:
labels = json.load(file)


# Function to create or update a label
def create_or_update_label(label):
response = requests.post(API_URL, headers=HEADERS, json=label)
if response.status_code == 201:
print(f"Created label: {label['name']}")
elif response.status_code == 422:
# Label already exists, update it
update_url = f"{API_URL}/{label['name']}"
response = requests.patch(update_url, headers=HEADERS, json=label)
if response.status_code == 200:
print(f"Updated label: {label['name']}")
else:
print(
f"Failed to update label: {label['name']}, {response.status_code}, {response.text}"
)
else:
print(
f"Failed to create label: {label['name']}, {response.status_code}, {response.text}"
)


# Upload labels to the repository
for label in labels:
create_or_update_label(label)
Loading

0 comments on commit 2404e3c

Please sign in to comment.