24_deb_pkg_gov/gh_gsql_req.py

77 lines
2.1 KiB
Python
Raw Normal View History

2023-10-26 15:57:56 +00:00
import requests
import datetime as dt
import json
import os
key = os.environ.get('KKEXKEY')
def main(vcs):
vcs_list = vcs[0].split('/')
repo_name = '"' + vcs_list[-1] + '"'
repo_owner = '"' + vcs_list[-2] + '"'
returned_content = get_discussion_gql(repo_owner, repo_name)
return returned_content
def get_discussion_gql(repo_owner, repo_name):
url = "https://api.github.com/graphql"
data_string = ("""
query {
repository(owner: """ + repo_owner + """, name: """ + repo_name + """) {
discussions(first: 3) {
# type: DiscussionConnection
totalCount # Int!
edges {
# type: DiscussionEdge
cursor
node {
# type: Discussion
id
title # String!
bodyText # String!
createdViaEmail # Boolean!
createdAt # DateTime!
answer {
#type: DiscussionComment
bodyText # String!
}
comments(first: 10){
# type: DiscussionCommentConnection
totalCount # Int!
edges {
# type: DiscussionCommentEdge
node {
# type: DiscussionComment
id
bodyText # String!
}
}
}
}
}
}
}
}
""")
data = {"query" : data_string}
data_json = json.dumps(data)
headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'Authorization': 'bearer ' + key}
r = requests.post(url=url, data=data_json, headers=headers)
print(r.content)
return r
if __name__ == "__main__":
get_discussion_gql()
# stashed info about page cursors
''' pageInfo {
# type: PageInfo (from the public schema)
startCursor
endCursor
hasNextPage
hasPreviousPage
}
'''