Skip to content

Commit

Permalink
Fix: fix label parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lwasser committed Jul 13, 2024
1 parent 9f709f3 commit 2996a34
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
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]

* Fix: allow for issues with multiple labels & fix presubmission ingest (@lwasser)

## [v0.3.2] - 2024-07-04

### Fixes
Expand Down
34 changes: 28 additions & 6 deletions src/pyosmeta/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,34 @@ def get_token(self) -> str | None:
)

@property
def api_endpoint(self):
labels_query = ",".join(self.labels) if self.labels else ""
url = (
f"https://api.github.com/repos/{self.org}/{self.repo}/"
f"issues?labels={labels_query}&state=all&per_page=100"
)
def api_endpoint(self) -> str:
"""Create the API endpoint url
Returns
-------
str
A string representing the api endpoint to query.
Notes
-----
The rest API will look for issues that have ALL labels provided in a
query (using an AND query vs an OR query by default). The graphQL may
support OR. As such if there is a list provided, we will want to parse
down the returned list to only include issues with a specific label
included.
"""
# If there is more than one label provided, request all issues
# Will have to parse later.
if len(self.labels) > 1:
url = (
f"https://api.github.com/repos/{self.org}/{self.repo}/"
f"issues?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"
)
return url

def handle_rate_limit(self, response):
Expand Down
3 changes: 2 additions & 1 deletion src/pyosmeta/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ class ReviewModel(BaseModel):
)
submitting_author: ReviewUser | None = None
all_current_maintainers: list[ReviewUser] = Field(default_factory=list)
repository_link: str
# Support presubmissions with an alias
repository_link: str = Field(..., alias="repository_link_(if_existing)")
version_submitted: Optional[str] = None
categories: Optional[list[str]] = None
editor: ReviewUser | None = None
Expand Down
17 changes: 16 additions & 1 deletion src/pyosmeta/parse_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,25 @@ def get_issues(self) -> list[Issue]:
-------
list
List of dict items each containing a review issue
Notes
-----
We add a filter here to labels because the github api defaults to
grabbing issues with ALL using an and operator labels in a list. We
need to use an OR as a selector.
"""

issues = self.github_api.return_response()
return [Issue(**i) for i in issues]
# Filter labels according to label select input
labels = self.github_api.labels

filtered_issues = [
issue
for issue in issues
if any(label["name"] in labels for label in issue["labels"])
]

return [Issue(**i) for i in filtered_issues]

def _is_review_role(self, string: str) -> bool:
"""
Expand Down

0 comments on commit 2996a34

Please sign in to comment.