WorkflowJob.py
1 ############################ Copyrights and license ############################ 2 # # 3 # Copyright 2021 Jeppe Fihl-Pearson <jeppe@tenzer.dk> # 4 # # 5 # This file is part of PyGithub. # 6 # http://pygithub.readthedocs.io/ # 7 # # 8 # PyGithub is free software: you can redistribute it and/or modify it under # 9 # the terms of the GNU Lesser General Public License as published by the Free # 10 # Software Foundation, either version 3 of the License, or (at your option) # 11 # any later version. # 12 # # 13 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # 14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # 15 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # 16 # details. # 17 # # 18 # You should have received a copy of the GNU Lesser General Public License # 19 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # 20 # # 21 ################################################################################ 22 from __future__ import annotations 23 24 from datetime import datetime 25 from typing import Any 26 27 import github.GithubObject 28 import github.WorkflowStep 29 from github.GithubObject import Attribute, CompletableGithubObject, NotSet 30 31 32 class WorkflowJob(CompletableGithubObject): 33 """ 34 This class represents Workflow Jobs. The reference can be found here https://docs.github.com/en/rest/reference/actions#workflow-jobs 35 """ 36 37 def _initAttributes(self) -> None: 38 self._check_run_url: Attribute[str] = NotSet 39 self._completed_at: Attribute[datetime] = NotSet 40 self._conclusion: Attribute[str] = NotSet 41 self._head_sha: Attribute[str] = NotSet 42 self._html_url: Attribute[str] = NotSet 43 self._id: Attribute[int] = NotSet 44 self._name: Attribute[str] = NotSet 45 self._node_id: Attribute[str] = NotSet 46 self._run_id: Attribute[int] = NotSet 47 self._run_url: Attribute[str] = NotSet 48 self._started_at: Attribute[datetime] = NotSet 49 self._status: Attribute[str] = NotSet 50 self._steps: Attribute[list[github.WorkflowStep.WorkflowStep]] = NotSet 51 self._url: Attribute[str] = NotSet 52 53 def __repr__(self) -> str: 54 return self.get__repr__({"id": self._id.value, "url": self._url.value}) 55 56 @property 57 def check_run_url(self) -> str: 58 self._completeIfNotSet(self._check_run_url) 59 return self._check_run_url.value 60 61 @property 62 def completed_at(self) -> datetime: 63 self._completeIfNotSet(self._completed_at) 64 return self._completed_at.value 65 66 @property 67 def conclusion(self) -> str: 68 self._completeIfNotSet(self._conclusion) 69 return self._conclusion.value 70 71 @property 72 def head_sha(self) -> str: 73 self._completeIfNotSet(self._head_sha) 74 return self._head_sha.value 75 76 @property 77 def html_url(self) -> str: 78 self._completeIfNotSet(self._html_url) 79 return self._html_url.value 80 81 @property 82 def id(self) -> int: 83 self._completeIfNotSet(self._id) 84 return self._id.value 85 86 @property 87 def name(self) -> str: 88 self._completeIfNotSet(self._name) 89 return self._name.value 90 91 @property 92 def node_id(self) -> str: 93 self._completeIfNotSet(self._node_id) 94 return self._node_id.value 95 96 @property 97 def run_id(self) -> int: 98 self._completeIfNotSet(self._run_id) 99 return self._run_id.value 100 101 @property 102 def run_url(self) -> str: 103 self._completeIfNotSet(self._run_url) 104 return self._run_url.value 105 106 @property 107 def started_at(self) -> datetime: 108 self._completeIfNotSet(self._started_at) 109 return self._started_at.value 110 111 @property 112 def status(self) -> str: 113 self._completeIfNotSet(self._status) 114 return self._status.value 115 116 @property 117 def steps(self) -> list[github.WorkflowStep.WorkflowStep]: 118 self._completeIfNotSet(self._steps) 119 return self._steps.value 120 121 @property 122 def url(self) -> str: 123 self._completeIfNotSet(self._url) 124 return self._url.value 125 126 def logs_url(self) -> str: 127 headers, _ = self._requester.requestBlobAndCheck("GET", f"{self.url}/logs") 128 return headers["location"] 129 130 def _useAttributes(self, attributes: dict[str, Any]) -> None: 131 if "check_run_url" in attributes: # pragma no branch 132 self._check_run_url = self._makeStringAttribute(attributes["check_run_url"]) 133 if "completed_at" in attributes: # pragma no branch 134 self._completed_at = self._makeDatetimeAttribute(attributes["completed_at"]) 135 if "conclusion" in attributes: # pragma no branch 136 self._conclusion = self._makeStringAttribute(attributes["conclusion"]) 137 if "head_sha" in attributes: # pragma no branch 138 self._head_sha = self._makeStringAttribute(attributes["head_sha"]) 139 if "html_url" in attributes: # pragma no branch 140 self._html_url = self._makeStringAttribute(attributes["html_url"]) 141 if "id" in attributes: # pragma no branch 142 self._id = self._makeIntAttribute(attributes["id"]) 143 if "name" in attributes: # pragma no branch 144 self._name = self._makeStringAttribute(attributes["name"]) 145 if "node_id" in attributes: # pragma no branch 146 self._node_id = self._makeStringAttribute(attributes["node_id"]) 147 if "run_id" in attributes: # pragma no branch 148 self._run_id = self._makeIntAttribute(attributes["run_id"]) 149 if "run_url" in attributes: # pragma no branch 150 self._run_url = self._makeStringAttribute(attributes["run_url"]) 151 if "started_at" in attributes: # pragma no branch 152 self._started_at = self._makeDatetimeAttribute(attributes["started_at"]) 153 if "status" in attributes: # pragma no branch 154 self._status = self._makeStringAttribute(attributes["status"]) 155 if "steps" in attributes: # pragma no branch 156 self._steps = self._makeListOfClassesAttribute(github.WorkflowStep.WorkflowStep, attributes["steps"]) 157 if "url" in attributes: # pragma no branch 158 self._url = self._makeStringAttribute(attributes["url"])