-
Notifications
You must be signed in to change notification settings - Fork 25
Refactor issue parser - lifecycle methods, use pydantic models, support reviewer lists #174
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
Changes from 12 commits
a41e251
268e940
00ad27e
63e9da1
4978019
253ec42
0152cee
fbfc13c
df5939a
2ca1a3f
eeffee1
7bd506d
cfdcad3
9594f19
8d5eb57
8ff2ac3
e59f603
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,8 @@ dev = [ | |
| "flake8", | ||
| "pre-commit", | ||
| "pytest", | ||
| "pytest-cov" | ||
| "pytest-cov", | ||
| "pytest-mock" | ||
| ] | ||
|
|
||
| [project.urls] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from pyosmeta.models.base import ( | ||
| GhMeta, | ||
| PersonModel, | ||
| ReviewModel, | ||
| ReviewUser, | ||
| UrlValidatorMixin, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "UrlValidatorMixin", | ||
| "PersonModel", | ||
| "GhMeta", | ||
| "ReviewModel", | ||
| "ReviewUser", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,8 @@ | |
| """ | ||
|
|
||
| import re | ||
| from typing import Optional, Set, Union | ||
| from datetime import datetime | ||
| from typing import Any, Optional, Set, Union | ||
|
|
||
| import requests | ||
| from pydantic import ( | ||
|
|
@@ -202,6 +203,21 @@ def clean_date(cls, a_date: Optional[str]) -> str: | |
| return clean_date(a_date) | ||
|
|
||
|
|
||
| class ReviewUser(BaseModel): | ||
| """Minimal model of a github user, used in several places in review parsing""" | ||
|
|
||
| name: str | ||
| github_username: str | ||
|
|
||
| @field_validator("github_username", mode="after") | ||
| def deurl_github_username(cls, github_username: str) -> str: | ||
| return github_username.replace("https://github.com/", "") | ||
|
|
||
| @field_validator("name", mode="after") | ||
| def demarkdown_name(cls, name: str) -> str: | ||
| return re.sub(r"\[|\]", "", name) | ||
|
|
||
|
|
||
| class ReviewModel(BaseModel): | ||
| # Make sure model populates both aliases and original attr name | ||
| model_config = ConfigDict( | ||
|
|
@@ -214,23 +230,22 @@ class ReviewModel(BaseModel): | |
| package_description: str = Field( | ||
| "", validation_alias=AliasChoices("one-line_description_of_package") | ||
| ) | ||
| submitting_author: dict[str, str | None] = {} | ||
| all_current_maintainers: list[dict[str, str | None]] = {} | ||
| repository_link: str | None = None | ||
| submitting_author: ReviewUser | None = None | ||
| all_current_maintainers: list[ReviewUser] = Field(default_factory=list) | ||
| repository_link: str | ||
| version_submitted: Optional[str] = None | ||
| categories: Optional[list[str]] = None | ||
| editor: dict[str, str | None] = {} | ||
| reviewer_1: dict[str, str | None] = {} | ||
| reviewer_2: dict[str, str | None] = {} | ||
| editor: ReviewUser = {} | ||
|
||
| reviewers: list[ReviewUser] = Field(default_factory=list) | ||
| archive: str | None = None | ||
| version_accepted: str | None = None | ||
| date_accepted: str | None = Field( | ||
| default=None, | ||
| validation_alias=AliasChoices("Date accepted", "date_accepted"), | ||
| ) | ||
| created_at: str = None | ||
| updated_at: str = None | ||
| closed_at: Optional[str] = None | ||
| created_at: datetime = None | ||
| updated_at: datetime = None | ||
| closed_at: Optional[datetime] = None | ||
| issue_link: str = None | ||
| joss: Optional[str] = None | ||
| partners: Optional[list[str]] = None | ||
|
|
@@ -255,22 +270,6 @@ def clean_date_review(cls, a_date: Optional[str]) -> str: | |
| else: | ||
| return f"{new_date[2]}-{new_date[0]}-{new_date[1]}" | ||
|
|
||
| @field_validator( | ||
| "created_at", | ||
| "updated_at", | ||
| "closed_at", | ||
| mode="before", | ||
| ) | ||
| @classmethod | ||
| def clean_date(cls, a_date: Optional[str]) -> str: | ||
| """Cleans up a datetime from github and returns a date string | ||
|
|
||
| Runs the general clean_date function in this module as a validator. | ||
|
|
||
| """ | ||
|
|
||
| return clean_date(a_date) | ||
|
|
||
| @field_validator( | ||
| "package_name", | ||
| mode="before", | ||
|
|
@@ -310,33 +309,12 @@ def clean_markdown_url(cls, repo: str) -> str: | |
| else: | ||
| return repo | ||
|
|
||
| @field_validator( | ||
| "editor", | ||
| "reviewer_1", | ||
| "reviewer_2", | ||
| mode="before", | ||
| ) | ||
| @classmethod | ||
| def clean_gh_url(cls, user: dict[str, str]) -> dict[str, str]: | ||
| """Remove markdown link remnants from gh usernames and name. | ||
|
|
||
| Sometimes editors and reviewers add names using github links. | ||
| Remove the link data. | ||
| """ | ||
|
|
||
| user["github_username"] = user["github_username"].replace( | ||
| "https://github.com/", "" | ||
| ) | ||
| user["name"] = re.sub(r"\[|\]", "", user["name"]) | ||
|
|
||
| return user | ||
|
|
||
| @field_validator( | ||
| "categories", | ||
| mode="before", | ||
| ) | ||
| @classmethod | ||
| def clean_categories(cls, categories: list[str]) -> list[str]: | ||
| def clean_categories(cls, categories: list[str]) -> list[str] | None: | ||
| """Make sure each category in the list is a valid value. | ||
|
|
||
| Valid pyos software categories are: | ||
|
|
@@ -358,6 +336,8 @@ def clean_categories(cls, categories: list[str]) -> list[str]: | |
| list[str] | ||
| List of cleaned categories. | ||
| """ | ||
| if categories is None: | ||
| return None | ||
|
|
||
| valid_categories = { | ||
| "data-processing": "data-processing-munging", | ||
|
|
@@ -375,3 +355,12 @@ def clean_categories(cls, categories: list[str]) -> list[str]: | |
| # No match found, keep the original category | ||
| cleaned_cats.append(category) | ||
| return cleaned_cats | ||
|
|
||
| @field_validator("all_current_maintainers", mode="before") | ||
| @classmethod | ||
| def listify(cls, item: Any): | ||
| """Make a field that's expected to be plural so before any validation""" | ||
| if not isinstance(item, list): | ||
| return [item] | ||
| else: | ||
| return item | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above - if you rebase from main (i am pretty sure_ i fiex this
labels=["6/pyOS-approved 🚀🚀🚀"]-->labels=["6/pyOS-approved"]
this is why we had a magical deleted file in our last pr 🙈 i removed the emojis.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merged in main, got the new label!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!! now we are no longer deleting all of the packages ✨ 😆