Skip to content

Commit 80a85fe

Browse files
authored
feat: try archiving when repo deletion fails (#398)
1 parent 3d5ae48 commit 80a85fe

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- update qs to 6.14.1 via npm override to address security vulnerability
1919
- pin @cdklabs/generative-ai-cdk-constructs to 0.1.311 to fix build compatibility
2020
- update starlette to 0.50.0 and fastapi to 0.128.0 to address security vulnerabilities
21+
- updated `sagemaker-templates` to try archiving when repo deletion fails
2122

2223

2324
## v3.1.0

modules/sagemaker/sagemaker-templates/common/code_repo_construct.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,38 @@ def lambda_handler(event, context):
252252
if response_code == 204:
253253
print(f"Repository {repo_name} deleted successfully")
254254
except urllib.error.HTTPError as e:
255-
print(f"HTTP Error: {e.code} - {e.reason}")
256-
print(e.read().decode())
257-
raise
255+
if e.code == 404:
256+
# Repository doesn't exist - already deleted
257+
print(f"Repository {repo_name} not found - treating as successful deletion")
258+
cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
259+
return
260+
elif e.code == 403:
261+
# Forbidden - try to archive instead
262+
print(f"HTTP Error deleting repository: 403 - Forbidden")
263+
print(f"Attempting to archive repository instead...")
264+
try:
265+
archive_data = json.dumps({'archived': True}).encode('utf-8')
266+
archive_req = urllib.request.Request(
267+
f"https://api.github.com/repos/{github_owner}/{repo_name}",
268+
data=archive_data,
269+
headers=headers,
270+
method='PATCH'
271+
)
272+
with urllib.request.urlopen(archive_req) as archive_response:
273+
if archive_response.getcode() == 200:
274+
print(f"Repository {repo_name} archived successfully")
275+
cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
276+
return
277+
except Exception as archive_error:
278+
print(f"Failed to archive repository: {str(archive_error)}")
279+
cfnresponse.send(event, context, cfnresponse.FAILED, {})
280+
return
281+
else:
282+
# Other errors - fail
283+
print(f"HTTP Error deleting repository: {e.code} - {e.reason}")
284+
print(e.read().decode())
285+
cfnresponse.send(event, context, cfnresponse.FAILED, {})
286+
return
258287
259288
cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
260289
else:

0 commit comments

Comments
 (0)