-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from github/discussions
Allow for measuring discussions
- Loading branch information
Showing
16 changed files
with
1,181 additions
and
569 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
GH_TOKEN = " " | ||
SEARCH_QUERY = "is:open is:issue" | ||
REPOSITORY_URL = "https://github.com/github/fetch" | ||
SEARCH_QUERY = "repo:owner/repo is:open is:issue" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""A module containing classes for representing GitHub issues and their metrics. | ||
Classes: | ||
IssueWithMetrics: A class to represent a GitHub issue with metrics. | ||
""" | ||
|
||
|
||
class IssueWithMetrics: | ||
"""A class to represent a GitHub issue with metrics. | ||
Attributes: | ||
title (str): The title of the issue. | ||
html_url (str): The URL of the issue on GitHub. | ||
time_to_first_response (timedelta, optional): The time it took to | ||
get the first response to the issue. | ||
time_to_close (timedelta, optional): The time it took to close the issue. | ||
time_to_answer (timedelta, optional): The time it took to answer the | ||
discussions in the issue. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
title, | ||
html_url, | ||
time_to_first_response=None, | ||
time_to_close=None, | ||
time_to_answer=None, | ||
): | ||
self.title = title | ||
self.html_url = html_url | ||
self.time_to_first_response = time_to_first_response | ||
self.time_to_close = time_to_close | ||
self.time_to_answer = time_to_answer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
This module provides functions for working with discussions in a GitHub repository. | ||
Functions: | ||
get_discussions(repo_url: str, token: str, search_query: str) -> List[Dict]: | ||
Get a list of discussions in a GitHub repository that match the search query. | ||
""" | ||
import requests | ||
|
||
|
||
def get_discussions(token: str, search_query: str): | ||
"""Get a list of discussions in a GitHub repository that match the search query. | ||
Args: | ||
token (str): A personal access token for GitHub. | ||
search_query (str): The search query to filter discussions by. | ||
Returns: | ||
list: A list of discussions in the repository that match the search query. | ||
""" | ||
# Construct the GraphQL query | ||
query = """ | ||
query($query: String!) { | ||
search(query: $query, type: DISCUSSION, first: 100) { | ||
edges { | ||
node { | ||
... on Discussion { | ||
title | ||
url | ||
createdAt | ||
comments(first: 1) { | ||
nodes { | ||
createdAt | ||
} | ||
} | ||
answerChosenAt | ||
closedAt | ||
} | ||
} | ||
} | ||
} | ||
} | ||
""" | ||
|
||
# Remove the type:discussions filter from the search query | ||
search_query = search_query.replace("type:discussions ", "") | ||
# Set the variables for the GraphQL query | ||
variables = {"query": search_query} | ||
|
||
# Send the GraphQL request | ||
headers = {"Authorization": f"Bearer {token}"} | ||
response = requests.post( | ||
"https://api.github.com/graphql", | ||
json={"query": query, "variables": variables}, | ||
headers=headers, | ||
timeout=60, | ||
) | ||
|
||
# Check for errors in the GraphQL response | ||
if response.status_code != 200 or "errors" in response.json(): | ||
raise ValueError("GraphQL query failed") | ||
|
||
data = response.json()["data"] | ||
|
||
# Extract the discussions from the GraphQL response | ||
discussions = [] | ||
for edge in data["search"]["edges"]: | ||
discussions.append(edge["node"]) | ||
|
||
return discussions |
Oops, something went wrong.