Skip to content

Commit 612ba68

Browse files
authored
Add actor property to WorkflowRun (PyGithub#2764)
The GitHub API [returns an `actor` field when listing workflow runs](https://docs.github.com/en/free-pro-team@latest/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-workflow) but `WorkflowRun` does not include `actor`. This PR adds the `actor` property of `NamedUser` type. Not sure about field ordering conventions so just followed the API response schema.
1 parent e1d67ad commit 612ba68

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

github/WorkflowRun.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from typing import TYPE_CHECKING, Any, NamedTuple
3939

4040
import github.GitCommit
41+
import github.NamedUser
4142
import github.PullRequest
4243
import github.WorkflowJob
4344
from github.GithubObject import Attribute, CompletableGithubObject, NotSet, Opt, is_optional
@@ -46,6 +47,7 @@
4647
if TYPE_CHECKING:
4748
from github.Artifact import Artifact
4849
from github.GitCommit import GitCommit
50+
from github.NamedUser import NamedUser
4951
from github.PullRequest import PullRequest
5052
from github.Repository import Repository
5153
from github.WorkflowJob import WorkflowJob
@@ -76,6 +78,7 @@ def _initAttributes(self) -> None:
7678
self._run_number: Attribute[int] = NotSet
7779
self._created_at: Attribute[datetime] = NotSet
7880
self._updated_at: Attribute[datetime] = NotSet
81+
self._actor: Attribute[NamedUser] = NotSet
7982
self._pull_requests: Attribute[list[PullRequest]] = NotSet
8083
self._status: Attribute[str] = NotSet
8184
self._conclusion: Attribute[str] = NotSet
@@ -187,6 +190,11 @@ def updated_at(self) -> datetime:
187190
self._completeIfNotSet(self._updated_at)
188191
return self._updated_at.value
189192

193+
@property
194+
def actor(self) -> NamedUser:
195+
self._completeIfNotSet(self._actor)
196+
return self._actor.value
197+
190198
@property
191199
def jobs_url(self) -> str:
192200
self._completeIfNotSet(self._jobs_url)
@@ -340,6 +348,8 @@ def _useAttributes(self, attributes: dict[str, Any]) -> None:
340348
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
341349
if "updated_at" in attributes: # pragma no branch
342350
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
351+
if "actor" in attributes: # pragma no branch
352+
self._actor = self._makeClassAttribute(github.NamedUser.NamedUser, attributes["actor"])
343353
if "jobs_url" in attributes: # pragma no branch
344354
self._jobs_url = self._makeStringAttribute(attributes["jobs_url"])
345355
if "logs_url" in attributes: # pragma no branch

tests/WorkflowRun.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def testAttributes(self):
4343
repr(self.workflow_run),
4444
'WorkflowRun(url="https://api.github.com/repos/PyGithub/PyGithub/actions/runs/3881497935", id=3881497935)',
4545
)
46+
self.assertEqual(self.workflow_run.actor.login, "nuang-ee")
4647
self.assertEqual(self.workflow_run.id, 3881497935)
4748
self.assertEqual(self.workflow_run.name, "CI")
4849
self.assertEqual(self.workflow_run.head_branch, "feat/workflow-run")

0 commit comments

Comments
 (0)