From 355c6d43014ea6210dc1bb7e9f0c5507be2ca849 Mon Sep 17 00:00:00 2001 From: Nicholas Tindle Date: Sun, 12 Jan 2025 16:46:21 -0600 Subject: [PATCH] feat: better parsing --- .../backend/backend/blocks/github/triggers.py | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/autogpt_platform/backend/backend/blocks/github/triggers.py b/autogpt_platform/backend/backend/blocks/github/triggers.py index 938dce84faea..19cf9d8f869d 100644 --- a/autogpt_platform/backend/backend/blocks/github/triggers.py +++ b/autogpt_platform/backend/backend/blocks/github/triggers.py @@ -1,6 +1,7 @@ import json import logging from pathlib import Path +from typing import Literal from pydantic import BaseModel @@ -23,6 +24,71 @@ logger = logging.getLogger(__name__) +class PRHead(BaseModel): + label: str + ref: str + repo: dict + sha: str + user: dict + + +class PullRequest(BaseModel): + _links: dict + active_lock_reason: str | None + additions: int + assignee: dict | None + assignees: list[dict] | None + author_association: ( + Literal["COLLABORATOR"] + | Literal["CONTRIBUTOR"] + | Literal["FIRST_TIME_CONTRIBUTOR"] + | Literal["MEMBER"] + | Literal["OWNER"] + | Literal["MANNEQUIN"] + ) + auto_merge: dict | None + base: dict + body: str | None + changed_files: int + closed_at: str | None + comments: int + comments_url: str + commits: int + commits_url: str + created_at: str + deletions: int + diff_url: str + draft: bool + head: PRHead + html_url: str + id: int + issue_url: str + labels: list[dict] + locked: bool + maintainer_can_modify: bool + merge_commit_sha: str | None + mergeable: bool | None + mergeable_state: Literal["dirty", "clean", "unstable"] | None + merged: bool | None + merged_at: str | None + merged_by: dict | None + milestone: dict | None + node_id: str + number: int + patch_url: str + requested_reviewers: list[dict] + requested_teams: list[dict] | None + review_comment_url: str + review_comments: int + review_comments_url: str + state: Literal["open", "closed"] + statuses_url: str + title: str + updated_at: str + url: str + user: dict + + # --8<-- [start:GithubTriggerExample] class GitHubTriggerBase: class Input(BlockSchema): @@ -101,7 +167,7 @@ class Output(GitHubTriggerBase.Output): description="The PR event that triggered the webhook (e.g. 'opened')" ) number: int = SchemaField(description="The number of the affected pull request") - pull_request: dict = SchemaField( + pull_request: PullRequest = SchemaField( description="Object representing the affected pull request" ) pull_request_url: str = SchemaField( @@ -150,6 +216,8 @@ def __init__(self): def run(self, input_data: Input, **kwargs) -> BlockOutput: # type: ignore yield from super().run(input_data, **kwargs) yield "event", input_data.payload["action"] + # yield "enterprise", input_data.payload["enterprise"] + # yield "installation", input_data.payload["installation"] yield "number", input_data.payload["number"] yield "pull_request", input_data.payload["pull_request"] yield "pull_request_url", input_data.payload["pull_request"]["html_url"]