From ebe15732d383c04cecd50478652cd72a8b5ecd8c Mon Sep 17 00:00:00 2001 From: JamesTessmer <47541313+JamesTessmer@users.noreply.github.com> Date: Wed, 10 Apr 2024 11:35:41 -0700 Subject: [PATCH 01/33] Add changes from branch Git was having issues pushing changes up from my local branch so I copied them and pushed from a new version --- nmdc_server/api.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 636ceac6..328adf70 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -30,6 +30,8 @@ ) from nmdc_server.pagination import Pagination +import requests + router = APIRouter() @@ -728,7 +730,10 @@ async def update_submission( status_code=400, detail="This submission is currently being edited by a different user.", ) - + #Create Github issue when metadata is being submitted + if submission.status == 'in-progress' and body_dict.get("status", None) == "Submitted- Pending Review": + create_github_issue(submission,user) + return # Merge the submission metadata dicts submission.metadata_submission = ( submission.metadata_submission | body_dict["metadata_submission"] @@ -746,6 +751,33 @@ async def update_submission( crud.update_submission_lock(db, submission.id) return submission +def create_github_issue(submission,user): + + url = "https://api.github.com/repos/JamesTessmer/Issue-bot-testing/issues?state=all" + + cookies = {'logged_in':'no'} + + headers = {'Authorization':'Bearer TOKEN', + 'Content-Type': 'text/plain; charset=utf-8'} + print(submission.metadata_submission) + studyform = submission.metadata_submission['studyForm'] + contextform = submission.metadata_submission['contextForm'] + multiomicsform = submission.metadata_submission['multiOmicsForm'] + pi = studyform['piName'] + piorcid = studyform['piOrcid'] + datagenerated = contextform['dataGenerated'] + omicsprocessingtypes = multiomicsform['omicsProcessingTypes'] + sampletype = submission.metadata_submission['templates'] + sampledata = submission.metadata_submission['sampleData'] + numsamples = 0 + for key in sampledata: + numsamples = numsamples + len(sampledata[key]) + + payload = '{\n "title":'+f'"NMDC Submission: {submission.id}", \n "body":"Submitter: {user.orcid} \\n Submission ID: {submission.id} \\n Has data been generated: {datagenerated} \\n PI: {pi} {piorcid} \\n Status: Submitted -Pending Review \\n Data types: {omicsprocessingtypes} \\n Sample type: {sampletype} \\n Number of samples: {numsamples} \\n Note:", \n "assignees": ["JamesTessmer"], \n "labels":["testing"]'+'}' + + res = requests.post(url,cookies=cookies,data=payload,headers=headers) + return res + @router.delete( "/metadata_submission/{id}", From 6f97aef303c1e6d2210f789364456e382acdaf45 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Tue, 9 Apr 2024 15:26:11 -0700 Subject: [PATCH 02/33] add create_github_issue with basic functionality --- nmdc_server/api.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 328adf70..0e959d9c 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -733,7 +733,7 @@ async def update_submission( #Create Github issue when metadata is being submitted if submission.status == 'in-progress' and body_dict.get("status", None) == "Submitted- Pending Review": create_github_issue(submission,user) - return + return #REMOVE AFTER TESTING # Merge the submission metadata dicts submission.metadata_submission = ( submission.metadata_submission | body_dict["metadata_submission"] @@ -752,12 +752,15 @@ async def update_submission( return submission def create_github_issue(submission,user): - - url = "https://api.github.com/repos/JamesTessmer/Issue-bot-testing/issues?state=all" + settings = Settings() + gh_url = settings.github_issue_url + token = settings.github_authentication_token + if(gh_url == None or token == None): + return cookies = {'logged_in':'no'} - headers = {'Authorization':'Bearer TOKEN', + headers = {'Authorization':f'Bearer {settings.github_authentication_token}', 'Content-Type': 'text/plain; charset=utf-8'} print(submission.metadata_submission) studyform = submission.metadata_submission['studyForm'] @@ -775,7 +778,7 @@ def create_github_issue(submission,user): payload = '{\n "title":'+f'"NMDC Submission: {submission.id}", \n "body":"Submitter: {user.orcid} \\n Submission ID: {submission.id} \\n Has data been generated: {datagenerated} \\n PI: {pi} {piorcid} \\n Status: Submitted -Pending Review \\n Data types: {omicsprocessingtypes} \\n Sample type: {sampletype} \\n Number of samples: {numsamples} \\n Note:", \n "assignees": ["JamesTessmer"], \n "labels":["testing"]'+'}' - res = requests.post(url,cookies=cookies,data=payload,headers=headers) + res = requests.post(gh_url,cookies=cookies,data=payload,headers=headers) return res From c253f9592ae0ae6f1920664b4659a109854e124d Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 12 Apr 2024 21:20:06 -0700 Subject: [PATCH 03/33] Add fields in config for github automation --- nmdc_server/config.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nmdc_server/config.py b/nmdc_server/config.py index 8f363bdd..86418d82 100644 --- a/nmdc_server/config.py +++ b/nmdc_server/config.py @@ -65,6 +65,10 @@ class Settings(BaseSettings): # CORS settings necessary for allowing request from Field Notes app cors_allow_origins: Optional[str] = None # comma separated list of allowed origins + # Github Issue creation settings. Both are required for automated issue creation. + github_issue_url: Optional[str] = None + github_authentication_token: Optional[str] = None + @property def current_db_uri(self) -> str: if self.environment == "testing": From 36e918c4487f1eb999b9b8feec96c9c266a7bedf Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Thu, 18 Apr 2024 16:06:37 -0700 Subject: [PATCH 04/33] updated reference to token --- nmdc_server/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 0e959d9c..98141667 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -760,7 +760,7 @@ def create_github_issue(submission,user): cookies = {'logged_in':'no'} - headers = {'Authorization':f'Bearer {settings.github_authentication_token}', + headers = {'Authorization':f'Bearer {token}', 'Content-Type': 'text/plain; charset=utf-8'} print(submission.metadata_submission) studyform = submission.metadata_submission['studyForm'] From d86954436f4a2bb1df151468acf8f636b676e5f6 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Thu, 18 Apr 2024 16:07:52 -0700 Subject: [PATCH 05/33] remove logged_in cookie --- nmdc_server/api.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 98141667..e12949fa 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -758,8 +758,6 @@ def create_github_issue(submission,user): if(gh_url == None or token == None): return - cookies = {'logged_in':'no'} - headers = {'Authorization':f'Bearer {token}', 'Content-Type': 'text/plain; charset=utf-8'} print(submission.metadata_submission) From 7f735843a18df387203245821d6a77085ce7751b Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Thu, 18 Apr 2024 16:08:44 -0700 Subject: [PATCH 06/33] Remove debugging line --- nmdc_server/api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index e12949fa..8e093880 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -760,7 +760,6 @@ def create_github_issue(submission,user): headers = {'Authorization':f'Bearer {token}', 'Content-Type': 'text/plain; charset=utf-8'} - print(submission.metadata_submission) studyform = submission.metadata_submission['studyForm'] contextform = submission.metadata_submission['contextForm'] multiomicsform = submission.metadata_submission['multiOmicsForm'] From fcc7efb6eccfbbe01c3891cb11b1a6504f3038fd Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Thu, 18 Apr 2024 16:15:56 -0700 Subject: [PATCH 07/33] add fix for numsamples --- nmdc_server/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 8e093880..19b2f543 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -771,7 +771,7 @@ def create_github_issue(submission,user): sampledata = submission.metadata_submission['sampleData'] numsamples = 0 for key in sampledata: - numsamples = numsamples + len(sampledata[key]) + numsamples = max(numsamples, len(sampledata[key])) payload = '{\n "title":'+f'"NMDC Submission: {submission.id}", \n "body":"Submitter: {user.orcid} \\n Submission ID: {submission.id} \\n Has data been generated: {datagenerated} \\n PI: {pi} {piorcid} \\n Status: Submitted -Pending Review \\n Data types: {omicsprocessingtypes} \\n Sample type: {sampletype} \\n Number of samples: {numsamples} \\n Note:", \n "assignees": ["JamesTessmer"], \n "labels":["testing"]'+'}' From 90d3bd105749843c180b556f86381b6c2a238896 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Thu, 18 Apr 2024 16:26:34 -0700 Subject: [PATCH 08/33] remove cookies ref in requests --- nmdc_server/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 19b2f543..83232805 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -775,7 +775,8 @@ def create_github_issue(submission,user): payload = '{\n "title":'+f'"NMDC Submission: {submission.id}", \n "body":"Submitter: {user.orcid} \\n Submission ID: {submission.id} \\n Has data been generated: {datagenerated} \\n PI: {pi} {piorcid} \\n Status: Submitted -Pending Review \\n Data types: {omicsprocessingtypes} \\n Sample type: {sampletype} \\n Number of samples: {numsamples} \\n Note:", \n "assignees": ["JamesTessmer"], \n "labels":["testing"]'+'}' - res = requests.post(gh_url,cookies=cookies,data=payload,headers=headers) + res = requests.post(gh_url,data=payload,headers=headers) + print(res) return res From c9ce2d8b7a27df44a925d7c5d0969ca881ca7d7d Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Thu, 18 Apr 2024 17:10:49 -0700 Subject: [PATCH 09/33] Add logging capability --- nmdc_server/api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 83232805..bdb18f61 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -31,6 +31,7 @@ from nmdc_server.pagination import Pagination import requests +import logging router = APIRouter() @@ -776,7 +777,10 @@ def create_github_issue(submission,user): payload = '{\n "title":'+f'"NMDC Submission: {submission.id}", \n "body":"Submitter: {user.orcid} \\n Submission ID: {submission.id} \\n Has data been generated: {datagenerated} \\n PI: {pi} {piorcid} \\n Status: Submitted -Pending Review \\n Data types: {omicsprocessingtypes} \\n Sample type: {sampletype} \\n Number of samples: {numsamples} \\n Note:", \n "assignees": ["JamesTessmer"], \n "labels":["testing"]'+'}' res = requests.post(gh_url,data=payload,headers=headers) - print(res) + if res.status_code != 201: + logging.error(f"Github issue creation failed with code {res.status_code}") + else: + logging.info(f"Github issue creation successful with code {res.status_code}") return res From d529ddd8b4d0416ab844a5a753d44c14a41a98f5 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Thu, 18 Apr 2024 17:14:11 -0700 Subject: [PATCH 10/33] add response text error logging --- nmdc_server/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index bdb18f61..1adc2269 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -779,6 +779,7 @@ def create_github_issue(submission,user): res = requests.post(gh_url,data=payload,headers=headers) if res.status_code != 201: logging.error(f"Github issue creation failed with code {res.status_code}") + logging.error(res.text) else: logging.info(f"Github issue creation successful with code {res.status_code}") return res From 0628ac2f892993fafbc292bc6c85f2d4b5fa0184 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Thu, 18 Apr 2024 17:16:23 -0700 Subject: [PATCH 11/33] update response.test to response.reason --- nmdc_server/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 1adc2269..c0a7d240 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -779,9 +779,10 @@ def create_github_issue(submission,user): res = requests.post(gh_url,data=payload,headers=headers) if res.status_code != 201: logging.error(f"Github issue creation failed with code {res.status_code}") - logging.error(res.text) + logging.error(res.reason) else: logging.info(f"Github issue creation successful with code {res.status_code}") + logging.info(res.reason) return res From a02dbc6ccdb38b8900d243ae1615d71afb6d3af3 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 19 Apr 2024 13:02:49 -0700 Subject: [PATCH 12/33] Add json dump and readability --- nmdc_server/api.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index c0a7d240..37e609ee 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -32,6 +32,7 @@ import requests import logging +import json router = APIRouter() @@ -774,7 +775,17 @@ def create_github_issue(submission,user): for key in sampledata: numsamples = max(numsamples, len(sampledata[key])) - payload = '{\n "title":'+f'"NMDC Submission: {submission.id}", \n "body":"Submitter: {user.orcid} \\n Submission ID: {submission.id} \\n Has data been generated: {datagenerated} \\n PI: {pi} {piorcid} \\n Status: Submitted -Pending Review \\n Data types: {omicsprocessingtypes} \\n Sample type: {sampletype} \\n Number of samples: {numsamples} \\n Note:", \n "assignees": ["JamesTessmer"], \n "labels":["testing"]'+'}' + body_lis = [f"Submitter: {user.orcid}", f"Submission ID: {submission.id}", + f"Has data been generated: {datagenerated}", f"PI: {pi} {piorcid}", + "Status: Submitted -Pending Review", f"Data types: {omicsprocessingtypes}", + f"Sample type:{sampletype}", f"Number of samples:{numsamples}", "Note:"] + body_string = " \n ".join(body_lis) + payload_dict = {"title":f"NMDC Submission{submission.id}", + "body":body_string, + "assignees":['JamesTessmer'], + "labels":['testing']} + + payload = json.dumps(payload_dict) res = requests.post(gh_url,data=payload,headers=headers) if res.status_code != 201: From 0f4b94e19290962a995b669a575645fe47de0b01 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 19 Apr 2024 14:15:07 -0700 Subject: [PATCH 13/33] Some formatting to make markdown look nicer --- nmdc_server/api.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 37e609ee..82f33bf0 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -735,7 +735,6 @@ async def update_submission( #Create Github issue when metadata is being submitted if submission.status == 'in-progress' and body_dict.get("status", None) == "Submitted- Pending Review": create_github_issue(submission,user) - return #REMOVE AFTER TESTING # Merge the submission metadata dicts submission.metadata_submission = ( submission.metadata_submission | body_dict["metadata_submission"] @@ -767,16 +766,16 @@ def create_github_issue(submission,user): multiomicsform = submission.metadata_submission['multiOmicsForm'] pi = studyform['piName'] piorcid = studyform['piOrcid'] - datagenerated = contextform['dataGenerated'] - omicsprocessingtypes = multiomicsform['omicsProcessingTypes'] - sampletype = submission.metadata_submission['templates'] + datagenerated = "Yes" if contextform['dataGenerated'] else "No" + omicsprocessingtypes = ", ".join(multiomicsform['omicsProcessingTypes']) + sampletype = ", ".join(submission.metadata_submission['templates']) sampledata = submission.metadata_submission['sampleData'] numsamples = 0 for key in sampledata: numsamples = max(numsamples, len(sampledata[key])) body_lis = [f"Submitter: {user.orcid}", f"Submission ID: {submission.id}", - f"Has data been generated: {datagenerated}", f"PI: {pi} {piorcid}", + f"Has data been generated: {datagenerated}", f"PI name and Orcid: {pi} {piorcid}", "Status: Submitted -Pending Review", f"Data types: {omicsprocessingtypes}", f"Sample type:{sampletype}", f"Number of samples:{numsamples}", "Note:"] body_string = " \n ".join(body_lis) From 0734a29dc4b7538eae87d7baf047e844c7c14138 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 19 Apr 2024 14:50:26 -0700 Subject: [PATCH 14/33] Fixed linting and formatting errors. --- nmdc_server/api.py | 66 +++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 82f33bf0..383f2dad 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -29,7 +29,6 @@ User, ) from nmdc_server.pagination import Pagination - import requests import logging import json @@ -732,9 +731,13 @@ async def update_submission( status_code=400, detail="This submission is currently being edited by a different user.", ) - #Create Github issue when metadata is being submitted - if submission.status == 'in-progress' and body_dict.get("status", None) == "Submitted- Pending Review": - create_github_issue(submission,user) + # Create Github issue when metadata is being submitted + if ( + submission.status == "in-progress" + and body_dict.get("status", None) == "Submitted- Pending Review" + ): + create_github_issue(submission, user) + return # REMOVE AFTER TESTING # Merge the submission metadata dicts submission.metadata_submission = ( submission.metadata_submission | body_dict["metadata_submission"] @@ -752,41 +755,50 @@ async def update_submission( crud.update_submission_lock(db, submission.id) return submission -def create_github_issue(submission,user): + +def create_github_issue(submission, user): settings = Settings() gh_url = settings.github_issue_url token = settings.github_authentication_token - if(gh_url == None or token == None): + if gh_url == None or token == None: return - headers = {'Authorization':f'Bearer {token}', - 'Content-Type': 'text/plain; charset=utf-8'} - studyform = submission.metadata_submission['studyForm'] - contextform = submission.metadata_submission['contextForm'] - multiomicsform = submission.metadata_submission['multiOmicsForm'] - pi = studyform['piName'] - piorcid = studyform['piOrcid'] - datagenerated = "Yes" if contextform['dataGenerated'] else "No" - omicsprocessingtypes = ", ".join(multiomicsform['omicsProcessingTypes']) - sampletype = ", ".join(submission.metadata_submission['templates']) - sampledata = submission.metadata_submission['sampleData'] + headers = {"Authorization": f"Bearer {token}", "Content-Type": "text/plain; charset=utf-8"} + studyform = submission.metadata_submission["studyForm"] + contextform = submission.metadata_submission["contextForm"] + multiomicsform = submission.metadata_submission["multiOmicsForm"] + pi = studyform["piName"] + piorcid = studyform["piOrcid"] + datagenerated = "Yes" if contextform["dataGenerated"] else "No" + omicsprocessingtypes = ", ".join(multiomicsform["omicsProcessingTypes"]) + sampletype = ", ".join(submission.metadata_submission["templates"]) + sampledata = submission.metadata_submission["sampleData"] numsamples = 0 for key in sampledata: numsamples = max(numsamples, len(sampledata[key])) - body_lis = [f"Submitter: {user.orcid}", f"Submission ID: {submission.id}", - f"Has data been generated: {datagenerated}", f"PI name and Orcid: {pi} {piorcid}", - "Status: Submitted -Pending Review", f"Data types: {omicsprocessingtypes}", - f"Sample type:{sampletype}", f"Number of samples:{numsamples}", "Note:"] + body_lis = [ + f"Submitter: {user.orcid}", + f"Submission ID: {submission.id}", + f"Has data been generated: {datagenerated}", + f"PI name and Orcid: {pi} {piorcid}", + "Status: Submitted -Pending Review", + f"Data types: {omicsprocessingtypes}", + f"Sample type:{sampletype}", + f"Number of samples:{numsamples}", + "Note:", + ] body_string = " \n ".join(body_lis) - payload_dict = {"title":f"NMDC Submission{submission.id}", - "body":body_string, - "assignees":['JamesTessmer'], - "labels":['testing']} + payload_dict = { + "title": f"NMDC Submission{submission.id}", + "body": body_string, + "assignees": ["JamesTessmer"], + "labels": ["testing"], + } payload = json.dumps(payload_dict) - - res = requests.post(gh_url,data=payload,headers=headers) + + res = requests.post(url=gh_url, data=payload, headers=headers) if res.status_code != 201: logging.error(f"Github issue creation failed with code {res.status_code}") logging.error(res.reason) From c1c680ba5507e42916a691f8f8035a9ae91f0abd Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 19 Apr 2024 14:51:31 -0700 Subject: [PATCH 15/33] remove return statement used for tests --- nmdc_server/api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 383f2dad..98f0b1fb 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -737,7 +737,6 @@ async def update_submission( and body_dict.get("status", None) == "Submitted- Pending Review" ): create_github_issue(submission, user) - return # REMOVE AFTER TESTING # Merge the submission metadata dicts submission.metadata_submission = ( submission.metadata_submission | body_dict["metadata_submission"] From 66721ba36e104a67a027ca7cdcf450b4a3f00c8d Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 19 Apr 2024 14:56:38 -0700 Subject: [PATCH 16/33] Repositioning imports for lint --- nmdc_server/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 98f0b1fb..eaa8ab48 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -7,6 +7,9 @@ from sqlalchemy.orm import Session from starlette.requests import Request from starlette.responses import RedirectResponse, StreamingResponse +import requests +import logging +import json from nmdc_server import __version__, crud, jobs, models, query, schemas, schemas_submission from nmdc_server.auth import ( @@ -29,9 +32,6 @@ User, ) from nmdc_server.pagination import Pagination -import requests -import logging -import json router = APIRouter() From 14dfcb38be500e757d66626d4c19002ac2080bb1 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 19 Apr 2024 15:03:04 -0700 Subject: [PATCH 17/33] reordered imports to the actual correct positions --- nmdc_server/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index eaa8ab48..bb1a9855 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -1,15 +1,15 @@ +import json +import logging from io import BytesIO from typing import Any, Dict, List, Optional from uuid import UUID +import requests from fastapi import APIRouter, Depends, Header, HTTPException, Response, status from fastapi.responses import JSONResponse, PlainTextResponse from sqlalchemy.orm import Session from starlette.requests import Request from starlette.responses import RedirectResponse, StreamingResponse -import requests -import logging -import json from nmdc_server import __version__, crud, jobs, models, query, schemas, schemas_submission from nmdc_server.auth import ( From fcffd0b5716d6f232047268028c73f17747b8268 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 19 Apr 2024 15:05:58 -0700 Subject: [PATCH 18/33] added typing to github url --- nmdc_server/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index bb1a9855..50a180ca 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -757,7 +757,7 @@ async def update_submission( def create_github_issue(submission, user): settings = Settings() - gh_url = settings.github_issue_url + gh_url = str(settings.github_issue_url) token = settings.github_authentication_token if gh_url == None or token == None: return From 02a77dd0eba64f441affd5dcf8c46e1002edab24 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Thu, 2 May 2024 15:28:15 -0700 Subject: [PATCH 19/33] Add github issue to project board function --- docker-compose.yml | 2 ++ nmdc_server/api.py | 40 +++++++++++++++++++++++++++++++++++++--- nmdc_server/config.py | 4 ++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 74e7392f..e82145ce 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,6 +20,8 @@ services: - "-c" # Our MGA ingest makes some *very* large transactions - "max_wal_size=2GB" + ports: + - "5555:5432" worker: image: ghcr.io/microbiomedata/nmdc-server/worker:main diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 50a180ca..af889ce6 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -736,12 +736,13 @@ async def update_submission( submission.status == "in-progress" and body_dict.get("status", None) == "Submitted- Pending Review" ): + print(submission.metadata_submission) create_github_issue(submission, user) + return # Merge the submission metadata dicts submission.metadata_submission = ( submission.metadata_submission | body_dict["metadata_submission"] ) - # Update permissions and status iff the user is an "owner" if current_user_role and current_user_role.role == models.SubmissionEditorRole.owner: new_permissions = body_dict.get("permissions", None) @@ -776,11 +777,18 @@ def create_github_issue(submission, user): for key in sampledata: numsamples = max(numsamples, len(sampledata[key])) + #some variable data to supply depending on if data has been generated or not + data_ids = [] + if contextForm["dataGenerated"]: + data_ids = [f"Gold IDs: {multiomicsform["NCBIBioProjectId"]}", + f"NCBI IDs: {multiomcisform["JGIStudyId"]}"] + body_lis = [ - f"Submitter: {user.orcid}", + f"Submitter: {user.name}, {user.orcid}", f"Submission ID: {submission.id}", f"Has data been generated: {datagenerated}", - f"PI name and Orcid: {pi} {piorcid}", + f"PI name: {pi}", + f"PI orcid: {piorcid}", "Status: Submitted -Pending Review", f"Data types: {omicsprocessingtypes}", f"Sample type:{sampletype}", @@ -804,8 +812,34 @@ def create_github_issue(submission, user): else: logging.info(f"Github issue creation successful with code {res.status_code}") logging.info(res.reason) + # if issue creation is successful we want to put the issue on a project board, if details for that are supplied + issue_node_id = res.json()['node_id'] + project_res = github_issue_to_project(issue_node_id,settings) + return res +def github_issue_to_project(issue_node_id:str, settings): + gh_project_token = settings.gh_project_token + gh_project_id = settings.gh_project_id + + if(gh_project_token == None or gh_project_id = None): + logging.error("Could not post created github issue to project board. Either access token or project ID are not supplied.") + return + + board_headers = {'Authorization':f'Bearer {gh_project_token}'} + payload = {"query":"mutation {addProjectV2ItemById(input: {projectId: "+f'"{gh_project_id}" contentId: "{issue_node_id}"'+"}) {item {id}}}"} + res = requests.post(url="https://api.github.com/graphql", + json=payload, + headers=board_headers) + + if res.status_code != 201: + logging.error(f"Could not post issue to project. Failed with code {res.status_code}") + logging.error(res.reason) + else: + logging.info(f"Github issue post to project board successful with code {res.status_code}") + logging.info(res.reason) + + return res @router.delete( "/metadata_submission/{id}", diff --git a/nmdc_server/config.py b/nmdc_server/config.py index 91819648..9b8ef0ae 100644 --- a/nmdc_server/config.py +++ b/nmdc_server/config.py @@ -71,6 +71,10 @@ class Settings(BaseSettings): github_issue_url: Optional[str] = None github_authentication_token: Optional[str] = None + #Github Issue to Project board settings. Both are required to post issue to project. + gh_project_token: Optional[str] = None + gh_project_id: Optional[str] = None + @property def current_db_uri(self) -> str: if self.environment == "testing": From f6fc626ea61706c97830e7ea673ffa8251f82362 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Thu, 2 May 2024 18:29:02 -0700 Subject: [PATCH 20/33] small bug fixes with posting to project board --- nmdc_server/api.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index af889ce6..04687667 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -778,10 +778,10 @@ def create_github_issue(submission, user): numsamples = max(numsamples, len(sampledata[key])) #some variable data to supply depending on if data has been generated or not - data_ids = [] - if contextForm["dataGenerated"]: - data_ids = [f"Gold IDs: {multiomicsform["NCBIBioProjectId"]}", - f"NCBI IDs: {multiomcisform["JGIStudyId"]}"] + #data_ids = [] + #if contextForm["dataGenerated"]: + #data_ids = [f"Gold IDs: {multiomicsform["NCBIBioProjectId"]}", + # f"NCBI IDs: {multiomcisform["JGIStudyId"]}"] body_lis = [ f"Submitter: {user.name}, {user.orcid}", @@ -821,8 +821,8 @@ def create_github_issue(submission, user): def github_issue_to_project(issue_node_id:str, settings): gh_project_token = settings.gh_project_token gh_project_id = settings.gh_project_id - - if(gh_project_token == None or gh_project_id = None): + + if(gh_project_token == None or gh_project_id == None): logging.error("Could not post created github issue to project board. Either access token or project ID are not supplied.") return @@ -832,13 +832,12 @@ def github_issue_to_project(issue_node_id:str, settings): json=payload, headers=board_headers) - if res.status_code != 201: + if res.status_code != 200: logging.error(f"Could not post issue to project. Failed with code {res.status_code}") logging.error(res.reason) else: logging.info(f"Github issue post to project board successful with code {res.status_code}") logging.info(res.reason) - return res @router.delete( From bae9a28b0a71508a98b80d9a141c6169856789a7 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 3 May 2024 13:52:25 -0700 Subject: [PATCH 21/33] Fixed some spacing and added comments --- nmdc_server/api.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 04687667..4ee17fad 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -760,9 +760,11 @@ def create_github_issue(submission, user): settings = Settings() gh_url = str(settings.github_issue_url) token = settings.github_authentication_token + #If the settings for issue creation weren't supplied return, no need to do anything further if gh_url == None or token == None: return + #Gathering the fields we want to display in the issue headers = {"Authorization": f"Bearer {token}", "Content-Type": "text/plain; charset=utf-8"} studyform = submission.metadata_submission["studyForm"] contextform = submission.metadata_submission["contextForm"] @@ -778,11 +780,12 @@ def create_github_issue(submission, user): numsamples = max(numsamples, len(sampledata[key])) #some variable data to supply depending on if data has been generated or not - #data_ids = [] - #if contextForm["dataGenerated"]: - #data_ids = [f"Gold IDs: {multiomicsform["NCBIBioProjectId"]}", - # f"NCBI IDs: {multiomcisform["JGIStudyId"]}"] + data_ids = [] + if contextForm["dataGenerated"]: + data_ids = [f"Gold IDs: " + multiomicsform["NCBIBioProjectId"], + f"NCBI IDs: {multiomcisform["JGIStudyId"]}"] + #assemble the body of the API request body_lis = [ f"Submitter: {user.name}, {user.orcid}", f"Submission ID: {submission.id}", @@ -797,7 +800,7 @@ def create_github_issue(submission, user): ] body_string = " \n ".join(body_lis) payload_dict = { - "title": f"NMDC Submission{submission.id}", + "title": f"NMDC Submission: {submission.id}", "body": body_string, "assignees": ["JamesTessmer"], "labels": ["testing"], @@ -805,6 +808,7 @@ def create_github_issue(submission, user): payload = json.dumps(payload_dict) + #make request and log an error or success depending on reply res = requests.post(url=gh_url, data=payload, headers=headers) if res.status_code != 201: logging.error(f"Github issue creation failed with code {res.status_code}") @@ -821,17 +825,20 @@ def create_github_issue(submission, user): def github_issue_to_project(issue_node_id:str, settings): gh_project_token = settings.gh_project_token gh_project_id = settings.gh_project_id - + + #Same as github issue, if we're missing the settings then we return. if(gh_project_token == None or gh_project_id == None): logging.error("Could not post created github issue to project board. Either access token or project ID are not supplied.") return + #All project API requests go through the same end point so all we specify is the project ID that we want to post to and the node id of the issue we want to post board_headers = {'Authorization':f'Bearer {gh_project_token}'} payload = {"query":"mutation {addProjectV2ItemById(input: {projectId: "+f'"{gh_project_id}" contentId: "{issue_node_id}"'+"}) {item {id}}}"} res = requests.post(url="https://api.github.com/graphql", json=payload, headers=board_headers) + #do some logging based on reply of request if res.status_code != 200: logging.error(f"Could not post issue to project. Failed with code {res.status_code}") logging.error(res.reason) From 71bab835b719708524d4850ef56c30a819136417 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 3 May 2024 14:16:48 -0700 Subject: [PATCH 22/33] add logic to supply fields for issue if there is/is not data --- nmdc_server/api.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 4ee17fad..fa031f30 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -738,7 +738,6 @@ async def update_submission( ): print(submission.metadata_submission) create_github_issue(submission, user) - return # Merge the submission metadata dicts submission.metadata_submission = ( submission.metadata_submission | body_dict["metadata_submission"] @@ -781,9 +780,16 @@ def create_github_issue(submission, user): #some variable data to supply depending on if data has been generated or not data_ids = [] - if contextForm["dataGenerated"]: - data_ids = [f"Gold IDs: " + multiomicsform["NCBIBioProjectId"], - f"NCBI IDs: {multiomcisform["JGIStudyId"]}"] + if contextform["dataGenerated"]: + data_ids = ["NCBI ID: " + multiomicsform["NCBIBioProjectId"], + "GOLD ID: " + multiomicsform["GOLDStudyId"], + "Alternative IDs/Names: " + ', '.join(multiomicsform["alternativeNames"])] + + else: + data_ids = ["JGI IDs: " + multiomicsform["JGIStudyId"], + "EMSL IDs: " + multiomicsform["studyNumber"], + "Alternative IDs/Names: " + ', '.join(multiomicsform["alternativeNames"])] + #assemble the body of the API request body_lis = [ @@ -796,7 +802,10 @@ def create_github_issue(submission, user): f"Data types: {omicsprocessingtypes}", f"Sample type:{sampletype}", f"Number of samples:{numsamples}", - "Note:", + data_ids[0], + data_ids[1], + data_ids[2], + "Note:" ] body_string = " \n ".join(body_lis) payload_dict = { From 562427ab6c0aa553c19883a5ad16c45e58325e6f Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 3 May 2024 14:17:10 -0700 Subject: [PATCH 23/33] remove testing line --- nmdc_server/api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index fa031f30..54c0f786 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -736,7 +736,6 @@ async def update_submission( submission.status == "in-progress" and body_dict.get("status", None) == "Submitted- Pending Review" ): - print(submission.metadata_submission) create_github_issue(submission, user) # Merge the submission metadata dicts submission.metadata_submission = ( From 673c1518ef7ac34125d9eab6882f447352dcc8be Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 3 May 2024 14:20:58 -0700 Subject: [PATCH 24/33] remove other testing lines --- nmdc_server/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 54c0f786..233af997 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -810,8 +810,8 @@ def create_github_issue(submission, user): payload_dict = { "title": f"NMDC Submission: {submission.id}", "body": body_string, - "assignees": ["JamesTessmer"], - "labels": ["testing"], + "assignees": ["mslarae13"], + "labels": [], } payload = json.dumps(payload_dict) From e2d9908543f0918a1d8d1e543fbe58b1d8b4bd8b Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 3 May 2024 14:24:08 -0700 Subject: [PATCH 25/33] Fixed formatting issues --- nmdc_server/api.py | 63 ++++++++++++++++++++++++------------------- nmdc_server/config.py | 2 +- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 233af997..d8319d2b 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -758,11 +758,11 @@ def create_github_issue(submission, user): settings = Settings() gh_url = str(settings.github_issue_url) token = settings.github_authentication_token - #If the settings for issue creation weren't supplied return, no need to do anything further + # If the settings for issue creation weren't supplied return, no need to do anything further if gh_url == None or token == None: return - #Gathering the fields we want to display in the issue + # Gathering the fields we want to display in the issue headers = {"Authorization": f"Bearer {token}", "Content-Type": "text/plain; charset=utf-8"} studyform = submission.metadata_submission["studyForm"] contextform = submission.metadata_submission["contextForm"] @@ -777,20 +777,23 @@ def create_github_issue(submission, user): for key in sampledata: numsamples = max(numsamples, len(sampledata[key])) - #some variable data to supply depending on if data has been generated or not + # some variable data to supply depending on if data has been generated or not data_ids = [] if contextform["dataGenerated"]: - data_ids = ["NCBI ID: " + multiomicsform["NCBIBioProjectId"], - "GOLD ID: " + multiomicsform["GOLDStudyId"], - "Alternative IDs/Names: " + ', '.join(multiomicsform["alternativeNames"])] + data_ids = [ + "NCBI ID: " + multiomicsform["NCBIBioProjectId"], + "GOLD ID: " + multiomicsform["GOLDStudyId"], + "Alternative IDs/Names: " + ", ".join(multiomicsform["alternativeNames"]), + ] else: - data_ids = ["JGI IDs: " + multiomicsform["JGIStudyId"], - "EMSL IDs: " + multiomicsform["studyNumber"], - "Alternative IDs/Names: " + ', '.join(multiomicsform["alternativeNames"])] - + data_ids = [ + "JGI IDs: " + multiomicsform["JGIStudyId"], + "EMSL IDs: " + multiomicsform["studyNumber"], + "Alternative IDs/Names: " + ", ".join(multiomicsform["alternativeNames"]), + ] - #assemble the body of the API request + # assemble the body of the API request body_lis = [ f"Submitter: {user.name}, {user.orcid}", f"Submission ID: {submission.id}", @@ -804,7 +807,7 @@ def create_github_issue(submission, user): data_ids[0], data_ids[1], data_ids[2], - "Note:" + "Note:", ] body_string = " \n ".join(body_lis) payload_dict = { @@ -816,7 +819,7 @@ def create_github_issue(submission, user): payload = json.dumps(payload_dict) - #make request and log an error or success depending on reply + # make request and log an error or success depending on reply res = requests.post(url=gh_url, data=payload, headers=headers) if res.status_code != 201: logging.error(f"Github issue creation failed with code {res.status_code}") @@ -825,28 +828,33 @@ def create_github_issue(submission, user): logging.info(f"Github issue creation successful with code {res.status_code}") logging.info(res.reason) # if issue creation is successful we want to put the issue on a project board, if details for that are supplied - issue_node_id = res.json()['node_id'] - project_res = github_issue_to_project(issue_node_id,settings) + issue_node_id = res.json()["node_id"] + project_res = github_issue_to_project(issue_node_id, settings) return res -def github_issue_to_project(issue_node_id:str, settings): + +def github_issue_to_project(issue_node_id: str, settings): gh_project_token = settings.gh_project_token gh_project_id = settings.gh_project_id - #Same as github issue, if we're missing the settings then we return. - if(gh_project_token == None or gh_project_id == None): - logging.error("Could not post created github issue to project board. Either access token or project ID are not supplied.") - return + # Same as github issue, if we're missing the settings then we return. + if gh_project_token == None or gh_project_id == None: + logging.error( + "Could not post created github issue to project board. Either access token or project ID are not supplied." + ) + return - #All project API requests go through the same end point so all we specify is the project ID that we want to post to and the node id of the issue we want to post - board_headers = {'Authorization':f'Bearer {gh_project_token}'} - payload = {"query":"mutation {addProjectV2ItemById(input: {projectId: "+f'"{gh_project_id}" contentId: "{issue_node_id}"'+"}) {item {id}}}"} - res = requests.post(url="https://api.github.com/graphql", - json=payload, - headers=board_headers) + # All project API requests go through the same end point so all we specify is the project ID that we want to post to and the node id of the issue we want to post + board_headers = {"Authorization": f"Bearer {gh_project_token}"} + payload = { + "query": "mutation {addProjectV2ItemById(input: {projectId: " + + f'"{gh_project_id}" contentId: "{issue_node_id}"' + + "}) {item {id}}}" + } + res = requests.post(url="https://api.github.com/graphql", json=payload, headers=board_headers) - #do some logging based on reply of request + # do some logging based on reply of request if res.status_code != 200: logging.error(f"Could not post issue to project. Failed with code {res.status_code}") logging.error(res.reason) @@ -855,6 +863,7 @@ def github_issue_to_project(issue_node_id:str, settings): logging.info(res.reason) return res + @router.delete( "/metadata_submission/{id}", tags=["metadata_submission"], diff --git a/nmdc_server/config.py b/nmdc_server/config.py index 9b8ef0ae..a8522b99 100644 --- a/nmdc_server/config.py +++ b/nmdc_server/config.py @@ -71,7 +71,7 @@ class Settings(BaseSettings): github_issue_url: Optional[str] = None github_authentication_token: Optional[str] = None - #Github Issue to Project board settings. Both are required to post issue to project. + # Github Issue to Project board settings. Both are required to post issue to project. gh_project_token: Optional[str] = None gh_project_id: Optional[str] = None From 7eae4bc2b8b9bcf0a31b1b409db823f9d1661ba6 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 3 May 2024 14:35:42 -0700 Subject: [PATCH 26/33] remove label tag in issue creation --- nmdc_server/api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index d8319d2b..77eca453 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -814,7 +814,6 @@ def create_github_issue(submission, user): "title": f"NMDC Submission: {submission.id}", "body": body_string, "assignees": ["mslarae13"], - "labels": [], } payload = json.dumps(payload_dict) From d522925c090d78b3d320703249f2c3a046adf957 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 3 May 2024 14:43:38 -0700 Subject: [PATCH 27/33] fixed lint issues --- nmdc_server/api.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 77eca453..122b31f0 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -826,9 +826,10 @@ def create_github_issue(submission, user): else: logging.info(f"Github issue creation successful with code {res.status_code}") logging.info(res.reason) - # if issue creation is successful we want to put the issue on a project board, if details for that are supplied + # if issue creation is successful we want to put the issue on a project board + # if details for that are supplied issue_node_id = res.json()["node_id"] - project_res = github_issue_to_project(issue_node_id, settings) + github_issue_to_project(issue_node_id, settings) return res @@ -840,11 +841,13 @@ def github_issue_to_project(issue_node_id: str, settings): # Same as github issue, if we're missing the settings then we return. if gh_project_token == None or gh_project_id == None: logging.error( - "Could not post created github issue to project board. Either access token or project ID are not supplied." + "Posting issue to projec board failed. Missing token or id. See config" ) return - # All project API requests go through the same end point so all we specify is the project ID that we want to post to and the node id of the issue we want to post + # All project API requests go through the same end point. + # so all we specify is the project ID that we want to post to + # and the node id of the issue we want to post board_headers = {"Authorization": f"Bearer {gh_project_token}"} payload = { "query": "mutation {addProjectV2ItemById(input: {projectId: " From f3c521f34d71dc6905cea4a7deb6995a0835e8b8 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 3 May 2024 14:48:16 -0700 Subject: [PATCH 28/33] removed trailing white space --- nmdc_server/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 122b31f0..bf1d87d6 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -826,7 +826,7 @@ def create_github_issue(submission, user): else: logging.info(f"Github issue creation successful with code {res.status_code}") logging.info(res.reason) - # if issue creation is successful we want to put the issue on a project board + # if issue creation is successful we want to put the issue on a project board # if details for that are supplied issue_node_id = res.json()["node_id"] github_issue_to_project(issue_node_id, settings) @@ -846,7 +846,7 @@ def github_issue_to_project(issue_node_id: str, settings): return # All project API requests go through the same end point. - # so all we specify is the project ID that we want to post to + # so all we specify is the project ID that we want to post to # and the node id of the issue we want to post board_headers = {"Authorization": f"Bearer {gh_project_token}"} payload = { From af4c9826ed3ed5e44c6ad3ce456fdefe23949661 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Fri, 3 May 2024 15:01:39 -0700 Subject: [PATCH 29/33] fixed black formatting error --- nmdc_server/api.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index bf1d87d6..cefa336d 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -840,9 +840,7 @@ def github_issue_to_project(issue_node_id: str, settings): # Same as github issue, if we're missing the settings then we return. if gh_project_token == None or gh_project_id == None: - logging.error( - "Posting issue to projec board failed. Missing token or id. See config" - ) + logging.error("Posting issue to projec board failed. Missing token or id. See config") return # All project API requests go through the same end point. From 40bf241556858ddf058c83bc44c049509cccaff2 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Tue, 7 May 2024 15:12:27 -0700 Subject: [PATCH 30/33] Implement PR suggestions --- nmdc_server/api.py | 11 ++++------- nmdc_server/config.py | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index cefa336d..429ec498 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -758,6 +758,7 @@ def create_github_issue(submission, user): settings = Settings() gh_url = str(settings.github_issue_url) token = settings.github_authentication_token + assignee = settings.github_issue_assignee # If the settings for issue creation weren't supplied return, no need to do anything further if gh_url == None or token == None: return @@ -804,16 +805,12 @@ def create_github_issue(submission, user): f"Data types: {omicsprocessingtypes}", f"Sample type:{sampletype}", f"Number of samples:{numsamples}", - data_ids[0], - data_ids[1], - data_ids[2], - "Note:", - ] + ] + data_ids body_string = " \n ".join(body_lis) payload_dict = { "title": f"NMDC Submission: {submission.id}", "body": body_string, - "assignees": ["mslarae13"], + "assignees": [assignee], } payload = json.dumps(payload_dict) @@ -840,7 +837,7 @@ def github_issue_to_project(issue_node_id: str, settings): # Same as github issue, if we're missing the settings then we return. if gh_project_token == None or gh_project_id == None: - logging.error("Posting issue to projec board failed. Missing token or id. See config") + logging.error("Posting issue to project board failed. Missing token or id. See config") return # All project API requests go through the same end point. diff --git a/nmdc_server/config.py b/nmdc_server/config.py index a8522b99..248fb211 100644 --- a/nmdc_server/config.py +++ b/nmdc_server/config.py @@ -70,6 +70,7 @@ class Settings(BaseSettings): # Github Issue creation settings. Both are required for automated issue creation. github_issue_url: Optional[str] = None github_authentication_token: Optional[str] = None + github_issue_assignee: Optional[str] = None # Github Issue to Project board settings. Both are required to post issue to project. gh_project_token: Optional[str] = None From 92f4648287b81c99d898be08f91953ab6cd449f9 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Tue, 7 May 2024 15:14:15 -0700 Subject: [PATCH 31/33] standardize github variable names --- nmdc_server/api.py | 4 ++-- nmdc_server/config.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 429ec498..21af1afc 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -832,8 +832,8 @@ def create_github_issue(submission, user): def github_issue_to_project(issue_node_id: str, settings): - gh_project_token = settings.gh_project_token - gh_project_id = settings.gh_project_id + github_project_token = settings.gh_project_token + github_project_id = settings.gh_project_id # Same as github issue, if we're missing the settings then we return. if gh_project_token == None or gh_project_id == None: diff --git a/nmdc_server/config.py b/nmdc_server/config.py index 248fb211..21ea7b88 100644 --- a/nmdc_server/config.py +++ b/nmdc_server/config.py @@ -73,8 +73,8 @@ class Settings(BaseSettings): github_issue_assignee: Optional[str] = None # Github Issue to Project board settings. Both are required to post issue to project. - gh_project_token: Optional[str] = None - gh_project_id: Optional[str] = None + github_project_token: Optional[str] = None + github_project_id: Optional[str] = None @property def current_db_uri(self) -> str: From 1464cd7b4b9b1f2a2d0ed4b45e9d7a5f1251ae00 Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Tue, 7 May 2024 15:54:28 -0700 Subject: [PATCH 32/33] small fix after testing, everything functions now --- nmdc_server/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index 21af1afc..a429865a 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -832,8 +832,8 @@ def create_github_issue(submission, user): def github_issue_to_project(issue_node_id: str, settings): - github_project_token = settings.gh_project_token - github_project_id = settings.gh_project_id + gh_project_token = settings.github_project_token + gh_project_id = settings.github_project_id # Same as github issue, if we're missing the settings then we return. if gh_project_token == None or gh_project_id == None: From 89af2d8167f7f45b368eb57fb4bdbaf754e1d27b Mon Sep 17 00:00:00 2001 From: James Tessmer Date: Wed, 8 May 2024 12:52:50 -0700 Subject: [PATCH 33/33] Remove references to posting GH issue to project --- nmdc_server/api.py | 34 ---------------------------------- nmdc_server/config.py | 4 ---- 2 files changed, 38 deletions(-) diff --git a/nmdc_server/api.py b/nmdc_server/api.py index a429865a..525a7a61 100644 --- a/nmdc_server/api.py +++ b/nmdc_server/api.py @@ -823,44 +823,10 @@ def create_github_issue(submission, user): else: logging.info(f"Github issue creation successful with code {res.status_code}") logging.info(res.reason) - # if issue creation is successful we want to put the issue on a project board - # if details for that are supplied - issue_node_id = res.json()["node_id"] - github_issue_to_project(issue_node_id, settings) return res -def github_issue_to_project(issue_node_id: str, settings): - gh_project_token = settings.github_project_token - gh_project_id = settings.github_project_id - - # Same as github issue, if we're missing the settings then we return. - if gh_project_token == None or gh_project_id == None: - logging.error("Posting issue to project board failed. Missing token or id. See config") - return - - # All project API requests go through the same end point. - # so all we specify is the project ID that we want to post to - # and the node id of the issue we want to post - board_headers = {"Authorization": f"Bearer {gh_project_token}"} - payload = { - "query": "mutation {addProjectV2ItemById(input: {projectId: " - + f'"{gh_project_id}" contentId: "{issue_node_id}"' - + "}) {item {id}}}" - } - res = requests.post(url="https://api.github.com/graphql", json=payload, headers=board_headers) - - # do some logging based on reply of request - if res.status_code != 200: - logging.error(f"Could not post issue to project. Failed with code {res.status_code}") - logging.error(res.reason) - else: - logging.info(f"Github issue post to project board successful with code {res.status_code}") - logging.info(res.reason) - return res - - @router.delete( "/metadata_submission/{id}", tags=["metadata_submission"], diff --git a/nmdc_server/config.py b/nmdc_server/config.py index 21ea7b88..43854f32 100644 --- a/nmdc_server/config.py +++ b/nmdc_server/config.py @@ -72,10 +72,6 @@ class Settings(BaseSettings): github_authentication_token: Optional[str] = None github_issue_assignee: Optional[str] = None - # Github Issue to Project board settings. Both are required to post issue to project. - github_project_token: Optional[str] = None - github_project_id: Optional[str] = None - @property def current_db_uri(self) -> str: if self.environment == "testing":