Skip to content

Commit 6206754

Browse files
committed
feat: add archive label and active status to ReviewModel
1 parent b6179f3 commit 6206754

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

src/pyosmeta/models/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ class ReviewModel(BaseModel):
279279
partners: Optional[list[Partnerships]] = None
280280
gh_meta: Optional[GhMeta] = None
281281
labels: list[str] = Field(default_factory=list)
282+
active: bool = True # To indicate if package is maintained or archived
282283

283284
@field_validator(
284285
"date_accepted",

src/pyosmeta/models/github.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
from __future__ import annotations
1818

1919
from datetime import datetime
20+
from enum import Enum
2021
from typing import Any, List, Literal, Optional, Union
2122

22-
from pydantic import AnyUrl, BaseModel, ConfigDict, Field
23+
from pydantic import AnyUrl, BaseModel, ConfigDict, Field, model_validator
2324

2425

2526
class User(BaseModel):
@@ -61,6 +62,12 @@ class ClosedBy(User): ...
6162
class Owner(User): ...
6263

6364

65+
class LabelType(str, Enum):
66+
ARCHIVED = "archived"
67+
PYOS_APPROVED = "6/pyOS-approved"
68+
JOSS_APPROVED = "9/joss-approved"
69+
70+
6471
class Labels(BaseModel):
6572
id: Optional[int] = None
6673
node_id: Optional[str] = None
@@ -69,6 +76,17 @@ class Labels(BaseModel):
6976
description: Optional[str] = None
7077
color: Optional[str] = None
7178
default: Optional[bool] = None
79+
type: Optional[LabelType] = None
80+
81+
@model_validator(mode="before")
82+
def parse_label_type(cls, data):
83+
"""Parse the label type from the name before validation."""
84+
if "name" in data:
85+
try:
86+
data["type"] = LabelType(data["name"])
87+
except ValueError:
88+
pass
89+
return data
7290

7391

7492
class Issue(BaseModel):

src/pyosmeta/parse_issues.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pydantic import ValidationError
88

99
from pyosmeta.models import ReviewModel, ReviewUser
10-
from pyosmeta.models.github import Issue
10+
from pyosmeta.models.github import Issue, Labels, LabelType
1111

1212
from .github_api import GitHubAPI
1313
from .utils_clean import clean_date_accepted_key
@@ -221,6 +221,25 @@ def _postprocess_meta(self, meta: dict, body: List[str]) -> dict:
221221

222222
return meta
223223

224+
def _postprocess_labels(self, meta: dict) -> dict:
225+
"""
226+
Handle specific labels that are model properties
227+
"""
228+
229+
def _is_archived(label: str) -> bool:
230+
if isinstance(label, str):
231+
return "archived" in label.lower()
232+
elif isinstance(label, Labels):
233+
return label.type == LabelType.ARCHIVED
234+
raise ValueError("Invalid label type")
235+
236+
# Check if the review has the "archived" label
237+
if "labels" in meta and [
238+
label for label in meta["labels"] if _is_archived(label)
239+
]:
240+
meta["active"] = False
241+
return meta
242+
224243
def _parse_field(self, key: str, val: str) -> Any:
225244
"""
226245
Method dispatcher for parsing specific header fields.
@@ -277,6 +296,7 @@ def parse_issue(self, issue: Issue | str) -> ReviewModel:
277296

278297
# Finalize review model before casting
279298
model = self._postprocess_meta(model, body)
299+
model = self._postprocess_labels(model)
280300

281301
return ReviewModel(**model)
282302

tests/integration/test_parse_issues.py

+17
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,20 @@ def test_parse_labels(issue_list, process_issues):
6969
issue.labels = labels
7070
review = process_issues.parse_issue(issue)
7171
assert review.labels == ["6/pyOS-approved", "another_label"]
72+
assert review.active
73+
74+
# Now add an archive label
75+
label_inst = Labels(
76+
id=1196238794,
77+
node_id="MDU6TGFiZWwxMTk2MjM4Nzk0",
78+
url="https://api.github.com/repos/pyOpenSci/software-submission/labels/archived",
79+
name="archived",
80+
description="",
81+
color="006B75",
82+
default=False,
83+
)
84+
labels = [label_inst, "another_label"]
85+
for issue in issue_list:
86+
issue.labels = labels
87+
review = process_issues.parse_issue(issue)
88+
assert not review.active

0 commit comments

Comments
 (0)