2023-10-26 15:57:56 +00:00
|
|
|
import requests
|
|
|
|
import datetime as dt
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
|
|
|
|
key = os.environ.get('KKEXKEY')
|
|
|
|
|
2023-10-27 17:25:33 +00:00
|
|
|
def main(vcs, early_cutoff):
|
|
|
|
gsql_dict = {}
|
2023-10-26 15:57:56 +00:00
|
|
|
vcs_list = vcs[0].split('/')
|
|
|
|
repo_name = '"' + vcs_list[-1] + '"'
|
|
|
|
repo_owner = '"' + vcs_list[-2] + '"'
|
2023-10-27 17:25:33 +00:00
|
|
|
gsql_dict["original_returned_content"] = get_discussion_gql(repo_owner, repo_name)
|
2023-11-06 22:20:35 +00:00
|
|
|
gsql_dict["time_cleaned_comm"] = within_time(gsql_dict["original_returned_content"], early_cutoff)
|
2023-10-27 17:25:33 +00:00
|
|
|
return gsql_dict
|
2023-10-26 15:57:56 +00:00
|
|
|
|
|
|
|
def get_discussion_gql(repo_owner, repo_name):
|
|
|
|
url = "https://api.github.com/graphql"
|
|
|
|
data_string = ("""
|
|
|
|
query {
|
|
|
|
repository(owner: """ + repo_owner + """, name: """ + repo_name + """) {
|
2023-11-07 04:18:30 +00:00
|
|
|
issues(last: 2) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
id
|
|
|
|
title
|
|
|
|
url
|
|
|
|
number
|
|
|
|
state
|
|
|
|
author {
|
|
|
|
url
|
|
|
|
}
|
|
|
|
labels(first:5) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
comments(first: 10) {
|
|
|
|
# edges.node is where the actual `Comment` object is
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
author {
|
|
|
|
avatarUrl
|
|
|
|
}
|
|
|
|
body
|
|
|
|
}
|
|
|
|
}
|
2023-10-26 15:57:56 +00:00
|
|
|
}
|
2023-11-07 04:18:30 +00:00
|
|
|
body
|
2023-10-26 15:57:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
""")
|
|
|
|
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)
|
2023-11-07 04:18:30 +00:00
|
|
|
print(r.content)
|
2023-11-06 22:20:35 +00:00
|
|
|
return r.json()
|
2023-10-26 15:57:56 +00:00
|
|
|
|
2023-10-27 17:25:33 +00:00
|
|
|
def within_time(comment_content, early_cutoff):
|
2023-11-06 22:20:35 +00:00
|
|
|
try:
|
|
|
|
list_of_comments = json.loads(comment_content)["data"]["repository"]["discussions"]["edges"]
|
|
|
|
valid_comments = []
|
|
|
|
for comment in list_of_comments:
|
|
|
|
if dt.datetime.fromisoformat(comment['node']['createdAt'][:-1]) < early_cutoff:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
valid_comments.append(comment)
|
|
|
|
return valid_comments
|
|
|
|
except TypeError:
|
|
|
|
print("no discussions found")
|
|
|
|
return []
|
2023-10-27 17:25:33 +00:00
|
|
|
|
2023-10-26 15:57:56 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-11-07 04:18:30 +00:00
|
|
|
repo_name = '"' + 'numpy' + '"'
|
|
|
|
repo_owner = '"' + 'numpy' + '"'
|
|
|
|
get_discussion_gql(repo_owner, repo_name)
|
2023-10-26 15:57:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
# stashed info about page cursors
|
|
|
|
''' pageInfo {
|
|
|
|
# type: PageInfo (from the public schema)
|
|
|
|
startCursor
|
|
|
|
endCursor
|
|
|
|
hasNextPage
|
|
|
|
hasPreviousPage
|
|
|
|
}
|
2023-11-07 04:18:30 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
'''
|
|
|
|
issue(number: 2) {
|
|
|
|
title
|
|
|
|
createdAt
|
|
|
|
# first 10 results
|
|
|
|
comments(first: 10) {
|
|
|
|
# edges.node is where the actual `Comment` object is
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
author {
|
|
|
|
avatarUrl
|
|
|
|
}
|
|
|
|
body
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
'''
|
|
|
|
discussions(first: 10) {
|
|
|
|
# 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!
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-26 15:57:56 +00:00
|
|
|
'''
|