|
| 1 | +from pydantic import BaseModel |
| 2 | + |
| 3 | +from codegen.git.models.github_named_user_context import GithubNamedUserContext |
| 4 | +from codegen.git.models.pr_part_context import PRPartContext |
| 5 | +from codegen.git.schemas.github import GithubType |
| 6 | + |
| 7 | + |
| 8 | +class PullRequestContext(BaseModel): |
| 9 | + """Represents a GitHub pull request""" |
| 10 | + |
| 11 | + id: int |
| 12 | + url: str |
| 13 | + html_url: str |
| 14 | + number: int |
| 15 | + state: str |
| 16 | + title: str |
| 17 | + user: GithubNamedUserContext |
| 18 | + body: str |
| 19 | + draft: bool |
| 20 | + head: PRPartContext |
| 21 | + base: PRPartContext |
| 22 | + merged: bool | None |
| 23 | + merged_by: dict | None |
| 24 | + additions: int | None |
| 25 | + deletions: int | None |
| 26 | + changed_files: int | None |
| 27 | + github_type: GithubType | None = None |
| 28 | + webhook_data: dict | None = None |
| 29 | + |
| 30 | + @classmethod |
| 31 | + def from_payload(cls, webhook_payload: dict) -> "PullRequestContext": |
| 32 | + webhook_data = webhook_payload.get("pull_request", {}) |
| 33 | + return cls( |
| 34 | + id=webhook_data.get("id"), |
| 35 | + url=webhook_data.get("url"), |
| 36 | + html_url=webhook_data.get("html_url"), |
| 37 | + number=webhook_data.get("number"), |
| 38 | + state=webhook_data.get("state"), |
| 39 | + title=webhook_data.get("title"), |
| 40 | + user=GithubNamedUserContext.from_payload(webhook_data.get("user", {})), |
| 41 | + body=webhook_data.get("body"), |
| 42 | + draft=webhook_data.get("draft"), |
| 43 | + head=PRPartContext.from_payload(webhook_data.get("head", {})), |
| 44 | + base=PRPartContext.from_payload(webhook_data.get("base", {})), |
| 45 | + merged=webhook_data.get("merged"), |
| 46 | + merged_by=webhook_data.get("merged_by", {}), |
| 47 | + additions=webhook_data.get("additions"), |
| 48 | + deletions=webhook_data.get("deletions"), |
| 49 | + changed_files=webhook_data.get("changed_files"), |
| 50 | + github_type=GithubType.from_url(webhook_data.get("html_url")), |
| 51 | + webhook_data=webhook_data, |
| 52 | + ) |
0 commit comments