Skip to content

Commit c23564d

Browse files
authored
Added support for Repository.get_workflow_runs parameters (PyGithub#1682)
* Added support for `Repository.get_workflow_runs` parameters * Added anchor tag to docstring link * Tests
1 parent ee4c7a7 commit c23564d

6 files changed

+221
-13
lines changed

github/Repository.py

+53-13
Original file line numberDiff line numberDiff line change
@@ -3015,19 +3015,6 @@ def get_workflows(self):
30153015
list_item="workflows",
30163016
)
30173017

3018-
def get_workflow_runs(self):
3019-
"""
3020-
:calls: `GET /repos/:owner/:repo/actions/runs <https://developer.github.com/v3/actions/workflow-runs>`_
3021-
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.WorkflowRun.WorkflowRun`
3022-
"""
3023-
return github.PaginatedList.PaginatedList(
3024-
github.WorkflowRun.WorkflowRun,
3025-
self._requester,
3026-
self.url + "/actions/runs",
3027-
None,
3028-
list_item="workflow_runs",
3029-
)
3030-
30313018
def get_workflow(self, id_or_name):
30323019
"""
30333020
:calls: `GET /repos/:owner/:repo/actions/workflows/:workflow_id <https://developer.github.com/v3/actions/workflows>`_
@@ -3041,6 +3028,59 @@ def get_workflow(self, id_or_name):
30413028
)
30423029
return github.Workflow.Workflow(self._requester, headers, data, completed=True)
30433030

3031+
def get_workflow_runs(
3032+
self,
3033+
actor=github.GithubObject.NotSet,
3034+
branch=github.GithubObject.NotSet,
3035+
event=github.GithubObject.NotSet,
3036+
status=github.GithubObject.NotSet,
3037+
):
3038+
"""
3039+
:calls: `GET /repos/:owner/:repo/actions/runs <https://developer.github.com/v3/actions/workflow-runs/#list-workflow-runs-for-a-repository>`_
3040+
:param actor: :class:`github.NamedUser.NamedUser` or string
3041+
:param branch: :class:`github.Branch.Branch` or string
3042+
:param event: string
3043+
:param status: string `queued`, `in_progress`, `completed`, `success`, `failure`, `neutral`, `cancelled`, `skipped`, `timed_out`, or `action_required`
3044+
3045+
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.WorkflowRun.WorkflowRun`
3046+
"""
3047+
assert (
3048+
actor is github.GithubObject.NotSet
3049+
or isinstance(actor, github.NamedUser.NamedUser)
3050+
or isinstance(actor, str)
3051+
), actor
3052+
assert (
3053+
branch is github.GithubObject.NotSet
3054+
or isinstance(branch, github.Branch.Branch)
3055+
or isinstance(branch, str)
3056+
), branch
3057+
assert event is github.GithubObject.NotSet or isinstance(event, str), event
3058+
assert status is github.GithubObject.NotSet or isinstance(status, str), status
3059+
3060+
url_parameters = dict()
3061+
if actor is not github.GithubObject.NotSet:
3062+
if isinstance(actor, github.NamedUser.NamedUser):
3063+
url_parameters["actor"] = actor._identity
3064+
else:
3065+
url_parameters["actor"] = actor
3066+
if branch is not github.GithubObject.NotSet:
3067+
if isinstance(branch, github.Branch.Branch):
3068+
url_parameters["branch"] = branch.name
3069+
else:
3070+
url_parameters["branch"] = branch
3071+
if event is not github.GithubObject.NotSet:
3072+
url_parameters["event"] = event
3073+
if status is not github.GithubObject.NotSet:
3074+
url_parameters["status"] = status
3075+
3076+
return github.PaginatedList.PaginatedList(
3077+
github.WorkflowRun.WorkflowRun,
3078+
self._requester,
3079+
self.url + "/actions/runs",
3080+
url_parameters,
3081+
list_item="workflow_runs",
3082+
)
3083+
30443084
def get_workflow_run(self, id_):
30453085
"""
30463086
:calls: `GET /repos/:owner/:repo/actions/runs/:run_id <https://developer.github.com/v3/actions/workflow-runs>`_

tests/PullRequest1682.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# -*- coding: utf-8 -*-
2+
3+
############################ Copyrights and license ############################
4+
# #
5+
# Copyright 2020 Victor Zeng <[email protected]> #
6+
# #
7+
# This file is part of PyGithub. #
8+
# http://pygithub.readthedocs.io/ #
9+
# #
10+
# PyGithub is free software: you can redistribute it and/or modify it under #
11+
# the terms of the GNU Lesser General Public License as published by the Free #
12+
# Software Foundation, either version 3 of the License, or (at your option) #
13+
# any later version. #
14+
# #
15+
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
16+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
17+
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
18+
# details. #
19+
# #
20+
# You should have received a copy of the GNU Lesser General Public License #
21+
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
22+
# #
23+
################################################################################
24+
25+
from . import Framework
26+
27+
28+
class PullRequest1682(Framework.TestCase):
29+
def setUp(self):
30+
super().setUp()
31+
self.repo = self.g.get_repo("ReDASers/Phishing-Detection")
32+
33+
def test_no_parameters(self):
34+
runs = self.repo.get_workflow_runs()
35+
self.assertEqual(313400760, runs[0].id)
36+
37+
def test_object_parameters(self):
38+
branch = self.repo.get_branch("adversary")
39+
runs = self.repo.get_workflow_runs(branch=branch)
40+
self.assertEqual(204764033, runs[0].id)
41+
self.assertEqual(1, runs.totalCount)
42+
43+
user = self.g.get_user("shahryarabaki")
44+
runs = self.repo.get_workflow_runs(actor=user)
45+
self.assertEqual(28372848, runs[0].id)
46+
47+
def test_string_parameters(self):
48+
runs = self.repo.get_workflow_runs(actor="xzhou29")
49+
self.assertEqual(226142695, runs[0].id)
50+
51+
runs = self.repo.get_workflow_runs(branch="API_Flatten")
52+
self.assertEqual(287515889, runs[0].id)
53+
54+
runs = self.repo.get_workflow_runs(event="pull_request")
55+
self.assertEqual(298867254, runs[0].id)
56+
57+
runs = self.repo.get_workflow_runs(status="failure")
58+
self.assertEqual(292080359, runs[0].id)
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
https
2+
GET
3+
api.github.com
4+
None
5+
/repos/ReDASers/Phishing-Detection
6+
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
7+
None
8+
200
9+
[('Server', 'GitHub.com'), ('Date', 'Tue, 27 Oct 2020 20:01:34 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Status', '200 OK'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', 'W/"3f57c3bc8bc24a574b14be5562a6807a14b95ece2301de951d8234cacea234ed"'), ('Last-Modified', 'Sat, 10 Oct 2020 08:06:04 GMT'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4909'), ('X-RateLimit-Reset', '1603831065'), ('X-RateLimit-Used', '91'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, 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', 'F14D:4B2E:23C90:6072E:5F987C9E')]
10+
{"id":146139403,"node_id":"MDEwOlJlcG9zaXRvcnkxNDYxMzk0MDM=","name":"Phishing-Detection","full_name":"ReDASers/Phishing-Detection","private":true,"owner":{"login":"ReDASers","id":67067070,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY3MDY3MDcw","avatar_url":"https://avatars0.githubusercontent.com/u/67067070?v=4","gravatar_id":"","url":"https://api.github.com/users/ReDASers","html_url":"https://github.com/ReDASers","followers_url":"https://api.github.com/users/ReDASers/followers","following_url":"https://api.github.com/users/ReDASers/following{/other_user}","gists_url":"https://api.github.com/users/ReDASers/gists{/gist_id}","starred_url":"https://api.github.com/users/ReDASers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReDASers/subscriptions","organizations_url":"https://api.github.com/users/ReDASers/orgs","repos_url":"https://api.github.com/users/ReDASers/repos","events_url":"https://api.github.com/users/ReDASers/events{/privacy}","received_events_url":"https://api.github.com/users/ReDASers/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/ReDASers/Phishing-Detection","description":"A customizable benchmarking framework for phishing research. ","fork":false,"url":"https://api.github.com/repos/ReDASers/Phishing-Detection","forks_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/forks","keys_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/teams","hooks_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/hooks","issue_events_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/issues/events{/number}","events_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/events","assignees_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/assignees{/user}","branches_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/branches{/branch}","tags_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/tags","blobs_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/git/refs{/sha}","trees_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/statuses/{sha}","languages_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/languages","stargazers_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/stargazers","contributors_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/contributors","subscribers_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/subscribers","subscription_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/subscription","commits_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/commits{/sha}","git_commits_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/git/commits{/sha}","comments_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/comments{/number}","issue_comment_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/issues/comments{/number}","contents_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/contents/{+path}","compare_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/merges","archive_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/downloads","issues_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/issues{/number}","pulls_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/pulls{/number}","milestones_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/milestones{/number}","notifications_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/labels{/name}","releases_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/releases{/id}","deployments_url":"https://api.github.com/repos/ReDASers/Phishing-Detection/deployments","created_at":"2018-08-26T00:30:13Z","updated_at":"2020-10-10T08:06:04Z","pushed_at":"2020-10-18T06:42:23Z","git_url":"git://github.com/ReDASers/Phishing-Detection.git","ssh_url":"[email protected]:ReDASers/Phishing-Detection.git","clone_url":"https://github.com/ReDASers/Phishing-Detection.git","svn_url":"https://github.com/ReDASers/Phishing-Detection","homepage":"","size":30731,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":11,"license":null,"forks":1,"open_issues":11,"watchers":1,"default_branch":"master","permissions":{"admin":true,"push":true,"pull":true},"temp_clone_token":"ABZLTTAMCWRKWXDZRJKUCUC7TB64U","allow_squash_merge":true,"allow_merge_commit":false,"allow_rebase_merge":true,"delete_branch_on_merge":false,"organization":{"login":"ReDASers","id":67067070,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY3MDY3MDcw","avatar_url":"https://avatars0.githubusercontent.com/u/67067070?v=4","gravatar_id":"","url":"https://api.github.com/users/ReDASers","html_url":"https://github.com/ReDASers","followers_url":"https://api.github.com/users/ReDASers/followers","following_url":"https://api.github.com/users/ReDASers/following{/other_user}","gists_url":"https://api.github.com/users/ReDASers/gists{/gist_id}","starred_url":"https://api.github.com/users/ReDASers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReDASers/subscriptions","organizations_url":"https://api.github.com/users/ReDASers/orgs","repos_url":"https://api.github.com/users/ReDASers/repos","events_url":"https://api.github.com/users/ReDASers/events{/privacy}","received_events_url":"https://api.github.com/users/ReDASers/received_events","type":"Organization","site_admin":false},"network_count":1,"subscribers_count":1}
11+

tests/ReplayData/PullRequest1682.test_no_parameters.txt

+11
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)