Skip to content

Commit 2996a34

Browse files
committed
Fix: fix label parsing
1 parent 9f709f3 commit 2996a34

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## [Unreleased]
66

7+
* Fix: allow for issues with multiple labels & fix presubmission ingest (@lwasser)
8+
79
## [v0.3.2] - 2024-07-04
810

911
### Fixes

src/pyosmeta/github_api.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,34 @@ def get_token(self) -> str | None:
7373
)
7474

7575
@property
76-
def api_endpoint(self):
77-
labels_query = ",".join(self.labels) if self.labels else ""
78-
url = (
79-
f"https://api.github.com/repos/{self.org}/{self.repo}/"
80-
f"issues?labels={labels_query}&state=all&per_page=100"
81-
)
76+
def api_endpoint(self) -> str:
77+
"""Create the API endpoint url
78+
79+
Returns
80+
-------
81+
str
82+
A string representing the api endpoint to query.
83+
84+
Notes
85+
-----
86+
The rest API will look for issues that have ALL labels provided in a
87+
query (using an AND query vs an OR query by default). The graphQL may
88+
support OR. As such if there is a list provided, we will want to parse
89+
down the returned list to only include issues with a specific label
90+
included.
91+
"""
92+
# If there is more than one label provided, request all issues
93+
# Will have to parse later.
94+
if len(self.labels) > 1:
95+
url = (
96+
f"https://api.github.com/repos/{self.org}/{self.repo}/"
97+
f"issues?state=all&per_page=100"
98+
)
99+
else:
100+
url = (
101+
f"https://api.github.com/repos/{self.org}/{self.repo}/"
102+
f"issues?labels={self.labels[0]}&state=all&per_page=100"
103+
)
82104
return url
83105

84106
def handle_rate_limit(self, response):

src/pyosmeta/models/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ class ReviewModel(BaseModel):
243243
)
244244
submitting_author: ReviewUser | None = None
245245
all_current_maintainers: list[ReviewUser] = Field(default_factory=list)
246-
repository_link: str
246+
# Support presubmissions with an alias
247+
repository_link: str = Field(..., alias="repository_link_(if_existing)")
247248
version_submitted: Optional[str] = None
248249
categories: Optional[list[str]] = None
249250
editor: ReviewUser | None = None

src/pyosmeta/parse_issues.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,25 @@ def get_issues(self) -> list[Issue]:
6767
-------
6868
list
6969
List of dict items each containing a review issue
70+
71+
Notes
72+
-----
73+
We add a filter here to labels because the github api defaults to
74+
grabbing issues with ALL using an and operator labels in a list. We
75+
need to use an OR as a selector.
7076
"""
7177

7278
issues = self.github_api.return_response()
73-
return [Issue(**i) for i in issues]
79+
# Filter labels according to label select input
80+
labels = self.github_api.labels
81+
82+
filtered_issues = [
83+
issue
84+
for issue in issues
85+
if any(label["name"] in labels for label in issue["labels"])
86+
]
87+
88+
return [Issue(**i) for i in filtered_issues]
7489

7590
def _is_review_role(self, string: str) -> bool:
7691
"""

0 commit comments

Comments
 (0)