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

get labels from issue metadata #189

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions src/pyosmeta/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
field_validator,
)

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


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

@field_validator(
"date_accepted",
Expand Down Expand Up @@ -368,3 +370,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 @@ -245,6 +245,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"]
Loading