Skip to content

Commit 76cd136

Browse files
Add runner attributes to WorkflowJob
This patch adds the runner attributes to the WorkflowJob class. The four attributes, runner_id, runner_name, runner_group_id, and runner_group_name are always sent along with the job information, but before this patch, are not represented in PyGtithub. This patch adds the attributes and test coverage.
1 parent cd8e528 commit 76cd136

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

github/WorkflowJob.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ def _initAttributes(self) -> None:
5353
self._status: Attribute[str] = NotSet
5454
self._steps: Attribute[list[github.WorkflowStep.WorkflowStep]] = NotSet
5555
self._url: Attribute[str] = NotSet
56+
self._runner_id: Attribute[int] = NotSet
57+
self._runner_name: Attribute[str] = NotSet
58+
self._runner_group_id: Attribute[str] = NotSet
59+
self._runner_group_name: Attribute[str] = NotSet
5660

5761
def __repr__(self) -> str:
5862
return self.get__repr__({"id": self._id.value, "url": self._url.value})
@@ -127,6 +131,26 @@ def url(self) -> str:
127131
self._completeIfNotSet(self._url)
128132
return self._url.value
129133

134+
@property
135+
def runner_id(self) -> int:
136+
self._completeIfNotSet(self._runner_id)
137+
return self._runner_id.value
138+
139+
@property
140+
def runner_name(self) -> str:
141+
self._completeIfNotSet(self._runner_name)
142+
return self._runner_name.value
143+
144+
@property
145+
def runner_group_id(self) -> int:
146+
self._completeIfNotSet(self._runner_group_id)
147+
return self._runner_group_id.value
148+
149+
@property
150+
def runner_group_name(self) -> str:
151+
self._completeIfNotSet(self._runner_group_name)
152+
return self._runner_group_name.value
153+
130154
def logs_url(self) -> str:
131155
headers, _ = self._requester.requestBlobAndCheck("GET", f"{self.url}/logs")
132156
return headers["location"]
@@ -160,3 +184,11 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
160184
self._steps = self._makeListOfClassesAttribute(github.WorkflowStep.WorkflowStep, attributes["steps"])
161185
if "url" in attributes: # pragma no branch
162186
self._url = self._makeStringAttribute(attributes["url"])
187+
if "runner_id" in attributes: # pragma no branch
188+
self._runner_id = self._makeIntAttribute(attributes["runner_id"])
189+
if "runner_name" in attributes: # pragma no branch
190+
self._runner_name = self._makeStringAttribute(attributes["runner_name"])
191+
if "runner_group_id" in attributes: # pragma no branch
192+
self._runner_group_id = self._makeIntAttribute(attributes["runner_group_id"])
193+
if "runner_group_name" in attributes: # pragma no branch
194+
self._runner_group_name = self._makeStringAttribute(attributes["runner_group_name"])

tests/WorkflowJob.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,7 @@ def testAttributes(self):
7979
self.job.logs_url(),
8080
"https://pipelines.actions.githubusercontent.com/serviceHosts/d560a817-28d4-4544-a539-eb35c2a56899/_apis/pipelines/1/runs/5/signedlogcontent/5?urlExpires=2023-03-15T17%3A02%3A58.1305046Z&urlSigningMethod=HMACV1&urlSignature=abcdefghijklmn",
8181
)
82+
self.assertEqual(self.job.runner_id, 2)
83+
self.assertEqual(self.job.runner_name, "GitHub Actions 2")
84+
self.assertEqual(self.job.runner_group_id, 2)
85+
self.assertEqual(self.job.runner_group_name, "GitHub Actions")

0 commit comments

Comments
 (0)