Skip to content

Add runner attributes to WorkflowJob #2902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions github/WorkflowJob.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def _initAttributes(self) -> None:
self._status: Attribute[str] = NotSet
self._steps: Attribute[list[github.WorkflowStep.WorkflowStep]] = NotSet
self._url: Attribute[str] = NotSet
self._runner_id: Attribute[int] = NotSet
self._runner_name: Attribute[str] = NotSet
self._runner_group_id: Attribute[int] = NotSet
self._runner_group_name: Attribute[str] = NotSet
Comment on lines +56 to +59
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep this list of attributes in alphabetical order?


def __repr__(self) -> str:
return self.get__repr__({"id": self._id.value, "url": self._url.value})
Expand Down Expand Up @@ -127,6 +131,26 @@ def url(self) -> str:
self._completeIfNotSet(self._url)
return self._url.value

@property
def runner_id(self) -> int:
self._completeIfNotSet(self._runner_id)
return self._runner_id.value

@property
def runner_name(self) -> str:
self._completeIfNotSet(self._runner_name)
return self._runner_name.value

@property
def runner_group_id(self) -> int:
self._completeIfNotSet(self._runner_group_id)
return self._runner_group_id.value

@property
def runner_group_name(self) -> str:
self._completeIfNotSet(self._runner_group_name)
return self._runner_group_name.value

def logs_url(self) -> str:
headers, _ = self._requester.requestBlobAndCheck("GET", f"{self.url}/logs")
return headers["location"]
Expand Down Expand Up @@ -160,3 +184,11 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
self._steps = self._makeListOfClassesAttribute(github.WorkflowStep.WorkflowStep, attributes["steps"])
if "url" in attributes: # pragma no branch
self._url = self._makeStringAttribute(attributes["url"])
if "runner_id" in attributes: # pragma no branch
self._runner_id = self._makeIntAttribute(attributes["runner_id"])
if "runner_name" in attributes: # pragma no branch
self._runner_name = self._makeStringAttribute(attributes["runner_name"])
if "runner_group_id" in attributes: # pragma no branch
self._runner_group_id = self._makeIntAttribute(attributes["runner_group_id"])
if "runner_group_name" in attributes: # pragma no branch
self._runner_group_name = self._makeStringAttribute(attributes["runner_group_name"])
4 changes: 4 additions & 0 deletions tests/WorkflowJob.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ def testAttributes(self):
self.job.logs_url(),
"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",
)
self.assertEqual(self.job.runner_id, 2)
self.assertEqual(self.job.runner_name, "GitHub Actions 2")
self.assertEqual(self.job.runner_group_id, 2)
self.assertEqual(self.job.runner_group_name, "GitHub Actions")