mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-01 11:21:16 +00:00
Add support for Workflow Runs (#1583)
To build on the previous work supporting querying Workflows for GitHub Actions, add a class and relevant methods to support querying runs of a workflow.
This commit is contained in:
@@ -136,6 +136,7 @@ import github.Tag
|
||||
import github.Team
|
||||
import github.View
|
||||
import github.Workflow
|
||||
import github.WorkflowRun
|
||||
|
||||
from . import Consts
|
||||
|
||||
@@ -3007,9 +3008,24 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
list_item="workflows",
|
||||
)
|
||||
|
||||
def get_workflow_runs(self):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/actions/runs <https://developer.github.com/v3/actions/workflow-runs>`_
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.WorkflowRun.WorkflowRun`
|
||||
"""
|
||||
return github.PaginatedList.PaginatedList(
|
||||
github.WorkflowRun.WorkflowRun,
|
||||
self._requester,
|
||||
self.url + "/actions/runs",
|
||||
None,
|
||||
list_item="workflow_runs",
|
||||
)
|
||||
|
||||
def get_workflow(self, id_or_name):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/actions/workflows/:workflow_id <https://developer.github.com/v3/actions/workflows>`_
|
||||
:param id_or_name: int or string
|
||||
|
||||
:rtype: :class:`github.Workflow.Workflow`
|
||||
"""
|
||||
assert isinstance(id_or_name, int) or isinstance(id_or_name, str), id_or_name
|
||||
@@ -3018,6 +3034,21 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
)
|
||||
return github.Workflow.Workflow(self._requester, headers, data, completed=True)
|
||||
|
||||
def get_workflow_run(self, id_):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/actions/runs/:run_id <https://developer.github.com/v3/actions/workflow-runs>`_
|
||||
:param id_: int
|
||||
|
||||
:rtype: :class:`github.WorkflowRun.WorkflowRun`
|
||||
"""
|
||||
assert isinstance(id_, int)
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"GET", self.url + "/actions/runs/" + str(id_)
|
||||
)
|
||||
return github.WorkflowRun.WorkflowRun(
|
||||
self._requester, headers, data, completed=True
|
||||
)
|
||||
|
||||
def has_in_assignees(self, assignee):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/assignees/:assignee <http://developer.github.com/v3/issues/assignees>`_
|
||||
|
||||
@@ -49,6 +49,7 @@ from github.Tag import Tag
|
||||
from github.Team import Team
|
||||
from github.View import View
|
||||
from github.Workflow import Workflow
|
||||
from github.WorkflowRun import WorkflowRun
|
||||
|
||||
class Repository(CompletableGithubObject):
|
||||
def __repr__(self) -> str: ...
|
||||
@@ -387,6 +388,8 @@ class Repository(CompletableGithubObject):
|
||||
def get_watchers(self) -> PaginatedList[NamedUser]: ...
|
||||
def get_workflow(self, id_or_name: Union[str, int]) -> Workflow: ...
|
||||
def get_workflows(self) -> PaginatedList[Workflow]: ...
|
||||
def get_workflow_run(self, id_: int) -> WorkflowRun: ...
|
||||
def get_workflow_runs(self) -> PaginatedList[WorkflowRun]: ...
|
||||
@property
|
||||
def git_commits_url(self) -> str: ...
|
||||
@property
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
################################################################################
|
||||
|
||||
import github.GithubObject
|
||||
import github.WorkflowRun
|
||||
|
||||
|
||||
class Workflow(github.GithubObject.CompletableGithubObject):
|
||||
@@ -105,6 +106,57 @@ class Workflow(github.GithubObject.CompletableGithubObject):
|
||||
self._completeIfNotSet(self._badge_url)
|
||||
return self._badge_url.value
|
||||
|
||||
def get_runs(
|
||||
self,
|
||||
actor=github.GithubObject.NotSet,
|
||||
branch=github.GithubObject.NotSet,
|
||||
event=github.GithubObject.NotSet,
|
||||
status=github.GithubObject.NotSet,
|
||||
):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/actions/workflows/:workflow_id/runs <https://developer.github.com/v3/actions/workflow-runs>`_
|
||||
:param actor: :class:`github.NamedUser.NamedUser` or string
|
||||
:param branch: :class:`github.Branch.Branch` or string
|
||||
:param event: string
|
||||
:param status: string
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.WorkflowRun.WorkflowRun`
|
||||
"""
|
||||
assert (
|
||||
actor is github.GithubObject.NotSet
|
||||
or isinstance(actor, github.NamedUser.NamedUser)
|
||||
or isinstance(actor, str)
|
||||
), actor
|
||||
assert (
|
||||
branch is github.GithubObject.NotSet
|
||||
or isinstance(branch, github.Branch.Branch)
|
||||
or isinstance(branch, str)
|
||||
), branch
|
||||
assert event is github.GithubObject.NotSet or isinstance(event, str), event
|
||||
assert status is github.GithubObject.NotSet or isinstance(status, str), status
|
||||
url_parameters = dict()
|
||||
if actor is not github.GithubObject.NotSet:
|
||||
url_parameters["actor"] = (
|
||||
actor._identity
|
||||
if isinstance(actor, github.NamedUser.NamedUser)
|
||||
else actor
|
||||
)
|
||||
if branch is not github.GithubObject.NotSet:
|
||||
url_parameters["branch"] = (
|
||||
branch.name if isinstance(branch, github.Branch.Branch) else branch
|
||||
)
|
||||
if event is not github.GithubObject.NotSet:
|
||||
url_parameters["event"] = event
|
||||
if status is not github.GithubObject.NotSet:
|
||||
url_parameters["status"] = status
|
||||
return github.PaginatedList.PaginatedList(
|
||||
github.WorkflowRun.WorkflowRun,
|
||||
self._requester,
|
||||
self.url + "/runs",
|
||||
url_parameters,
|
||||
None,
|
||||
list_item="workflow_runs",
|
||||
)
|
||||
|
||||
def _initAttributes(self):
|
||||
self._id = github.GithubObject.NotSet
|
||||
self._name = github.GithubObject.NotSet
|
||||
|
||||
+13
-2
@@ -1,12 +1,23 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict
|
||||
from typing import Any, Dict, Union
|
||||
|
||||
from github.GithubObject import CompletableGithubObject
|
||||
from github.Branch import Branch
|
||||
from github.GithubObject import CompletableGithubObject, _NotSetType
|
||||
from github.NamedUser import NamedUser
|
||||
from github.PaginatedList import PaginatedList
|
||||
from github.WorkflowRun import WorkflowRun
|
||||
|
||||
class Workflow(CompletableGithubObject):
|
||||
def __repr__(self) -> str: ...
|
||||
def _initAttributes(self) -> None: ...
|
||||
def _useAttributes(self, attributes: Dict[str, Any]) -> None: ...
|
||||
def get_runs(
|
||||
self,
|
||||
actor: Union[str, NamedUser, _NotSetType],
|
||||
branch: Union[str, Branch, _NotSetType],
|
||||
event: Union[str, _NotSetType],
|
||||
status: Union[str, _NotSetType]
|
||||
) -> PaginatedList[WorkflowRun]: ...
|
||||
@property
|
||||
def id(self) -> int: ...
|
||||
@property
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
############################ Copyrights and license ############################
|
||||
# #
|
||||
# Copyright 2020 Steve Kowalik <steven@wedontsleep.org> #
|
||||
# #
|
||||
# This file is part of PyGithub. #
|
||||
# http://pygithub.readthedocs.io/ #
|
||||
# #
|
||||
# PyGithub is free software: you can redistribute it and/or modify it under #
|
||||
# the terms of the GNU Lesser General Public License as published by the Free #
|
||||
# Software Foundation, either version 3 of the License, or (at your option) #
|
||||
# any later version. #
|
||||
# #
|
||||
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
|
||||
# details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Lesser General Public License #
|
||||
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
import github.GithubObject
|
||||
import github.PullRequest
|
||||
|
||||
|
||||
class WorkflowRun(github.GithubObject.CompletableGithubObject):
|
||||
"""
|
||||
This class represents Workflow Runs. The reference can be found here https://developer.github.com/v3/actions/workflow-runs/
|
||||
"""
|
||||
|
||||
def __repr__(self):
|
||||
return self.get__repr__({"id": self._id.value, "url": self._url.value})
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
"""
|
||||
:type: int
|
||||
"""
|
||||
self._completeIfNotSet(self._id)
|
||||
return self._id.value
|
||||
|
||||
@property
|
||||
def head_branch(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._head_branch)
|
||||
return self._head_branch.value
|
||||
|
||||
@property
|
||||
def head_sha(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._head_sha)
|
||||
return self._head_sha.value
|
||||
|
||||
@property
|
||||
def run_number(self):
|
||||
"""
|
||||
:type: int
|
||||
"""
|
||||
self._completeIfNotSet(self._run_number)
|
||||
return self._run_number.value
|
||||
|
||||
@property
|
||||
def event(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._event)
|
||||
return self._event.value
|
||||
|
||||
@property
|
||||
def status(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._status)
|
||||
return self._status.value
|
||||
|
||||
@property
|
||||
def conclusion(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._conclusion)
|
||||
return self._conclusion.value
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._url)
|
||||
return self._url.value
|
||||
|
||||
@property
|
||||
def html_url(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._html_url)
|
||||
return self._html_url.value
|
||||
|
||||
@property
|
||||
def pull_requests(self):
|
||||
"""
|
||||
:type: list of :class:`github.PullRequest.PullRequest`
|
||||
"""
|
||||
self._completeIfNotSet(self._pull_requests)
|
||||
return self._pull_requests.value
|
||||
|
||||
@property
|
||||
def created_at(self):
|
||||
"""
|
||||
:type: datetime.datetime
|
||||
"""
|
||||
self._completeIfNotSet(self._created_at)
|
||||
return self._created_at.value
|
||||
|
||||
@property
|
||||
def updated_at(self):
|
||||
"""
|
||||
:type: datetime.datetime
|
||||
"""
|
||||
self._completeIfNotSet(self._updated_at)
|
||||
return self._updated_at.value
|
||||
|
||||
@property
|
||||
def jobs_url(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._jobs_url)
|
||||
return self._jobs_url.value
|
||||
|
||||
@property
|
||||
def logs_url(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._logs_url)
|
||||
return self._logs_url.value
|
||||
|
||||
@property
|
||||
def check_suite_url(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._check_suite_url)
|
||||
return self._check_suite_url.value
|
||||
|
||||
@property
|
||||
def artifacts_url(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._artifacts_url)
|
||||
return self._artifacts_url.value
|
||||
|
||||
@property
|
||||
def cancel_url(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._cancel_url)
|
||||
return self._cancel_url.value
|
||||
|
||||
@property
|
||||
def rerun_url(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._rerun_url)
|
||||
return self._rerun_url.value
|
||||
|
||||
@property
|
||||
def workflow_url(self):
|
||||
"""
|
||||
:type: string
|
||||
"""
|
||||
self._completeIfNotSet(self._workflow_url)
|
||||
return self._workflow_url.value
|
||||
|
||||
@property
|
||||
def head_commit(self):
|
||||
"""
|
||||
:type: :class:`github.GitCommit.GitCommit`
|
||||
"""
|
||||
self._completeIfNotSet(self._head_commit)
|
||||
return self._head_commit.value
|
||||
|
||||
@property
|
||||
def repository(self):
|
||||
"""
|
||||
:type: :class:`github.Repository.Repository`
|
||||
"""
|
||||
self._completeIfNotSet(self._repository)
|
||||
return self._repository.value
|
||||
|
||||
@property
|
||||
def head_repository(self):
|
||||
"""
|
||||
:type: :class:`github.Repository.Repository`
|
||||
"""
|
||||
self._completeIfNotSet(self._head_repository)
|
||||
return self._head_repository.value
|
||||
|
||||
def cancel(self):
|
||||
"""
|
||||
:calls: `POST /repos/:owner/:repo/actions/runs/:run_id/cancel <https://developer.github.com/v3/actions/workflow-runs/>`_
|
||||
:rtype: bool
|
||||
"""
|
||||
status, _, _ = self._requester.requestJson("POST", self.cancel_url)
|
||||
return status == 202
|
||||
|
||||
def rerun(self):
|
||||
"""
|
||||
:calls: `POST /repos/:owner/:repo/actions/runs/:run_id/rerun <https://developer.github.com/v3/actions/workflow-runs/>`_
|
||||
:rtype: bool
|
||||
"""
|
||||
status, _, _ = self._requester.requestJson("POST", self.rerun_url)
|
||||
return status == 201
|
||||
|
||||
def timing(self):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/actions/runs/:run_id/timing <https://developer.github.com/v3/actions/workflow-runs/>`_
|
||||
:rtype: namedtuple with billable and run_duration_ms members
|
||||
"""
|
||||
timingdata = namedtuple("TimingData", ["billable", "run_duration_ms"])
|
||||
headers, data = self._requester.requestJsonAndCheck("GET", self.url + "/timing")
|
||||
return timingdata._make(data.values())
|
||||
|
||||
def _initAttributes(self):
|
||||
self._id = github.GithubObject.NotSet
|
||||
self._head_branch = github.GithubObject.NotSet
|
||||
self._head_sha = github.GithubObject.NotSet
|
||||
self._run_number = github.GithubObject.NotSet
|
||||
self._event = github.GithubObject.NotSet
|
||||
self._status = github.GithubObject.NotSet
|
||||
self._conclusion = github.GithubObject.NotSet
|
||||
self._url = github.GithubObject.NotSet
|
||||
self._html_url = github.GithubObject.NotSet
|
||||
self._pull_requests = github.GithubObject.NotSet
|
||||
self._created_at = github.GithubObject.NotSet
|
||||
self._updated_at = github.GithubObject.NotSet
|
||||
self._jobs_url = github.GithubObject.NotSet
|
||||
self._logs_url = github.GithubObject.NotSet
|
||||
self._check_suite_url = github.GithubObject.NotSet
|
||||
self._artifacts_url = github.GithubObject.NotSet
|
||||
self._cancel_url = github.GithubObject.NotSet
|
||||
self._rerun_url = github.GithubObject.NotSet
|
||||
self._workflow_url = github.GithubObject.NotSet
|
||||
self._head_commit = github.GithubObject.NotSet
|
||||
self._repository = github.GithubObject.NotSet
|
||||
self._head_repository = github.GithubObject.NotSet
|
||||
|
||||
def _useAttributes(self, attributes):
|
||||
if "id" in attributes: # pragma no branch
|
||||
self._id = self._makeIntAttribute(attributes["id"])
|
||||
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 "run_number" in attributes: # pragma no branch
|
||||
self._run_number = self._makeIntAttribute(attributes["run_number"])
|
||||
if "event" in attributes: # pragma no branch
|
||||
self._event = self._makeStringAttribute(attributes["event"])
|
||||
if "status" in attributes: # pragma no branch
|
||||
self._status = self._makeStringAttribute(attributes["status"])
|
||||
if "conclusion" in attributes: # pragma no branch
|
||||
self._conclusion = self._makeStringAttribute(attributes["conclusion"])
|
||||
if "url" in attributes: # pragma no branch
|
||||
self._url = self._makeStringAttribute(attributes["url"])
|
||||
if "html_url" in attributes: # pragma no branch
|
||||
self._html_url = self._makeStringAttribute(attributes["html_url"])
|
||||
if "pull_requests" in attributes: # pragma no branch
|
||||
self._pull_requests = self._makeListOfClassesAttribute(
|
||||
github.PullRequest.PullRequest, attributes["pull_requests"]
|
||||
)
|
||||
if "created_at" in attributes: # pragma no branch
|
||||
self._created_at = self._makeDatetimeAttribute(attributes["created_at"])
|
||||
if "updated_at" in attributes: # pragma no branch
|
||||
self._updated_at = self._makeDatetimeAttribute(attributes["updated_at"])
|
||||
if "jobs_url" in attributes: # pragma no branch
|
||||
self._jobs_url = self._makeStringAttribute(attributes["jobs_url"])
|
||||
if "logs_url" in attributes: # pragma no branch
|
||||
self._logs_url = self._makeStringAttribute(attributes["logs_url"])
|
||||
if "check_suite_url" in attributes: # pragma no branch
|
||||
self._check_suite_url = self._makeStringAttribute(
|
||||
attributes["check_suite_url"]
|
||||
)
|
||||
if "artifacts_url" in attributes: # pragma no branch
|
||||
self._artifacts_url = self._makeStringAttribute(attributes["artifacts_url"])
|
||||
if "cancel_url" in attributes: # pragma no branch
|
||||
self._cancel_url = self._makeStringAttribute(attributes["cancel_url"])
|
||||
if "rerun_url" in attributes: # pragma no branch
|
||||
self._rerun_url = self._makeStringAttribute(attributes["rerun_url"])
|
||||
if "workflow_url" in attributes: # pragma no branch
|
||||
self._workflow_url = self._makeStringAttribute(attributes["workflow_url"])
|
||||
if "head_commit" in attributes: # pragma no branch
|
||||
self._head_commit = self._makeClassAttribute(
|
||||
github.GitCommit.GitCommit, attributes["head_commit"]
|
||||
)
|
||||
if "repository" in attributes: # pragma no branch
|
||||
self._repository = self._makeClassAttribute(
|
||||
github.Repository.Repository, attributes["repository"]
|
||||
)
|
||||
if "head_repository" in attributes: # pragma no branch
|
||||
self._head_repository = self._makeClassAttribute(
|
||||
github.Repository.Repository, attributes["head_repository"]
|
||||
)
|
||||
@@ -0,0 +1,63 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, NamedTuple, List
|
||||
|
||||
from github.GitCommit import GitCommit
|
||||
from github.GithubObject import CompletableGithubObject
|
||||
from github.PullRequest import PullRequest
|
||||
from github.Repository import Repository
|
||||
|
||||
class TimingData(NamedTuple):
|
||||
billable: Dict[str, Dict[str, int]]
|
||||
run_duration_ms: int
|
||||
|
||||
class WorkflowRun(CompletableGithubObject):
|
||||
def __repr__(self) -> str: ...
|
||||
def _initAttributes(self) -> None: ...
|
||||
def _useAttributes(self, attributes: Dict[str, Any]) -> None: ...
|
||||
@property
|
||||
def id(self) -> int: ...
|
||||
@property
|
||||
def head_branch(self) -> str: ...
|
||||
@property
|
||||
def head_sha(self) -> str: ...
|
||||
@property
|
||||
def run_number(self) -> int: ...
|
||||
@property
|
||||
def event(self) -> str: ...
|
||||
@property
|
||||
def status(self) -> str: ...
|
||||
@property
|
||||
def conclusion(self) -> str: ...
|
||||
@property
|
||||
def url(self) -> str: ...
|
||||
@property
|
||||
def html_url(self) -> str: ...
|
||||
@property
|
||||
def pull_requests(self) -> List[PullRequest]: ...
|
||||
@property
|
||||
def created_at(self) -> datetime: ...
|
||||
@property
|
||||
def updated_at(self) -> datetime: ...
|
||||
@property
|
||||
def jobs_url(self) -> str: ...
|
||||
@property
|
||||
def logs_url(self) -> str: ...
|
||||
@property
|
||||
def check_suite_url(self) -> str: ...
|
||||
@property
|
||||
def artifacts_url(self) -> str: ...
|
||||
@property
|
||||
def cancel_url(self) -> str: ...
|
||||
@property
|
||||
def rerun_url(self) -> str: ...
|
||||
@property
|
||||
def workflow_url(self) -> str: ...
|
||||
@property
|
||||
def head_commit(self) -> GitCommit: ...
|
||||
@property
|
||||
def repository(self) -> Repository: ...
|
||||
@property
|
||||
def head_repository(self) -> Repository: ...
|
||||
def cancel(self) -> bool: ...
|
||||
def rerun(self) -> bool: ...
|
||||
def timing(self) -> TimingData: ...
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
https
|
||||
POST
|
||||
api.github.com
|
||||
None
|
||||
/repos/PyGithub/PyGithub/actions/runs/148274629/cancel
|
||||
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
|
||||
None
|
||||
202
|
||||
[('Date', 'Fri, 26 Jun 2020 05:04:32 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '2'), ('Server', 'GitHub.com'), ('Status', '202 Accepted'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4948'), ('X-RateLimit-Reset', '1593150230'), ('X-OAuth-Scopes', 'admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, read:packages, repo, user, workflow, write:discussion, write:packages'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Vary', 'Accept-Encoding, Accept, X-Requested-With'), ('X-GitHub-Request-Id', '9B56:4D5E:1A2549:1E86BB:5EF581DF')]
|
||||
{}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
https
|
||||
POST
|
||||
api.github.com
|
||||
None
|
||||
/repos/PyGithub/PyGithub/actions/runs/148274629/rerun
|
||||
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
|
||||
None
|
||||
201
|
||||
[('Date', 'Fri, 26 Jun 2020 05:04:31 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Content-Length', '2'), ('Server', 'GitHub.com'), ('Status', '201 Created'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4949'), ('X-RateLimit-Reset', '1593150230'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding'), ('ETag', '"f4f61bef4e0189176324081da79fde4b"'), ('X-OAuth-Scopes', 'admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, read:packages, repo, user, workflow, write:discussion, write:packages'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('X-GitHub-Request-Id', '9B54:4D5E:1A253C:1E86A7:5EF581DF')]
|
||||
{}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
https
|
||||
GET
|
||||
api.github.com
|
||||
None
|
||||
/repos/PyGithub/PyGithub/actions/runs/148274629/timing
|
||||
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
|
||||
None
|
||||
200
|
||||
[('Date', 'Fri, 26 Jun 2020 05:25:09 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Server', 'GitHub.com'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4935'), ('X-RateLimit-Reset', '1593150231'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With, Accept-Encoding'), ('ETag', 'W/"d5c60782b947caaf365ec6da07f69a32"'), ('X-OAuth-Scopes', 'admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete:packages, delete_repo, gist, notifications, read:packages, repo, user, workflow, write:discussion, write:packages'), ('X-Accepted-OAuth-Scopes', ''), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip'), ('X-GitHub-Request-Id', '9F74:5067:1B8264:1FF1A4:5EF586B5')]
|
||||
{"billable":{},"run_duration_ms":105000}
|
||||
|
||||
@@ -966,6 +966,13 @@ class Repository(Framework.TestCase):
|
||||
workflows, lambda w: w.name, ["check", "Publish to PyPI"]
|
||||
)
|
||||
|
||||
def testGetWorkflowRuns(self):
|
||||
self.assertListKeyEqual(
|
||||
self.g.get_repo("PyGithub/PyGithub").get_workflow_runs(),
|
||||
lambda r: r.id,
|
||||
[110932306, 110932159, 110932072, 110286191, 110278769],
|
||||
)
|
||||
|
||||
def testGetSourceImport(self):
|
||||
import_repo = self.g.get_user("brix4dayz").get_repo("source-import-test")
|
||||
source_import = import_repo.get_source_import()
|
||||
|
||||
@@ -56,3 +56,28 @@ class Workflow(Framework.TestCase):
|
||||
self.workflow.badge_url,
|
||||
"https://github.com/PyGithub/PyGithub/workflows/check/badge.svg",
|
||||
)
|
||||
|
||||
def testGetRunsWithNoArguments(self):
|
||||
self.assertListKeyEqual(
|
||||
self.workflow.get_runs(),
|
||||
lambda r: r.id,
|
||||
[109950033, 109168419, 108934155, 108817672],
|
||||
)
|
||||
|
||||
def testGetRunsWithObjects(self):
|
||||
sfdye = self.g.get_user("sfdye")
|
||||
master = self.g.get_repo("PyGithub/PyGithub").get_branch("master")
|
||||
self.assertListKeyEqual(
|
||||
self.workflow.get_runs(
|
||||
actor=sfdye, branch=master, event="push", status="completed"
|
||||
),
|
||||
lambda r: r.id,
|
||||
[100957683, 94845611, 93946842, 92714488],
|
||||
)
|
||||
|
||||
def testGetRunsWithStrings(self):
|
||||
self.assertListKeyEqual(
|
||||
self.workflow.get_runs(actor="s-t-e-v-e-n-k", branch="master"),
|
||||
lambda r: r.id,
|
||||
[109950033, 108817672, 108794468, 107927403, 105213061, 105212023],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
############################ Copyrights and license ############################
|
||||
# #
|
||||
# Copyright 2020 Steve Kowalik <steven@wedontsleep.org> #
|
||||
# #
|
||||
# This file is part of PyGithub. #
|
||||
# http://pygithub.readthedocs.io/ #
|
||||
# #
|
||||
# PyGithub is free software: you can redistribute it and/or modify it under #
|
||||
# the terms of the GNU Lesser General Public License as published by the Free #
|
||||
# Software Foundation, either version 3 of the License, or (at your option) #
|
||||
# any later version. #
|
||||
# #
|
||||
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
|
||||
# details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Lesser General Public License #
|
||||
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
import datetime
|
||||
|
||||
from . import Framework
|
||||
|
||||
|
||||
class WorkflowRun(Framework.TestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.repo = self.g.get_repo("PyGithub/PyGithub")
|
||||
self.workflow_run = self.repo.get_workflow_run(148274629)
|
||||
|
||||
def testAttributes(self):
|
||||
self.assertEqual(
|
||||
repr(self.workflow_run),
|
||||
'WorkflowRun(url="https://api.github.com/repos/PyGithub/PyGithub/actions/runs/148274629", id=148274629)',
|
||||
)
|
||||
self.assertEqual(self.workflow_run.id, 148274629)
|
||||
self.assertEqual(self.workflow_run.head_branch, "more-precise-typing")
|
||||
self.assertEqual(
|
||||
self.workflow_run.head_sha, "f91c729d786efcc93db47dd755313a26172c105e"
|
||||
)
|
||||
self.assertEqual(self.workflow_run.run_number, 162)
|
||||
self.assertEqual(self.workflow_run.event, "pull_request")
|
||||
self.assertEqual(self.workflow_run.status, "completed")
|
||||
self.assertEqual(self.workflow_run.conclusion, "failure")
|
||||
self.assertEqual(
|
||||
self.workflow_run.url,
|
||||
"https://api.github.com/repos/PyGithub/PyGithub/actions/runs/148274629",
|
||||
)
|
||||
self.assertEqual(
|
||||
self.workflow_run.html_url,
|
||||
"https://github.com/PyGithub/PyGithub/actions/runs/148274629",
|
||||
)
|
||||
self.assertEqual(self.workflow_run.pull_requests, [])
|
||||
created_at = datetime.datetime(2020, 6, 26, 4, 51, 26)
|
||||
self.assertEqual(self.workflow_run.created_at, created_at)
|
||||
updated_at = datetime.datetime(2020, 6, 26, 4, 52, 59)
|
||||
self.assertEqual(self.workflow_run.updated_at, updated_at)
|
||||
self.assertEqual(
|
||||
self.workflow_run.jobs_url,
|
||||
"https://api.github.com/repos/PyGithub/PyGithub/actions/runs/148274629/jobs",
|
||||
)
|
||||
self.assertEqual(
|
||||
self.workflow_run.logs_url,
|
||||
"https://api.github.com/repos/PyGithub/PyGithub/actions/runs/148274629/logs",
|
||||
)
|
||||
self.assertEqual(
|
||||
self.workflow_run.check_suite_url,
|
||||
"https://api.github.com/repos/PyGithub/PyGithub/check-suites/843925976",
|
||||
)
|
||||
self.assertEqual(
|
||||
self.workflow_run.artifacts_url,
|
||||
"https://api.github.com/repos/PyGithub/PyGithub/actions/runs/148274629/artifacts",
|
||||
)
|
||||
self.assertEqual(
|
||||
self.workflow_run.cancel_url,
|
||||
"https://api.github.com/repos/PyGithub/PyGithub/actions/runs/148274629/cancel",
|
||||
)
|
||||
self.assertEqual(
|
||||
self.workflow_run.rerun_url,
|
||||
"https://api.github.com/repos/PyGithub/PyGithub/actions/runs/148274629/rerun",
|
||||
)
|
||||
self.assertEqual(
|
||||
self.workflow_run.workflow_url,
|
||||
"https://api.github.com/repos/PyGithub/PyGithub/actions/workflows/1026390",
|
||||
)
|
||||
self.assertEqual(self.workflow_run.head_commit.message, "More precise typing")
|
||||
self.assertEqual(self.workflow_run.repository.name, "PyGithub")
|
||||
self.assertEqual(self.workflow_run.head_repository.name, "PyGithub")
|
||||
|
||||
def test_timing(self):
|
||||
timing = self.workflow_run.timing()
|
||||
self.assertEqual(timing.billable, {})
|
||||
self.assertEqual(timing.run_duration_ms, 105000)
|
||||
|
||||
def test_rerun(self):
|
||||
self.assertTrue(self.workflow_run.rerun())
|
||||
|
||||
def test_rerun_with_successful_run(self):
|
||||
wr = self.repo.get_workflow_run(145732882)
|
||||
self.assertFalse(wr.rerun())
|
||||
|
||||
def test_cancel(self):
|
||||
self.assertTrue(self.workflow_run.cancel())
|
||||
Reference in New Issue
Block a user