Skip to content

Commit

Permalink
Add missing attributes to WorkflowJob (#2921)
Browse files Browse the repository at this point in the history
Co-authored-by: Aiden Grossman <agrossman154@yahoo.com>
  • Loading branch information
xvega and boomanaiden154 committed Mar 21, 2024
1 parent e3d3653 commit 9e09245
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
72 changes: 72 additions & 0 deletions github/WorkflowJob.py
Expand Up @@ -46,17 +46,26 @@ def _initAttributes(self) -> None:
self._check_run_url: Attribute[str] = NotSet
self._completed_at: Attribute[datetime] = NotSet
self._conclusion: Attribute[str] = NotSet
self._created_at: Attribute[datetime] = NotSet
self._head_branch: Attribute[str] = NotSet
self._head_sha: Attribute[str] = NotSet
self._html_url: Attribute[str] = NotSet
self._id: Attribute[int] = NotSet
self._labels: Attribute[list[str]] = NotSet
self._name: Attribute[str] = NotSet
self._node_id: Attribute[str] = NotSet
self._run_attempt: Attribute[int] = NotSet
self._run_id: Attribute[int] = NotSet
self._run_url: Attribute[str] = NotSet
self._runner_group_id: Attribute[int] = NotSet
self._runner_group_name: Attribute[str] = NotSet
self._runner_id: Attribute[int] = NotSet
self._runner_name: Attribute[str] = NotSet
self._started_at: Attribute[datetime] = NotSet
self._status: Attribute[str] = NotSet
self._steps: Attribute[list[github.WorkflowStep.WorkflowStep]] = NotSet
self._url: Attribute[str] = NotSet
self._workflow_name: Attribute[str] = NotSet

def __repr__(self) -> str:
return self.get__repr__({"id": self._id.value, "url": self._url.value})
Expand All @@ -76,6 +85,16 @@ def conclusion(self) -> str:
self._completeIfNotSet(self._conclusion)
return self._conclusion.value

@property
def created_at(self) -> datetime:
self._completeIfNotSet(self._created_at)
return self._created_at.value

@property
def head_branch(self) -> str:
self._completeIfNotSet(self._head_branch)
return self._head_branch.value

@property
def head_sha(self) -> str:
self._completeIfNotSet(self._head_sha)
Expand All @@ -91,6 +110,11 @@ def id(self) -> int:
self._completeIfNotSet(self._id)
return self._id.value

@property
def labels(self) -> list[str]:
self._completeIfNotSet(self._labels)
return self._labels.value

@property
def name(self) -> str:
self._completeIfNotSet(self._name)
Expand All @@ -101,6 +125,11 @@ def node_id(self) -> str:
self._completeIfNotSet(self._node_id)
return self._node_id.value

@property
def run_attempt(self) -> int:
self._completeIfNotSet(self._run_attempt)
return self._run_attempt.value

@property
def run_id(self) -> int:
self._completeIfNotSet(self._run_id)
Expand All @@ -111,6 +140,26 @@ def run_url(self) -> str:
self._completeIfNotSet(self._run_url)
return self._run_url.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

@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 started_at(self) -> datetime:
self._completeIfNotSet(self._started_at)
Expand All @@ -131,6 +180,11 @@ def url(self) -> str:
self._completeIfNotSet(self._url)
return self._url.value

@property
def workflow_name(self) -> str:
self._completeIfNotSet(self._workflow_name)
return self._workflow_name.value

def logs_url(self) -> str:
headers, _ = self._requester.requestBlobAndCheck("GET", f"{self.url}/logs")
return headers["location"]
Expand All @@ -142,20 +196,36 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
self._completed_at = self._makeDatetimeAttribute(attributes["completed_at"])
if "conclusion" in attributes: # pragma no branch
self._conclusion = self._makeStringAttribute(attributes["conclusion"])
if "created_at" in attributes: # pragma no branch
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
if "head_branch" in attributes: # pragma no branch
self._head_branch = self._makeStringAttribute(attributes["head_branch"])
if "head_sha" in attributes: # pragma no branch
self._head_sha = self._makeStringAttribute(attributes["head_sha"])
if "html_url" in attributes: # pragma no branch
self._html_url = self._makeStringAttribute(attributes["html_url"])
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
if "labels" in attributes: # pragma no branch
self._labels = self._makeListOfStringsAttribute(attributes["labels"])
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_attempt" in attributes: # pragma no branch
self._run_attempt = self._makeIntAttribute(attributes["run_attempt"])
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 "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"])
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 "started_at" in attributes: # pragma no branch
self._started_at = self._makeDatetimeAttribute(attributes["started_at"])
if "status" in attributes: # pragma no branch
Expand All @@ -164,3 +234,5 @@ 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 "workflow_name" in attributes: # pragma no branch
self._workflow_name = self._makeStringAttribute(attributes["workflow_name"])
10 changes: 10 additions & 0 deletions tests/WorkflowJob.py
Expand Up @@ -79,3 +79,13 @@ 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")
created_at = datetime(2023, 2, 17, 16, 3, 38, tzinfo=timezone.utc)
self.assertEqual(self.job.created_at, created_at)
self.assertEqual(self.job.head_branch, "tz-aware-2")
self.assertEqual(self.job.labels, ["ubuntu-latest"])
self.assertEqual(self.job.run_attempt, 1)
self.assertEqual(self.job.workflow_name, "CI")

0 comments on commit 9e09245

Please sign in to comment.