Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for issues ++ prs ✨ in pyosmeta #211

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## [Unreleased]

* Add: Endpoint variable to support both prs and issues to GitHubAPI (@lwasser)

## [v0.3.4] - 2024-08-01

### Fixes
Expand Down
32 changes: 23 additions & 9 deletions src/pyosmeta/github_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
A module that houses all of the methods related to interfacing
with the GitHub API. THere are three groupings of activities here:
A module that contains all of the methods related to interfacing
with the GitHub API. There are three groupings of activities:

1. Parsing github issues to return peer review information
1. Parsing GitHub issues to return pyOS software peer review information
2. Parsing contributor profile data to return names and affiliations where
available
3. Parsing package repositories to return package metadata such as pull request
Expand All @@ -28,9 +28,10 @@ class GitHubAPI:

def __init__(
self,
org: str | None = None,
org: str | None = "pyopensci",
repo: str | None = None,
labels: list[str] | None = None,
endpoint_type: str = "issues",
):
"""
Initialize a GitHub client object that handles interfacing with the
Expand All @@ -43,12 +44,16 @@ def __init__(
repo : str, Optional
Repo name where the software review issues live
labels : list of strings, Optional
Labels for issues that we want to access - e.g. pyos approved
Labels for issues that we want to access - e.g. pyOS approved
endpoint_type : str
The end point type to hit (pull request -- pulls or issues).
Default is "issues".
"""

self.org: str | None = org
self.repo: str | None = repo
self.labels: list[str] | None = labels
self.endpoint_type: str = endpoint_type

def get_token(self) -> str | None:
"""Fetches the GitHub API key from the users environment. If running
Expand Down Expand Up @@ -89,17 +94,26 @@ def api_endpoint(self) -> str:
down the returned list to only include issues with a specific label
included.
"""

endpoint = self.endpoint_type
# If there is more than one label provided, request all issues
# Will have to parse later.
if len(self.labels) > 1:
# TODO: this will cause a problem with reviews if there is a presubmission
# and a submission with the same package name
lwasser marked this conversation as resolved.
Show resolved Hide resolved
# If there are no labels provided, query all
if not self.labels:
url = (
f"https://api.github.com/repos/{self.org}/{self.repo}/"
f"{endpoint}?state=all&per_page=100"
)
elif len(self.labels) > 1:
url = (
f"https://api.github.com/repos/{self.org}/{self.repo}/"
f"issues?state=all&per_page=100"
f"{endpoint}?state=all&per_page=100"
)
else:
url = (
f"https://api.github.com/repos/{self.org}/{self.repo}/"
f"issues?labels={self.labels[0]}&state=all&per_page=100"
f"{endpoint}?labels={self.labels[0]}&state=all&per_page=100"
)
return url

Expand Down
63 changes: 56 additions & 7 deletions tests/unit/test_github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,62 @@ def test_missing_token(mock_missing_github_token, tmpdir):
github_api.get_token()


def test_api_endpoint(github_api):
"""Test that the generated api url created in the property is valid"""
expected_endpoint = [
"https://api.github.com/repos/pyopensci/pyosmeta/issues?labels=label1,label2&state=all&per_page=100",
"https://api.github.com/repos/pyopensci/pyosmeta/issues?state=all&per_page=100",
]
assert github_api.api_endpoint in expected_endpoint
@pytest.mark.parametrize(
"org, repo, endpoint_type, labels, expected_url",
[
(
"pyopensci",
"pyosmeta",
"issues",
[],
"https://api.github.com/repos/pyopensci/pyosmeta/issues?state=all&per_page=100",
),
(
"pyopensci",
"pyosmeta",
"issues",
["label1"],
"https://api.github.com/repos/pyopensci/pyosmeta/issues?labels=label1&state=all&per_page=100",
),
(
"pyopensci",
"pyosmeta",
"issues",
["label1", "label2"],
"https://api.github.com/repos/pyopensci/pyosmeta/issues?state=all&per_page=100",
),
(
"pyopensci",
"pyosmeta",
"pulls",
[],
"https://api.github.com/repos/pyopensci/pyosmeta/pulls?state=all&per_page=100",
),
(
"pyopensci",
"pyosmeta",
"pulls",
["label1"],
"https://api.github.com/repos/pyopensci/pyosmeta/pulls?labels=label1&state=all&per_page=100",
),
(
"pyopensci",
"pyosmeta",
"pulls",
["label1", "label2"],
"https://api.github.com/repos/pyopensci/pyosmeta/pulls?state=all&per_page=100",
),
],
)
def test_api_endpoint(org, repo, endpoint_type, labels, expected_url):
"""Test that the generated API URL created in the property is valid."""
github_api = GitHubAPI()
github_api.org = org
github_api.repo = repo
github_api.endpoint_type = endpoint_type
github_api.labels = labels

assert github_api.api_endpoint == expected_url


def test_get_user_info_successful(mocker, ghuser_response):
Expand Down