Skip to content

Commit 09d78b8

Browse files
committed
Added branch argument
1 parent 0ae198b commit 09d78b8

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

tools/ci_status.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,27 @@
2929
def run_gh_rest_check(
3030
lib_repo: Repository,
3131
user: Optional[str] = None,
32+
branch: Optional[str] = "main",
3233
workflow_filename: Optional[str] = "build.yml",
3334
) -> str:
3435
"""Uses ``PyGithub`` to check the CI status of a repository
3536
3637
:param Repository lib_repo: The repo as a github.Repository.Repository object
3738
:param str|None user: The user that triggered the run; if `None` is
3839
provided, any user is acceptable
40+
:param str|None branch: The branch name to specifically check; if `None` is
41+
provided, all branches are allowed; the default is ``"main"``
3942
:param str|None workflow_filename: The filename of the workflow; if `None` is
40-
provided, any workflow name is acceptable; the default is `"build.yml"`
43+
provided, any workflow name is acceptable; the default is ``"build.yml"``
4144
:return: The requested runs conclusion
4245
:rtype: str
4346
"""
4447

4548
arg_dict = {}
4649
if user is not None:
4750
arg_dict["actor"] = user
51+
if branch is not None:
52+
arg_dict["branch"] = branch
4853

4954
workflow: Workflow = lib_repo.get_workflow(workflow_filename)
5055
workflow_runs = workflow.get_runs(**arg_dict)
@@ -54,6 +59,7 @@ def run_gh_rest_check(
5459
def check_build_status(
5560
lib_repo: Repository,
5661
user: Optional[str] = None,
62+
branch: Optional[str] = "main",
5763
workflow_filename: Optional[str] = "build.yml",
5864
debug: bool = False,
5965
) -> Optional[str]:
@@ -63,6 +69,8 @@ def check_build_status(
6369
:param Repository lib_repo: The repo as a github.Repository.Repository object
6470
:param str|None user: The user that triggered the run; if `None` is
6571
provided, any user is acceptable
72+
:param str|None branch: The branch name to specifically check; if `None` is
73+
provided, all branches are allowed; the default is ``"main"``
6674
:param str|None workflow_filename: The filename of the workflow; if `None`
6775
is provided, any workflow name is acceptable; the defail is `"build.yml"`
6876
:param bool debug: Whether debug statements should be printed to the standard
@@ -79,7 +87,9 @@ def check_build_status(
7987
return True
8088

8189
try:
82-
result = run_gh_rest_check(lib_repo, user, workflow_filename) == "success"
90+
result = (
91+
run_gh_rest_check(lib_repo, user, branch, workflow_filename) == "success"
92+
)
8393
if debug and not result:
8494
print("***", "Library", lib_repo.name, "failed the patch!", "***")
8595
return result
@@ -98,6 +108,7 @@ def check_build_status(
98108
def check_build_statuses(
99109
gh_token: str,
100110
user: Optional[str] = None,
111+
branch: Optional[str] = "main",
101112
workflow_filename: Optional[str] = "build.yml",
102113
*,
103114
debug: bool = False,
@@ -108,6 +119,8 @@ def check_build_statuses(
108119
:param str gh_token: The Github token to be used for with the Github API
109120
:param str|None user: The user that triggered the run; if `None` is
110121
provided, any user is acceptable
122+
:param str|None branch: The branch name to specifically check; if `None` is
123+
provided, all branches are allowed; the default is ``"main"``
111124
:param str|None workflow_filename: The filename of the workflow; if `None` is
112125
provided, any workflow name is acceptable; the defail is `"build.yml"`
113126
:param bool debug: Whether debug statements should be printed to
@@ -118,7 +131,8 @@ def check_build_statuses(
118131
"""
119132

120133
return iter_remote_bundle_with_func(
121-
gh_token, [(check_build_status, (user, workflow_filename), {"debug": debug})]
134+
gh_token,
135+
[(check_build_status, (user, branch, workflow_filename), {"debug": debug})],
122136
)
123137

124138

@@ -160,6 +174,14 @@ def save_build_statuses(
160174
default=None,
161175
help="Select a specific user that triggered the workflow",
162176
)
177+
parser.add_argument(
178+
"--branch",
179+
metavar="B",
180+
type=str,
181+
dest="branch",
182+
default="main",
183+
help='Branch name; default is "main"',
184+
)
163185
parser.add_argument(
164186
"--workflow",
165187
metavar="W",
@@ -175,7 +197,7 @@ def save_build_statuses(
175197
args = parser.parse_args()
176198

177199
results = check_build_statuses(
178-
args.gh_token, args.user, args.workflow, debug=args.debug
200+
args.gh_token, args.user, args.branch, args.workflow, debug=args.debug
179201
)
180202
fail_list = [
181203
repo_name.name for repo_name, repo_results in results if not repo_results[0]

0 commit comments

Comments
 (0)