Added support for Repository.get_workflow_runs parameters (#1682)

* Added support for `Repository.get_workflow_runs` parameters

* Added anchor tag to docstring link

* Tests
This commit is contained in:
Victor Zeng
2020-10-28 13:37:59 +11:00
committed by GitHub
parent ee4c7a7e9e
commit c23564ddbd
6 changed files with 221 additions and 13 deletions
+53 -13
View File
@@ -3015,19 +3015,6 @@ 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>`_
@@ -3041,6 +3028,59 @@ class Repository(github.GithubObject.CompletableGithubObject):
)
return github.Workflow.Workflow(self._requester, headers, data, completed=True)
def get_workflow_runs(
self,
actor=github.GithubObject.NotSet,
branch=github.GithubObject.NotSet,
event=github.GithubObject.NotSet,
status=github.GithubObject.NotSet,
):
"""
:calls: `GET /repos/:owner/:repo/actions/runs <https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs-for-a-repository>`_
:param actor: :class:`github.NamedUser.NamedUser` or string
:param branch: :class:`github.Branch.Branch` or string
:param event: string
:param status: string `queued`, `in_progress`, `completed`, `success`, `failure`, `neutral`, `cancelled`, `skipped`, `timed_out`, or `action_required`
: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:
if isinstance(actor, github.NamedUser.NamedUser):
url_parameters["actor"] = actor._identity
else:
url_parameters["actor"] = actor
if branch is not github.GithubObject.NotSet:
if isinstance(branch, github.Branch.Branch):
url_parameters["branch"] = branch.name
else:
url_parameters["branch"] = 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 + "/actions/runs",
url_parameters,
list_item="workflow_runs",
)
def get_workflow_run(self, id_):
"""
:calls: `GET /repos/:owner/:repo/actions/runs/:run_id <https://developer.github.com/v3/actions/workflow-runs>`_
+58
View File
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
############################ Copyrights and license ############################
# #
# Copyright 2020 Victor Zeng <zacker150@hotmail.com> #
# #
# 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 . import Framework
class PullRequest1682(Framework.TestCase):
def setUp(self):
super().setUp()
self.repo = self.g.get_repo("ReDASers/Phishing-Detection")
def test_no_parameters(self):
runs = self.repo.get_workflow_runs()
self.assertEqual(313400760, runs[0].id)
def test_object_parameters(self):
branch = self.repo.get_branch("adversary")
runs = self.repo.get_workflow_runs(branch=branch)
self.assertEqual(204764033, runs[0].id)
self.assertEqual(1, runs.totalCount)
user = self.g.get_user("shahryarabaki")
runs = self.repo.get_workflow_runs(actor=user)
self.assertEqual(28372848, runs[0].id)
def test_string_parameters(self):
runs = self.repo.get_workflow_runs(actor="xzhou29")
self.assertEqual(226142695, runs[0].id)
runs = self.repo.get_workflow_runs(branch="API_Flatten")
self.assertEqual(287515889, runs[0].id)
runs = self.repo.get_workflow_runs(event="pull_request")
self.assertEqual(298867254, runs[0].id)
runs = self.repo.get_workflow_runs(status="failure")
self.assertEqual(292080359, runs[0].id)
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