Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
_webhooks_payload.py137 linesDownload Raw Back to huggingface_hub
1# Copyright 2023-present, the HuggingFace Inc. team.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7#     http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14"""Contains data structures to parse the webhooks payload."""15 16from typing import Literal17 18from .utils import is_pydantic_available19 20 21if is_pydantic_available():22    from pydantic import BaseModel23else:24    # Define a dummy BaseModel to avoid import errors when pydantic is not installed25    # Import error will be raised when trying to use the class26 27    class BaseModel:  # type: ignore [no-redef]28        def __init__(self, *args, **kwargs) -> None:29            raise ImportError(30                "You must have `pydantic` installed to use `WebhookPayload`. This is an optional dependency that"31                " should be installed separately. Please run `pip install --upgrade pydantic` and retry."32            )33 34 35# This is an adaptation of the ReportV3 interface implemented in moon-landing. V0, V1 and V2 have been ignored as they36# are not in used anymore. To keep in sync when format is updated in37# https://github.com/huggingface/moon-landing/blob/main/server/lib/HFWebhooks.ts (internal link).38 39 40WebhookEvent_T = Literal[41    "create",42    "delete",43    "move",44    "update",45]46RepoChangeEvent_T = Literal[47    "add",48    "move",49    "remove",50    "update",51]52RepoType_T = Literal[53    "dataset",54    "model",55    "space",56]57DiscussionStatus_T = Literal[58    "closed",59    "draft",60    "open",61    "merged",62]63SupportedWebhookVersion = Literal[3]64 65 66class ObjectId(BaseModel):67    id: str68 69 70class WebhookPayloadUrl(BaseModel):71    web: str72    api: str | None = None73 74 75class WebhookPayloadMovedTo(BaseModel):76    name: str77    owner: ObjectId78 79 80class WebhookPayloadWebhook(ObjectId):81    version: SupportedWebhookVersion82 83 84class WebhookPayloadEvent(BaseModel):85    action: WebhookEvent_T86    scope: str87 88 89class WebhookPayloadDiscussionChanges(BaseModel):90    base: str91    mergeCommitId: str | None = None92 93 94class WebhookPayloadComment(ObjectId):95    author: ObjectId96    hidden: bool97    content: str | None = None98    url: WebhookPayloadUrl99 100 101class WebhookPayloadDiscussion(ObjectId):102    num: int103    author: ObjectId104    url: WebhookPayloadUrl105    title: str106    isPullRequest: bool107    status: DiscussionStatus_T108    changes: WebhookPayloadDiscussionChanges | None = None109    pinned: bool | None = None110 111 112class WebhookPayloadRepo(ObjectId):113    owner: ObjectId114    head_sha: str | None = None115    name: str116    private: bool117    subdomain: str | None = None118    tags: list[str] | None = None119    type: Literal["dataset", "model", "space"]120    url: WebhookPayloadUrl121 122 123class WebhookPayloadUpdatedRef(BaseModel):124    ref: str125    oldSha: str | None = None126    newSha: str | None = None127 128 129class WebhookPayload(BaseModel):130    event: WebhookPayloadEvent131    repo: WebhookPayloadRepo132    discussion: WebhookPayloadDiscussion | None = None133    comment: WebhookPayloadComment | None = None134    webhook: WebhookPayloadWebhook135    movedTo: WebhookPayloadMovedTo | None = None136    updatedRefs: list[WebhookPayloadUpdatedRef] | None = None137 
codekingpro/portable-devtools · Team Ai