@@ -1244,8 +1244,10 @@ async def update_submission(
1244
1244
if body_dict .get ("status" , None ):
1245
1245
new_status = body_dict ["status" ]
1246
1246
allowed_transitions = {
1247
- SubmissionStatusEnum .UpdatesRequired .text : SubmissionStatusEnum .InProgress .text ,
1248
- SubmissionStatusEnum .InProgress .text : SubmissionStatusEnum .SubmittedPendingReview .text
1247
+ SubmissionStatusEnum .UpdatesRequired .text :
1248
+ SubmissionStatusEnum .InProgress .text ,
1249
+ SubmissionStatusEnum .InProgress .text :
1250
+ SubmissionStatusEnum .SubmittedPendingReview .text ,
1249
1251
}
1250
1252
current_status = submission .status
1251
1253
if (
@@ -1266,15 +1268,18 @@ def create_github_issue(submission: schemas_submission.SubmissionMetadataSchema,
1266
1268
# If the settings for issue creation weren't supplied return, no need to do anything further
1267
1269
if gh_url is None or token is None :
1268
1270
return None
1269
-
1271
+
1270
1272
headers = {"Authorization" : f"Bearer { token } " , "Content-Type" : "text/plain; charset=utf-8" }
1271
1273
1272
1274
# Check for existing issues first
1273
1275
existing_issue = check_existing_github_issue (submission .id , headers , gh_url , user )
1274
1276
if existing_issue :
1275
- logging .info (f"GitHub issue already exists for submission { submission .id } : { existing_issue ['html_url' ]} " )
1277
+ logging .info (
1278
+ f"GitHub issue already exists for submission { submission .id } : \
1279
+ { existing_issue ['html_url' ]} "
1280
+ )
1276
1281
return existing_issue
1277
-
1282
+
1278
1283
else :
1279
1284
1280
1285
# Gathering the fields we want to display in the issue
@@ -1333,6 +1338,7 @@ def create_github_issue(submission: schemas_submission.SubmissionMetadataSchema,
1333
1338
1334
1339
return res
1335
1340
1341
+
1336
1342
def update_github_issue_for_resubmission (existing_issue , user , headers ):
1337
1343
"""
1338
1344
Update an existing GitHub issue to note that the submission was resubmitted.
@@ -1341,78 +1347,73 @@ def update_github_issue_for_resubmission(existing_issue, user, headers):
1341
1347
try :
1342
1348
issue_number = existing_issue .get ("number" )
1343
1349
issue_url = existing_issue .get ("url" ) # API URL for the issue
1344
-
1350
+
1345
1351
if not issue_number or not issue_url :
1346
1352
logging .error ("Could not find issue number or URL for existing GitHub issue" )
1347
1353
return existing_issue
1348
-
1354
+
1349
1355
# Create a comment noting the resubmission
1350
1356
from datetime import datetime
1357
+
1351
1358
timestamp = datetime .utcnow ().strftime ("%Y-%m-%d %H:%M:%S UTC" )
1352
-
1359
+
1353
1360
comment_body = f"""
1354
1361
## 🔄 Submission Resubmitted
1355
1362
1356
- **Resubmitted by:** { user .name } ({ user .orcid } )
1357
- **Timestamp:** { timestamp }
1363
+ **Resubmitted by:** { user .name } ({ user .orcid } )
1364
+ **Timestamp:** { timestamp }
1358
1365
**Status:** { SubmissionStatusEnum .SubmittedPendingReview .text }
1359
1366
1360
1367
The submission has been updated and resubmitted for review.
1361
1368
""" .strip ()
1362
-
1369
+
1363
1370
# Add comment to the issue
1364
1371
comment_url = f"{ issue_url } /comments"
1365
1372
comment_payload = {"body" : comment_body }
1366
-
1373
+
1367
1374
comment_response = requests .post (
1368
- comment_url ,
1369
- headers = headers ,
1370
- data = json .dumps (comment_payload )
1375
+ comment_url , headers = headers , data = json .dumps (comment_payload )
1371
1376
)
1372
-
1377
+
1373
1378
if comment_response .status_code == 201 :
1374
1379
logging .info (f"Successfully added resubmission comment to GitHub issue #{ issue_number } " )
1375
1380
else :
1376
1381
logging .error (f"Failed to add comment to GitHub issue: { comment_response .status_code } " )
1377
-
1382
+
1378
1383
# If the issue is closed, reopen it
1379
1384
if existing_issue .get ("state" ) == "closed" :
1380
- reopen_payload = {
1381
- "state" : "open" ,
1382
- "state_reason" : "reopened"
1383
- }
1384
-
1385
+ reopen_payload = {"state" : "open" , "state_reason" : "reopened" }
1386
+
1385
1387
reopen_response = requests .patch (
1386
- issue_url ,
1387
- headers = headers ,
1388
- data = json .dumps (reopen_payload )
1388
+ issue_url , headers = headers , data = json .dumps (reopen_payload )
1389
1389
)
1390
-
1390
+
1391
1391
if reopen_response .status_code == 200 :
1392
1392
logging .info (f"Successfully reopened GitHub issue #{ issue_number } " )
1393
1393
else :
1394
1394
logging .error (f"Failed to reopen GitHub issue: { reopen_response .status_code } " )
1395
-
1395
+
1396
1396
return existing_issue
1397
-
1397
+
1398
1398
except Exception as e :
1399
1399
logging .error (f"Error updating GitHub issue for resubmission: { str (e )} " )
1400
1400
return existing_issue
1401
1401
1402
- def check_existing_github_issue (submission_id : str , headers : dict , gh_base_url :str , user ):
1402
+
1403
+ def check_existing_github_issue (submission_id : str , headers : dict , gh_base_url : str , user ):
1403
1404
"""
1404
1405
Check if a GitHub issue already exists for the given submission ID using GitHub's search API.
1405
1406
"""
1406
1407
try :
1407
- repo_url = gh_base_url .replace (' /issues' , '' )
1408
+ repo_url = gh_base_url .replace (" /issues" , "" )
1408
1409
search_url = f"{ repo_url } /issues"
1409
1410
expected_title = f"NMDC Submission: { submission_id } "
1410
1411
params = {
1411
1412
"state" : "all" ,
1412
1413
"per_page" : 100 ,
1413
1414
}
1414
1415
response = requests .get (search_url , headers = headers , params = params )
1415
-
1416
+
1416
1417
if response .status_code == 200 :
1417
1418
issues = response .json ()
1418
1419
@@ -1428,11 +1429,12 @@ def check_existing_github_issue(submission_id: str, headers: dict, gh_base_url:s
1428
1429
else :
1429
1430
logging .warning (f"Failed to search GitHub issues: { response .status_code } " )
1430
1431
return None
1431
-
1432
+
1432
1433
except Exception as e :
1433
1434
logging .error (f"Error searching GitHub issues: { str (e )} " )
1434
1435
return None
1435
1436
1437
+
1436
1438
@router .delete (
1437
1439
"/metadata_submission/{id}" ,
1438
1440
tags = ["metadata_submission" ],
0 commit comments