Skip to content

Commit 59dd56f

Browse files
committed
feat: try archiving when repo deletion fails
1 parent 3d5ae48 commit 59dd56f

2 files changed

Lines changed: 19 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: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,25 @@ 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}")
255+
print(f"HTTP Error deleting repository: {e.code} - {e.reason}")
256256
print(e.read().decode())
257-
raise
258-
257+
print(f"Attempting to archive repository instead...")
258+
259+
# Try to archive the repository
260+
try:
261+
archive_data = json.dumps({'archived': True}).encode('utf-8')
262+
archive_req = urllib.request.Request(
263+
f"https://api.github.com/repos/{github_owner}/{repo_name}",
264+
data=archive_data,
265+
headers=headers,
266+
method='PATCH'
267+
)
268+
with urllib.request.urlopen(archive_req) as archive_response:
269+
if archive_response.getcode() == 200:
270+
print(f"Repository {repo_name} archived successfully")
271+
except Exception as archive_error:
272+
print(f"Failed to archive repository: {str(archive_error)}")
273+
cfnresponse.send(event, context, cfnresponse.FAILED, {})
259274
cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
260275
else:
261276
# raise Exception(f"Invalid request type: {event['RequestType']}")

0 commit comments

Comments
 (0)