Skip to content

Commit 028308f

Browse files
committed
feat(github): add user activity query method using GitHub GraphQL API
1 parent f478c43 commit 028308f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/mcp_github/github_integration.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,3 +665,28 @@ def create_release(self, repo_owner: str, repo_name: str, tag_name: str, release
665665
logging.error(f"Error creating release: {str(e)}")
666666
traceback.print_exc()
667667
return {"status": "error", "message": str(e)}
668+
669+
def user_activity_query(self, variables: dict[str, Any], query: str) -> Dict[str, Any]:
670+
"""
671+
Performs a user activity query using GitHub's GraphQL API across all repositories and organisations.
672+
Args:
673+
variables (dict[str, Any]): The variables to include in the query i.e. {"login": "username", "from": "2023-01-01", "to": "2023-12-31"}.
674+
query (str): The search query string. GitHub GraphQL query summary collection that includes all activity across all orgs, public and private.
675+
Returns:
676+
Dict[str, Any]: The JSON response from the GitHub API containing search results if successful.
677+
"""
678+
logging.info("Performing user query on GitHub")
679+
680+
try:
681+
response = requests.post('https://api.github.com/graphql', json={'query': query, 'variables': variables}, headers=self._get_headers(), timeout=TIMEOUT)
682+
response.raise_for_status()
683+
query_data = response.json()
684+
return query_data
685+
except requests.exceptions.RequestException as req_err:
686+
logging.error(f"Request error during user activity query: {str(req_err)}")
687+
traceback.print_exc()
688+
return {"status": "error", "message": str(req_err)}
689+
except Exception as e:
690+
logging.error(f"Error performing user activity query: {str(e)}")
691+
traceback.print_exc()
692+
return {"status": "error", "message": str(e)}

0 commit comments

Comments
 (0)