Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #234: GitHub action api verification #246

Merged
merged 20 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pykern/pkcli/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""
from __future__ import absolute_import, division, print_function
from pykern import pkcli
from pykern import pkconfig
from pykern import pkio
from pykern import pkjson
Expand Down Expand Up @@ -49,6 +50,31 @@ def backup():
pkdlog("DONE")


def ci_check(repo, branch=None):
def _branch(r, name, reraise=True):
try:
return r.branch(name=name)
except github3.exceptions.NotFoundError:
if reraise:
raise
rorour marked this conversation as resolved.
Show resolved Hide resolved
return None

r = _repo_arg(repo)
b = (
_branch(r, branch)
if branch
else _branch(r, "master", False) or _branch(r, "main")
)
s = b.commit.sha
rorour marked this conversation as resolved.
Show resolved Hide resolved
c = [c.conclusion for c in b.commit.check_runs()]
i = f"branch={b.name} sha={s}"
if not c:
pkcli.command_error(f"{i} No workflow runs for commit")
if c[0] != "success":
pkcli.command_error(f"{i} Unsuccessful conclusion={c}")
return f"{i} Passed CI"


def collaborators(org, filename, affiliation="outside", private=True):
"""Lists direct repos to which user has access and is not a team member

Expand Down
2 changes: 1 addition & 1 deletion pykern/pkconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Required(tuple, object):

cfg = pkconfig.init(
any_param=(1, int, 'A parameter with a default'),
needed=pkconfig.Required(int, 'A parameter with a default'),
needed=pkconfig.Required(int, 'A parameter without a default'),
)

Args:
Expand Down