sqlmesh.integrations.github.notification_target API documentation

Edit on GitHub

# sqlmesh.integrations.github.notification_target

View Source

     1from __future__ import annotations
     2
     3import sys
     4import typing as t
     5
     6if sys.version_info >= (3, 8):
     7    from typing import Literal
     8else:
     9    from typing_extensions import Literal
    10
    11from pydantic import Field
    12
    13from sqlmesh.core.notification_target import BaseNotificationTarget, NotificationStatus
    14from sqlmesh.core.user import User
    15from sqlmesh.integrations.github.shared import PullRequestInfo, add_comment_to_pr
    16
    17
    18class GithubNotificationTarget(BaseNotificationTarget):
    19    """
    20    Github Notification Target that sends notifications to pull requests
    21    """
    22
    23    type_: Literal["github"] = Field(alias="type", default="github")
    24    token: str
    25    github_url: t.Optional[str] = None
    26    pull_request_url: str
    27    _pull_request_info: t.Optional[PullRequestInfo] = None
    28
    29    def send(
    30        self,
    31        notification_status: NotificationStatus,
    32        msg: str,
    33        user_to_append_to: t.Optional[User] = None,
    34        **kwargs: t.Any,
    35    ) -> None:
    36        from github import Github
    37
    38        client = (
    39            Github(login_or_token=self.token, base_url=self.github_url)
    40            if self.github_url
    41            else Github(login_or_token=self.token)
    42        )
    43        repo = client.get_repo(self.pull_request_info.full_repo_path, lazy=True)
    44        add_comment_to_pr(
    45            repo,
    46            self.pull_request_info,
    47            notification_status,
    48            msg,
    49            user_to_append_to=user_to_append_to,
    50        )
    51
    52    @property
    53    def pull_request_info(self) -> PullRequestInfo:
    54        if not self._pull_request_info:
    55            self._pull_request_info = PullRequestInfo.create_from_pull_request_url(
    56                self.pull_request_url
    57            )
    58        return self._pull_request_info

class GithubNotificationTarget(sqlmesh.core.notification_target.BaseNotificationTarget): View Source

    19class GithubNotificationTarget(BaseNotificationTarget):
    20    """
    21    Github Notification Target that sends notifications to pull requests
    22    """
    23
    24    type_: Literal["github"] = Field(alias="type", default="github")
    25    token: str
    26    github_url: t.Optional[str] = None
    27    pull_request_url: str
    28    _pull_request_info: t.Optional[PullRequestInfo] = None
    29
    30    def send(
    31        self,
    32        notification_status: NotificationStatus,
    33        msg: str,
    34        user_to_append_to: t.Optional[User] = None,
    35        **kwargs: t.Any,
    36    ) -> None:
    37        from github import Github
    38
    39        client = (
    40            Github(login_or_token=self.token, base_url=self.github_url)
    41            if self.github_url
    42            else Github(login_or_token=self.token)
    43        )
    44        repo = client.get_repo(self.pull_request_info.full_repo_path, lazy=True)
    45        add_comment_to_pr(
    46            repo,
    47            self.pull_request_info,
    48            notification_status,
    49            msg,
    50            user_to_append_to=user_to_append_to,
    51        )
    52
    53    @property
    54    def pull_request_info(self) -> PullRequestInfo:
    55        if not self._pull_request_info:
    56            self._pull_request_info = PullRequestInfo.create_from_pull_request_url(
    57                self.pull_request_url
    58            )
    59        return self._pull_request_info

Github Notification Target that sends notifications to pull requests

def send( self, notification_status: sqlmesh.core.notification_target.NotificationStatus, msg: str, user_to_append_to: Optional[sqlmesh.core.user.User] = None, **kwargs: Any) -> None: View Source

    30    def send(
    31        self,
    32        notification_status: NotificationStatus,
    33        msg: str,
    34        user_to_append_to: t.Optional[User] = None,
    35        **kwargs: t.Any,
    36    ) -> None:
    37        from github import Github
    38
    39        client = (
    40            Github(login_or_token=self.token, base_url=self.github_url)
    41            if self.github_url
    42            else Github(login_or_token=self.token)
    43        )
    44        repo = client.get_repo(self.pull_request_info.full_repo_path, lazy=True)
    45        add_comment_to_pr(
    46            repo,
    47            self.pull_request_info,
    48            notification_status,
    49            msg,
    50            user_to_append_to=user_to_append_to,
    51        )

Sends notification with the provided message. Currently only used by the built-in scheduler.

##### Inherited Members

pydantic.main.BaseModel
  BaseModel
  parse_obj
  parse_raw
  parse_file
  from_orm
  construct
  copy
  schema
  schema_json
  validate
  update_forward_refs
sqlmesh.utils.pydantic.PydanticModel
  Config
  dict
  json
  missing_required_fields
  extra_fields
  all_fields
  required_fields