Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Replace github library with graphql (#33)
Browse files Browse the repository at this point in the history
* Replace github library with graphql

Signed-off-by: Anna Jung (VMware) <[email protected]>

* Add support for rate limit and other known external responses

Signed-off-by: Anna Jung (VMware) <[email protected]>
  • Loading branch information
Anna authored Feb 22, 2022
1 parent 41779a7 commit b134e8c
Show file tree
Hide file tree
Showing 14 changed files with 1,112 additions and 125 deletions.
3 changes: 3 additions & 0 deletions mcat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright 2021 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

299 changes: 180 additions & 119 deletions mcat/githubDataExtraction.py

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions mcat/queries/pull_requests_with_reactions.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2021 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

query PullRequests($owner: String!, $repo: String!, $cursor: String) {
repository(owner: $owner, name: $repo) {
name
pullRequests(first: 100, after: $cursor) {
nodes {
number
title
author {
login
}
url
state
body
additions
deletions
comments(first: 100) {
totalCount
nodes {
author {
login
}
createdAt
body
updatedAt
reactions(first: 100) {
nodes {
content
createdAt
user {
login
}
}
}
}
}
commits {
totalCount
}
createdAt
closedAt
merged
mergedAt
mergedBy {
login
}
reviews(first: 100) {
totalCount
nodes {
author {
login
}
createdAt
body
updatedAt
}
}
updatedAt
}
pageInfo {
endCursor
hasNextPage
}
}
}
}

60 changes: 60 additions & 0 deletions mcat/queries/pull_requests_without_reactions.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2021 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

query PullRequests($owner: String!, $repo: String!, $cursor: String) {
repository(owner: $owner, name: $repo) {
name
pullRequests(first: 100, after: $cursor) {
nodes {
number
title
author {
login
}
url
state
body
additions
deletions
comments(first: 100) {
totalCount
nodes {
author {
login
}
createdAt
body
updatedAt
}
}
commits {
totalCount
}
createdAt
closedAt
merged
mergedAt
mergedBy {
login
}
reviews(first: 100) {
totalCount
nodes {
author {
login
}
createdAt
body
updatedAt
}
}
updatedAt
}
pageInfo {
endCursor
hasNextPage
}
}
}
}

17 changes: 17 additions & 0 deletions mcat/queries/repos.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2021 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

query ($owner: String!, $cursor: String) {
organization(login: $owner) {
repositories(first: 100, after: $cursor) {
nodes {
name
}
pageInfo {
endCursor
hasNextPage
}
}
}
}

6 changes: 2 additions & 4 deletions mcat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,5 @@ def construct_file_name(name, component_a, component_b, separator="_"):

def string_to_dict(string):
"""Function to convert json strings to dictionary"""
string = ast.literal_eval(string)
for i in range(len(string)):
string[i] = ast.literal_eval(string[i])
return string
return ast.literal_eval(string)

1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
requests>=2.26.0
pandas>=1.3.2
PyGithub>=1.55
argparse>=1.4.0
numpy>=1.19.5
nltk>=3.6.2
Expand Down
3 changes: 3 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright 2021 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0

49 changes: 49 additions & 0 deletions tests/resources/pr_post_processing_with_reactions_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"Number": 1,
"Title": "test-title",
"User": "test-author-login",
"URL": "test-url",
"State": "MERGED",
"Body": "test-body",
"Additions": 2,
"Deletions": 3,
"Comments_Num": 1,
"Commits_Num": 1,
"Created_At": "2000-01-01T01:01:01Z",
"Closed_At": "2000-01-01T01:01:01Z",
"Merged": "True",
"Merged_At": "2000-01-01T01:01:01Z",
"Merged_By": "test-merged-by",
"Review_Comments_Num": 4,
"Updated_At": "2000-01-01T01:01:01Z",
"Comments": [
{
"Created_At": "2000-01-01T01:01:01Z",
"User": "test-comment-user",
"Body": "test-comment",
"Updated_At": "2000-01-01T01:01:01Z",
"Reactions": [
{
"Content": "test-content",
"Created_At": "2000-01-01T01:01:01Z",
"User": "test-reaction-user"
}
]
}
],
"Review_Comments": [
{
"Created_At": "2000-01-01T01:01:01Z",
"User": "test-review-user",
"Body": "test-body",
"Updated_At": "2000-01-01T01:01:01Z",
"Reactions": [
{
"Content": "test-content",
"Created_At": "2000-01-01T01:01:01Z",
"User": "test-reaction-user"
}
]
}
]
}
35 changes: 35 additions & 0 deletions tests/resources/pr_post_processing_without_reactions_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"Number": 1,
"Title": "test-title",
"User": "test-author-login",
"URL": "test-url",
"State": "MERGED",
"Body": "test-body",
"Additions": 2,
"Deletions": 3,
"Comments_Num": 1,
"Commits_Num": 1,
"Created_At": "2000-01-01T01:01:01Z",
"Closed_At": "2000-01-01T01:01:01Z",
"Merged": "True",
"Merged_At": "2000-01-01T01:01:01Z",
"Merged_By": "test-merged-by",
"Review_Comments_Num": 4,
"Updated_At": "2000-01-01T01:01:01Z",
"Comments": [
{
"Created_At": "2000-01-01T01:01:01Z",
"User": "test-comment-user",
"Body": "test-comment",
"Updated_At": "2000-01-01T01:01:01Z"
}
],
"Review_Comments": [
{
"Created_At": "2000-01-01T01:01:01Z",
"User": "test-review-user",
"Body": "test-body",
"Updated_At": "2000-01-01T01:01:01Z"
}
]
}
71 changes: 71 additions & 0 deletions tests/resources/pr_raw_data_example_one.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"number": 1,
"title": "test-title",
"author": {
"login": "test-author-login"
},
"url": "test-url",
"state": "MERGED",
"body": "test-body",
"additions": 2,
"deletions": 3,
"comments": {
"totalCount": 1,
"nodes": [
{
"author": {
"login": "test-comment-user"
},
"createdAt": "2000-01-01T01:01:01Z",
"body": "test-comment",
"updatedAt": "2000-01-01T01:01:01Z",
"reactions": {
"nodes": [
{
"content": "test-content",
"createdAt": "2000-01-01T01:01:01Z",
"user": {
"login": "test-reaction-user"
}
}
]
}
}
]
},
"commits": {
"totalCount": 1
},
"createdAt": "2000-01-01T01:01:01Z",
"closedAt": "2000-01-01T01:01:01Z",
"merged": "True",
"mergedAt": "2000-01-01T01:01:01Z",
"mergedBy": {
"login": "test-merged-by"
},
"reviews": {
"totalCount": 4,
"nodes": [
{
"author": {
"login": "test-review-user"
},
"createdAt": "2000-01-01T01:01:01Z",
"body": "test-body",
"updatedAt": "2000-01-01T01:01:01Z",
"reactions": {
"nodes": [
{
"content": "test-content",
"createdAt": "2000-01-01T01:01:01Z",
"user": {
"login": "test-reaction-user"
}
}
]
}
}
]
},
"updatedAt": "2000-01-01T01:01:01Z"
}
Loading

0 comments on commit b134e8c

Please sign in to comment.