From 09179e56afec66e647afce5e60f1e61efe5ee4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Pich=C3=A9?= Date: Wed, 26 Feb 2025 05:56:05 -0500 Subject: [PATCH] fix: use the WorkflowJob object --- github/Job.py | 237 ------------------------------------------- github/Job.pyi | 48 --------- github/Repository.py | 10 +- 3 files changed, 5 insertions(+), 290 deletions(-) delete mode 100644 github/Job.py delete mode 100644 github/Job.pyi diff --git a/github/Job.py b/github/Job.py deleted file mode 100644 index da378e5bb9..0000000000 --- a/github/Job.py +++ /dev/null @@ -1,237 +0,0 @@ -############################ Copyrights and license ############################ -# # -# Copyright 2021 Denis Blanchette # -# # -# This file is part of PyGithub. # -# http://pygithub.readthedocs.io/ # -# # -# PyGithub is free software: you can redistribute it and/or modify it under # -# the terms of the GNU Lesser General Public License as published by the Free # -# Software Foundation, either version 3 of the License, or (at your option) # -# any later version. # -# # -# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # -# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # -# details. # -# # -# You should have received a copy of the GNU Lesser General Public License # -# along with PyGithub. If not, see . # -# # -################################################################################ - -import github.GithubObject - - -class JobStep(github.GithubObject.NonCompletableGithubObject): - def __repr__(self): - return super().get__repr__({"id": self.id}) - - @property - def completed_at(self): - """ - :type: datetime.datetime - """ - return self._completed_at.value - - @property - def conclusion(self): - """ - :type: string - """ - return self._conclusion.value - - @property - def name(self): - """ - :type: string - """ - return self._name.value - - @property - def number(self): - """ - :type: integer - """ - return self._number.value - - @property - def started_at(self): - """ - :type: datetime.datetime - """ - return self._started_at.value - - @property - def status(self): - """ - :type: string - """ - return self._status.value - - def _initAttributes(self): - self._completed_at = github.GithubObject.NotSet - self._conclusion = github.GithubObject.NotSet - self._id = github.GithubObject.NotSet - self._number = github.GithubObject.NotSet - self._started_at = github.GithubObject.NotSet - self._status = github.GithubObject.NotSet - - def _useAttributes(self, attributes): - if "name" in attributes: - self._name = self._makeStringAttribute(attributes["name"]) - if "completed_at" in attributes: # pragma no branch - assert attributes["completed_at"] is None or isinstance(attributes["completed_at"], str), attributes[ - "completed_at" - ] - self._completed_at = self._makeDatetimeAttribute(attributes["completed_at"]) - if "conclusion" in attributes: # pragma no branch - self._conclusion = self._makeStringAttribute(attributes["conclusion"]) - if "number" in attributes: # pragma no branch - self._number = self._makeIntAttribute(attributes["number"]) - if "started_at" in attributes: # pragma no branch - assert attributes["started_at"] is None or isinstance(attributes["started_at"], str), attributes[ - "started_at" - ] - self._started_at = self._makeDatetimeAttribute(attributes["started_at"]) - if "status" in attributes: # pragma no branch - self._status = self._makeStringAttribute(attributes["status"]) - - -class Job(github.GithubObject.CompletableGithubObject): - def __repr__(self): - return super().get__repr__({"id": self.id}) - - @property - def completed_at(self): - """ - :type: datetime.datetime - """ - self._completeIfNotSet(self._completed_at) - return self._completed_at.value - - @property - def conclusion(self): - """ - :type: string - """ - self._completeIfNotSet(self._conclusion) - return self._conclusion.value - - @property - def head_sha(self): - """ - :type: string - """ - self._completeIfNotSet(self._head_sha) - return self._head_sha.value - - @property - def id(self): - """ - :type: integer - """ - self._completeIfNotSet(self._id) - return self._id.value - - @property - def name(self): - """ - :type: string - """ - self._completeIfNotSet(self._name) - return self._name.value - - @property - def node_id(self): - """ - :type: string - """ - self._completeIfNotSet(self._node_id) - return self._node_id.value - - @property - def run_id(self): - """ - :type: integer - """ - self._completeIfNotSet(self._run_id) - return self._run_id.value - - @property - def run_url(self): - """ - :type: string - """ - self._completeIfNotSet(self._run_url) - return self._run_url.value - - @property - def started_at(self): - """ - :type: datetime.datetime - """ - self._completeIfNotSet(self._started_at) - return self._started_at.value - - @property - def status(self): - """ - :type: string - """ - self._completeIfNotSet(self._status) - return self._status.value - - @property - def steps(self): - """ - :type: list of :class:`github.JobStep.JobStep` - """ - self._completeIfNotSet(self._steps) - return self._steps.value - - def _initAttributes(self): - self._completed_at = github.GithubObject.NotSet - self._conclusion = github.GithubObject.NotSet - self._head_sha = github.GithubObject.NotSet - self._id = github.GithubObject.NotSet - self._id = github.GithubObject.NotSet - self._name = github.GithubObject.NotSet - self._node_id = github.GithubObject.NotSet - self._run_id = github.GithubObject.NotSet - self._run_url = github.GithubObject.NotSet - self._started_at = github.GithubObject.NotSet - self._status = github.GithubObject.NotSet - self._steps = github.GithubObject.NotSet - - def _useAttributes(self, attributes): - if "id" in attributes: - self._id = self._makeIntAttribute(attributes["id"]) - if "completed_at" in attributes: # pragma no branch - assert attributes["completed_at"] is None or isinstance(attributes["completed_at"], str), attributes[ - "completed_at" - ] - self._completed_at = self._makeDatetimeAttribute(attributes["completed_at"]) - if "conclusion" in attributes: # pragma no branch - self._conclusion = self._makeStringAttribute(attributes["conclusion"]) - if "head_sha" in attributes: # pragma no branch - self._head_sha = self._makeStringAttribute(attributes["head_sha"]) - if "id" in attributes: # pragma no branch - self._id = self._makeIntAttribute(attributes["id"]) - if "name" in attributes: # pragma no branch - self._name = self._makeStringAttribute(attributes["name"]) - if "node_id" in attributes: # pragma no branch - self._node_id = self._makeStringAttribute(attributes["node_id"]) - if "run_id" in attributes: # pragma no branch - self._run_id = self._makeIntAttribute(attributes["run_id"]) - if "run_url" in attributes: # pragma no branch - self._run_url = self._makeStringAttribute(attributes["run_url"]) - if "started_at" in attributes: # pragma no branch - assert attributes["started_at"] is None or isinstance(attributes["started_at"], str), attributes[ - "started_at" - ] - self._started_at = self._makeDatetimeAttribute(attributes["started_at"]) - if "status" in attributes: # pragma no branch - self._status = self._makeStringAttribute(attributes["status"]) - if "steps" in attributes: # pragma no branch - self._steps = self._makeListOfClassesAttribute(JobStep, attributes["steps"]) diff --git a/github/Job.pyi b/github/Job.pyi deleted file mode 100644 index fddf510371..0000000000 --- a/github/Job.pyi +++ /dev/null @@ -1,48 +0,0 @@ -from datetime import datetime -from typing import Any, Dict, List - -import github.GithubObject - -class JobStep(github.GithubObject.CompletableGithubObject): - @property - def completed_at(self) -> datetime: ... - @property - def conclusion(self) -> str: ... - @property - def name(self) -> str: ... - @property - def number(self) -> int: ... - @property - def started_at(self) -> datetime: ... - @property - def status(self) -> str: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... - -class Job(github.GithubObject.CompletableGithubObject): - @property - def check_run_url(self) -> str: ... - @property - def completed_at(self) -> datetime: ... - @property - def conclusion(self) -> str: ... - @property - def head_sha(self) -> str: ... - @property - def id(self) -> int: ... - @property - def name(self) -> str: ... - @property - def node_id(self) -> str: ... - @property - def run_id(self) -> int: ... - @property - def run_url(self) -> str: ... - @property - def started_at(self) -> str: ... - @property - def status(self) -> str: ... - @property - def steps(self) -> List[JobStep]: ... - def _initAttributes(self) -> None: ... - def _useAttributes(self, attributes: Dict[str, Any]) -> None: ... diff --git a/github/Repository.py b/github/Repository.py index aba4d796b3..2c0a89cae7 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -197,7 +197,6 @@ import github.Issue import github.IssueComment import github.IssueEvent -import github.Job import github.Label import github.License import github.Milestone @@ -232,6 +231,7 @@ import github.Variable import github.View import github.Workflow +import github.WorkflowJob import github.WorkflowRun from github import Consts from github.Environment import Environment @@ -282,7 +282,6 @@ from github.Issue import Issue from github.IssueComment import IssueComment from github.IssueEvent import IssueEvent - from github.Job import Job from github.Label import Label from github.License import License from github.Milestone import Milestone @@ -312,6 +311,7 @@ from github.Team import Team from github.View import View from github.Workflow import Workflow + from github.WorkflowJob import WorkflowJob from github.WorkflowRun import WorkflowRun @@ -3399,16 +3399,16 @@ def get_workflow(self, id_or_file_name: str | int) -> Workflow: headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/actions/workflows/{id_or_file_name}") return github.Workflow.Workflow(self._requester, headers, data, completed=True) - def get_workflow_job(self, job_id: int | str) -> Job: + def get_workflow_job(self, job_id: int | str) -> WorkflowJob: """ :calls: `GET /repos/{owner}/{repo}/actions/jobs/{job_id} `_ :param job_id: int or string - :rtype: :class:`github.Job.Job` + :rtype: :class:`github.WorkflowJob.WorkflowJob` """ assert isinstance(job_id, int) or isinstance(job_id, str), job_id headers, data = self._requester.requestJsonAndCheck("GET", f"{self.url}/actions/jobs/{job_id}") - return github.Job.Job(self._requester, headers, data, completed=True) + return github.WorkflowJob.WorkflowJob(self._requester, headers, data, completed=True) def get_workflow_runs( self,