Skip to content

Commit 768256a

Browse files
sneakers-the-ratlwasser
authored andcommitted
get labels from issue metadata
1 parent 630eb20 commit 768256a

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/pyosmeta/models/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020

2121
from pyosmeta.utils_clean import clean_date, clean_markdown
22+
from pyosmeta.models.github import Labels
2223

2324

2425
class Partnerships(str, Enum):
@@ -261,6 +262,7 @@ class ReviewModel(BaseModel):
261262
joss: Optional[str] = None
262263
partners: Optional[list[Partnerships]] = None
263264
gh_meta: Optional[GhMeta] = None
265+
labels: list[str] = Field(default_factory=list)
264266

265267
@field_validator(
266268
"date_accepted",
@@ -375,3 +377,13 @@ def listify(cls, item: Any):
375377
return [item]
376378
else:
377379
return item
380+
381+
@field_validator("labels", mode="before")
382+
def extract_label(cls, labels: list[str | Labels]) -> list[str]:
383+
"""
384+
Get just the ``name`` from the Labels model, if given
385+
"""
386+
return [
387+
label.name if isinstance(label, Labels) else label
388+
for label in labels
389+
]

src/pyosmeta/parse_issues.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def parse_issue(self, issue: Issue | str) -> ReviewModel:
256256
"updated_at",
257257
"closed_at",
258258
"repository_url",
259+
"labels",
259260
],
260261
)
261262

tests/integration/test_parse_issues.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44
from pyosmeta.models import ReviewUser
5+
from pyosmeta.models.github import Labels
56

67

78
def test_parse_issue_header(process_issues, issue_list):
@@ -47,3 +48,23 @@ def test_parse_bolded_keys(process_issues, data_file):
4748
review = data_file("reviews/bolded_keys.txt", True)
4849
review = process_issues.parse_issue(review)
4950
assert review.package_name == "fake_package"
51+
52+
53+
def test_parse_labels(issue_list, process_issues):
54+
"""
55+
`Label` models should be coerced to a string when parsing an issue
56+
"""
57+
label_inst = Labels(
58+
id=1196238794,
59+
node_id="MDU6TGFiZWwxMTk2MjM4Nzk0",
60+
url="https://api.github.com/repos/pyOpenSci/software-submission/labels/6/pyOS-approved",
61+
name="6/pyOS-approved",
62+
description="",
63+
color="006B75",
64+
default=False,
65+
)
66+
labels = [label_inst, "another_label"]
67+
for issue in issue_list:
68+
issue.labels = labels
69+
review = process_issues.parse_issue(issue)
70+
assert review.labels == ["6/pyOS-approved", "another_label"]

0 commit comments

Comments
 (0)