Skip to content

Commit

Permalink
get labels from issue metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakers-the-rat authored and lwasser committed Jul 12, 2024
1 parent 630eb20 commit 768256a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/pyosmeta/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
)

from pyosmeta.utils_clean import clean_date, clean_markdown
from pyosmeta.models.github import Labels


class Partnerships(str, Enum):
Expand Down Expand Up @@ -261,6 +262,7 @@ class ReviewModel(BaseModel):
joss: Optional[str] = None
partners: Optional[list[Partnerships]] = None
gh_meta: Optional[GhMeta] = None
labels: list[str] = Field(default_factory=list)

@field_validator(
"date_accepted",
Expand Down Expand Up @@ -375,3 +377,13 @@ def listify(cls, item: Any):
return [item]
else:
return item

@field_validator("labels", mode="before")
def extract_label(cls, labels: list[str | Labels]) -> list[str]:
"""
Get just the ``name`` from the Labels model, if given
"""
return [
label.name if isinstance(label, Labels) else label
for label in labels
]
1 change: 1 addition & 0 deletions src/pyosmeta/parse_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def parse_issue(self, issue: Issue | str) -> ReviewModel:
"updated_at",
"closed_at",
"repository_url",
"labels",
],
)

Expand Down
21 changes: 21 additions & 0 deletions tests/integration/test_parse_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from pyosmeta.models import ReviewUser
from pyosmeta.models.github import Labels


def test_parse_issue_header(process_issues, issue_list):
Expand Down Expand Up @@ -47,3 +48,23 @@ def test_parse_bolded_keys(process_issues, data_file):
review = data_file("reviews/bolded_keys.txt", True)
review = process_issues.parse_issue(review)
assert review.package_name == "fake_package"


def test_parse_labels(issue_list, process_issues):
"""
`Label` models should be coerced to a string when parsing an issue
"""
label_inst = Labels(
id=1196238794,
node_id="MDU6TGFiZWwxMTk2MjM4Nzk0",
url="https://api.github.com/repos/pyOpenSci/software-submission/labels/6/pyOS-approved",
name="6/pyOS-approved",
description="",
color="006B75",
default=False,
)
labels = [label_inst, "another_label"]
for issue in issue_list:
issue.labels = labels
review = process_issues.parse_issue(issue)
assert review.labels == ["6/pyOS-approved", "another_label"]

0 comments on commit 768256a

Please sign in to comment.