From 50e26d566f8b6fcd2fa4e57e630521472914796e Mon Sep 17 00:00:00 2001 From: Trim21 Date: Wed, 5 Jul 2023 15:50:31 +0800 Subject: [PATCH] Merge `WorkflowRun` type stub back to source (#2554) --- github/WorkflowRun.py | 263 +++++++++++++++-------------------------- github/WorkflowRun.pyi | 80 ------------- 2 files changed, 96 insertions(+), 247 deletions(-) delete mode 100644 github/WorkflowRun.pyi diff --git a/github/WorkflowRun.py b/github/WorkflowRun.py index 1fbed3f0..92fe8cef 100644 --- a/github/WorkflowRun.py +++ b/github/WorkflowRun.py @@ -21,200 +21,185 @@ # # ################################################################################ -from collections import namedtuple +from __future__ import annotations -import github.Artifact -import github.GithubObject +from datetime import datetime +from typing import TYPE_CHECKING, NamedTuple + +import github.GitCommit import github.PullRequest import github.WorkflowJob +from github.GithubObject import ( + Attribute, + CompletableGithubObject, + NotSet, + Opt, + is_optional, +) +from github.PaginatedList import PaginatedList + +if TYPE_CHECKING: + from github.Artifact import Artifact + from github.GitCommit import GitCommit + from github.PullRequest import PullRequest + from github.Repository import Repository + from github.WorkflowJob import WorkflowJob -class WorkflowRun(github.GithubObject.CompletableGithubObject): +class TimingData(NamedTuple): + billable: dict[str, dict[str, int]] + run_duration_ms: int + + +class WorkflowRun(CompletableGithubObject): """ This class represents Workflow Runs. The reference can be found here https://docs.github.com/en/rest/reference/actions#workflow-runs """ + def _initAttributes(self): + self._id: Attribute[int] = NotSet + self._url: Attribute[str] = NotSet + self._name: Attribute[str] = NotSet + self._path: Attribute[str] = NotSet + self._head_branch: Attribute[str] = NotSet + self._head_sha: Attribute[str] = NotSet + self._run_attempt: Attribute[int] = NotSet + self._run_number: Attribute[int] = NotSet + self._created_at: Attribute[datetime] = NotSet + self._updated_at: Attribute[datetime] = NotSet + self._pull_requests: Attribute[list[PullRequest]] = NotSet + self._status: Attribute[str] = NotSet + self._conclusion: Attribute[str] = NotSet + self._html_url: Attribute[str] = NotSet + self._jobs_url: Attribute[str] = NotSet + self._logs_url: Attribute[str] = NotSet + self._display_title: Attribute[str] = NotSet + self._event: Attribute[str] = NotSet + self._run_started_at: Attribute[datetime] = NotSet + self._check_suite_url: Attribute[str] = NotSet + self._cancel_url: Attribute[str] = NotSet + self._rerun_url: Attribute[str] = NotSet + self._artifacts_url: Attribute[str] = NotSet + self._workflow_url: Attribute[str] = NotSet + self._head_commit: Attribute[GitCommit] = NotSet + self._repository: Attribute[Repository] = NotSet + self._head_repository: Attribute[Repository] = NotSet + def __repr__(self): return self.get__repr__({"id": self._id.value, "url": self._url.value}) @property - def id(self): - """ - :type: int - """ + def id(self) -> int: self._completeIfNotSet(self._id) return self._id.value @property - def name(self): - """ - :type: string - """ + def name(self) -> str: self._completeIfNotSet(self._name) return self._name.value @property - def head_branch(self): - """ - :type: string - """ + def head_branch(self) -> str: self._completeIfNotSet(self._head_branch) return self._head_branch.value @property - def head_sha(self): - """ - :type: string - """ + def head_sha(self) -> str: self._completeIfNotSet(self._head_sha) return self._head_sha.value @property - def display_title(self): - """ - :type: string - """ + def display_title(self) -> str: self._completeIfNotSet(self._display_title) return self._display_title.value @property - def path(self): - """ - :type: string - """ + def path(self) -> str: self._completeIfNotSet(self._path) return self._path.value @property - def run_attempt(self): - """ - :type: integer - """ + def run_attempt(self) -> int: self._completeIfNotSet(self._run_attempt) return self._run_attempt.value @property - def run_number(self): - """ - :type: int - """ + def run_number(self) -> int: self._completeIfNotSet(self._run_number) return self._run_number.value @property - def event(self): - """ - :type: string - """ + def event(self) -> str: self._completeIfNotSet(self._event) return self._event.value @property - def run_started_at(self): - """ - :type: datetime.datetime - """ + def run_started_at(self) -> datetime: self._completeIfNotSet(self._run_started_at) return self._run_started_at.value @property - def status(self): - """ - :type: string - """ + def status(self) -> str: self._completeIfNotSet(self._status) return self._status.value @property - def conclusion(self): - """ - :type: string - """ + def conclusion(self) -> str: self._completeIfNotSet(self._conclusion) return self._conclusion.value @property - def workflow_id(self): - """ - :type: int - """ + def workflow_id(self) -> int: self._completeIfNotSet(self._workflow_id) return self._workflow_id.value @property - def url(self): - """ - :type: string - """ + def url(self) -> str: self._completeIfNotSet(self._url) return self._url.value @property - def html_url(self): - """ - :type: string - """ + def html_url(self) -> str: self._completeIfNotSet(self._html_url) return self._html_url.value @property - def pull_requests(self): - """ - :type: list of :class:`github.PullRequest.PullRequest` - """ + def pull_requests(self) -> list[PullRequest]: self._completeIfNotSet(self._pull_requests) return self._pull_requests.value @property - def created_at(self): - """ - :type: datetime.datetime - """ + def created_at(self) -> datetime: self._completeIfNotSet(self._created_at) return self._created_at.value @property - def updated_at(self): - """ - :type: datetime.datetime - """ + def updated_at(self) -> datetime: self._completeIfNotSet(self._updated_at) return self._updated_at.value @property - def jobs_url(self): - """ - :type: string - """ + def jobs_url(self) -> str: self._completeIfNotSet(self._jobs_url) return self._jobs_url.value @property - def logs_url(self): - """ - :type: string - """ + def logs_url(self) -> str: self._completeIfNotSet(self._logs_url) return self._logs_url.value @property - def check_suite_url(self): - """ - :type: string - """ + def check_suite_url(self) -> str: self._completeIfNotSet(self._check_suite_url) return self._check_suite_url.value @property - def artifacts_url(self): - """ - :type: string - """ + def artifacts_url(self) -> str: self._completeIfNotSet(self._artifacts_url) return self._artifacts_url.value - def get_artifacts(self): - return github.PaginatedList.PaginatedList( + def get_artifacts(self) -> PaginatedList[Artifact]: + return PaginatedList( github.Artifact.Artifact, self._requester, self._artifacts_url.value, @@ -223,101 +208,75 @@ class WorkflowRun(github.GithubObject.CompletableGithubObject): ) @property - def cancel_url(self): - """ - :type: string - """ + def cancel_url(self) -> str: self._completeIfNotSet(self._cancel_url) return self._cancel_url.value @property - def rerun_url(self): - """ - :type: string - """ + def rerun_url(self) -> str: self._completeIfNotSet(self._rerun_url) return self._rerun_url.value @property - def workflow_url(self): - """ - :type: string - """ + def workflow_url(self) -> str: self._completeIfNotSet(self._workflow_url) return self._workflow_url.value @property - def head_commit(self): - """ - :type: :class:`github.GitCommit.GitCommit` - """ + def head_commit(self) -> GitCommit: self._completeIfNotSet(self._head_commit) return self._head_commit.value @property - def repository(self): - """ - :type: :class:`github.Repository.Repository` - """ + def repository(self) -> Repository: self._completeIfNotSet(self._repository) return self._repository.value @property - def head_repository(self): - """ - :type: :class:`github.Repository.Repository` - """ + def head_repository(self) -> Repository: self._completeIfNotSet(self._head_repository) return self._head_repository.value - def cancel(self): + def cancel(self) -> bool: """ :calls: `POST /repos/{owner}/{repo}/actions/runs/{run_id}/cancel `_ - :rtype: bool """ status, _, _ = self._requester.requestJson("POST", self.cancel_url) return status == 202 - def rerun(self): + def rerun(self) -> bool: """ :calls: `POST /repos/{owner}/{repo}/actions/runs/{run_id}/rerun `_ - :rtype: bool """ status, _, _ = self._requester.requestJson("POST", self.rerun_url) return status == 201 - def timing(self): + def timing(self) -> TimingData: """ :calls: `GET /repos/{owner}/{repo}/actions/runs/{run_id}/timing `_ - :rtype: namedtuple with billable and run_duration_ms members """ headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/timing") - timingdata = namedtuple("TimingData", data.keys()) - return timingdata._make(data.values()) + return TimingData( + billable=data["billable"], run_duration_ms=data["run_duration_ms"] # type: ignore + ) - def delete(self): + def delete(self) -> bool: """ :calls: `DELETE /repos/{owner}/{repo}/actions/runs/{run_id} `_ - :rtype: bool """ status, _, _ = self._requester.requestJson("DELETE", self.url) return status == 204 - def jobs(self, _filter=github.GithubObject.NotSet): + def jobs(self, _filter: Opt[str] = NotSet) -> PaginatedList[WorkflowJob]: """ :calls "`GET /repos/{owner}/{repo}/actions/runs/{run_id}/jobs `_ :param _filter: string `latest`, or `all` - :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.WorkflowJob.WorkflowJob` """ - assert _filter is github.GithubObject.NotSet or isinstance( - _filter, str - ), _filter + assert is_optional(_filter, str), _filter - url_parameters = dict() - if _filter is not github.GithubObject.NotSet: - url_parameters["filter"] = _filter + url_parameters = NotSet.remove_unset_items({"filter": _filter}) - return github.PaginatedList.PaginatedList( + return PaginatedList( github.WorkflowJob.WorkflowJob, self._requester, self.jobs_url, @@ -325,36 +284,6 @@ class WorkflowRun(github.GithubObject.CompletableGithubObject): list_item="jobs", ) - def _initAttributes(self): - self._id = github.GithubObject.NotSet - self._name = github.GithubObject.NotSet - self._head_branch = github.GithubObject.NotSet - self._head_sha = github.GithubObject.NotSet - self._display_title = github.GithubObject.NotSet - self._path = github.GithubObject.NotSet - self._run_attempt = github.GithubObject.NotSet - self._run_number = github.GithubObject.NotSet - self._event = github.GithubObject.NotSet - self._run_started_at = github.GithubObject.NotSet - self._status = github.GithubObject.NotSet - self._conclusion = github.GithubObject.NotSet - self._workflow_id = github.GithubObject.NotSet - self._url = github.GithubObject.NotSet - self._html_url = github.GithubObject.NotSet - self._pull_requests = github.GithubObject.NotSet - self._created_at = github.GithubObject.NotSet - self._updated_at = github.GithubObject.NotSet - self._jobs_url = github.GithubObject.NotSet - self._logs_url = github.GithubObject.NotSet - self._check_suite_url = github.GithubObject.NotSet - self._artifacts_url = github.GithubObject.NotSet - self._cancel_url = github.GithubObject.NotSet - self._rerun_url = github.GithubObject.NotSet - self._workflow_url = github.GithubObject.NotSet - self._head_commit = github.GithubObject.NotSet - self._repository = github.GithubObject.NotSet - self._head_repository = github.GithubObject.NotSet - def _useAttributes(self, attributes): if "id" in attributes: # pragma no branch self._id = self._makeIntAttribute(attributes["id"]) diff --git a/github/WorkflowRun.pyi b/github/WorkflowRun.pyi deleted file mode 100644 index 6c210160..00000000 --- a/github/WorkflowRun.pyi +++ /dev/null @@ -1,80 +0,0 @@ -from datetime import datetime -from typing import Any, Dict, NamedTuple, List, Union - -from github.GitCommit import GitCommit -from github.GithubObject import CompletableGithubObject, _NotSetType -from github.PaginatedList import PaginatedList -from github.PullRequest import PullRequest -from github.Repository import Repository -from github.WorkflowJob import WorkflowJob - -class TimingData(NamedTuple): - billable: Dict[str, Dict[str, int]] - run_duration_ms: int - -class WorkflowRun(CompletableGithubObject): - def __repr__(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - @property - def id(self) -> int: ... - @property - def name(self) -> str: ... - @property - def head_branch(self) -> str: ... - @property - def head_sha(self) -> str: ... - @property - def path(self) -> str: ... - @property - def display_title(self) -> str: ... - @property - def run_number(self) -> int: ... - @property - def run_attempt(self) -> int: ... - @property - def run_started_at(self) -> str: ... - @property - def event(self) -> str: ... - @property - def status(self) -> str: ... - @property - def conclusion(self) -> str: ... - @property - def workflow_id(self) -> int: ... - @property - def url(self) -> str: ... - @property - def html_url(self) -> str: ... - @property - def pull_requests(self) -> List[PullRequest]: ... - @property - def created_at(self) -> datetime: ... - @property - def updated_at(self) -> datetime: ... - @property - def jobs_url(self) -> str: ... - @property - def logs_url(self) -> str: ... - @property - def check_suite_url(self) -> str: ... - @property - def artifacts_url(self) -> str: ... - @property - def cancel_url(self) -> str: ... - @property - def rerun_url(self) -> str: ... - @property - def workflow_url(self) -> str: ... - @property - def head_commit(self) -> GitCommit: ... - @property - def repository(self) -> Repository: ... - @property - def head_repository(self) -> Repository: ... - def cancel(self) -> bool: ... - def jobs( - self, _filter: Union[str, _NotSetType] = ... - ) -> PaginatedList[WorkflowJob]: ... - def rerun(self) -> bool: ... - def timing(self) -> TimingData: ...