Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create github issue when user submits metadata #1208

Merged
merged 35 commits into from
May 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ebe1573
Add changes from branch
JamesTessmer Apr 10, 2024
6f97aef
add create_github_issue with basic functionality
Apr 9, 2024
c253f95
Add fields in config for github automation
Apr 13, 2024
36e918c
updated reference to token
Apr 18, 2024
d869544
remove logged_in cookie
Apr 18, 2024
7f73584
Remove debugging line
Apr 18, 2024
2b26566
Merge branch 'main' into automate-github-issues
Apr 18, 2024
fcc7efb
add fix for numsamples
Apr 18, 2024
90d3bd1
remove cookies ref in requests
Apr 18, 2024
c9ce2d8
Add logging capability
Apr 19, 2024
d529ddd
add response text error logging
Apr 19, 2024
0628ac2
update response.test to response.reason
Apr 19, 2024
a02dbc6
Add json dump and readability
Apr 19, 2024
0f4b94e
Some formatting to make markdown look nicer
Apr 19, 2024
0734a29
Fixed linting and formatting errors.
Apr 19, 2024
c1c680b
remove return statement used for tests
Apr 19, 2024
66721ba
Repositioning imports for lint
Apr 19, 2024
14dfcb3
reordered imports to the actual correct positions
Apr 19, 2024
fcffd0b
added typing to github url
Apr 19, 2024
02a77dd
Add github issue to project board function
May 2, 2024
f6fc626
small bug fixes with posting to project board
May 3, 2024
bae9a28
Fixed some spacing and added comments
May 3, 2024
71bab83
add logic to supply fields for issue if there is/is not data
May 3, 2024
562427a
remove testing line
May 3, 2024
673c151
remove other testing lines
May 3, 2024
e2d9908
Fixed formatting issues
May 3, 2024
7eae4bc
remove label tag in issue creation
May 3, 2024
d522925
fixed lint issues
May 3, 2024
f3c521f
removed trailing white space
May 3, 2024
af4c982
fixed black formatting error
May 3, 2024
40bf241
Implement PR suggestions
May 7, 2024
92f4648
standardize github variable names
May 7, 2024
6a32b5f
Merge branch 'main' into automate-github-issues
May 7, 2024
1464cd7
small fix after testing, everything functions now
May 7, 2024
89af2d8
Remove references to posting GH issue to project
May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion nmdc_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
)
from nmdc_server.pagination import Pagination

import requests

router = APIRouter()


Expand Down Expand Up @@ -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
JamesTessmer marked this conversation as resolved.
Show resolved Hide resolved
# Merge the submission metadata dicts
submission.metadata_submission = (
submission.metadata_submission | body_dict["metadata_submission"]
Expand All @@ -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"
JamesTessmer marked this conversation as resolved.
Show resolved Hide resolved

cookies = {'logged_in':'no'}
JamesTessmer marked this conversation as resolved.
Show resolved Hide resolved

headers = {'Authorization':'Bearer TOKEN',
'Content-Type': 'text/plain; charset=utf-8'}
print(submission.metadata_submission)
JamesTessmer marked this conversation as resolved.
Show resolved Hide resolved
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])
JamesTessmer marked this conversation as resolved.
Show resolved Hide resolved

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"]'+'}'
JamesTessmer marked this conversation as resolved.
Show resolved Hide resolved

res = requests.post(url,cookies=cookies,data=payload,headers=headers)
JamesTessmer marked this conversation as resolved.
Show resolved Hide resolved
return res


@router.delete(
"/metadata_submission/{id}",
Expand Down
Loading