From ac0274cfba1c61120eee33061dc11254d5562a0c Mon Sep 17 00:00:00 2001
From: Pierre Delpy
Date: Tue, 15 Oct 2024 09:38:24 +0200
Subject: [PATCH] feat: add exceptions and boilerplate
---
.github/scripts/rename_inactive_branches.py | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/.github/scripts/rename_inactive_branches.py b/.github/scripts/rename_inactive_branches.py
index e62fe835..b9bd3597 100644
--- a/.github/scripts/rename_inactive_branches.py
+++ b/.github/scripts/rename_inactive_branches.py
@@ -13,12 +13,14 @@
# Fetch all branches
def get_branches():
response = requests.get(API_URL, headers=HEADERS)
+ response.raise_for_status()
return response.json() if response.status_code == 200 else []
# Rename inactive branches
def rename_branch(old_name, new_name):
rename_url = f'https://api.github.com/repos/{REPO}/branches/{old_name}/rename'
response = requests.post(rename_url, json={'new_name': new_name}, headers=HEADERS)
+ response.raise_for_status()
print(f"Renamed branch {old_name} to {new_name}" if response.status_code == 201 else f"Failed to rename {old_name}: {response.status_code}")
# Check if the branch is inactive
@@ -27,7 +29,11 @@ def is_inactive(commit_url):
return datetime.strptime(last_commit_date, '%Y-%m-%dT%H:%M:%SZ') < CUTOFF_DATE
# Rename inactive branches
-for branch in get_branches():
- if is_inactive(branch['commit']['url']):
- #rename_branch(branch['name'], f"archived/{branch['name']}")
- print(f"[LOG] Branch '{branch['name']}' is inactive and would be renamed to 'archived/{branch['name']}'")
\ No newline at end of file
+def main():
+ for branch in get_branches():
+ if is_inactive(branch['commit']['url']):
+ #rename_branch(branch['name'], f"archived/{branch['name']}")
+ print(f"[LOG] Branch '{branch['name']}' is inactive and would be renamed to 'archived/{branch['name']}'")
+
+if __name__ == "__main__":
+ main()
\ No newline at end of file