Created
June 23, 2025 10:57
-
-
Save stormslowly/c08fc5fe8cf65017e26f49961a447520 to your computer and use it in GitHub Desktop.
list workflow according to current github repo's branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import subprocess | |
import json | |
import os | |
def run(cmd): | |
return subprocess.check_output(cmd, shell=True, text=True).strip() | |
def main(): | |
branch = run("git rev-parse --abbrev-ref HEAD") | |
raw = run(f'gh api -X GET repos/:owner/:repo/actions/runs -F branch={branch} -F per_page=200') | |
runs = json.loads(raw)["workflow_runs"] | |
# 以 workflow name 去重,只保留最新一条 | |
latest_by_name = {} | |
for run_obj in sorted(runs, key=lambda x: x["created_at"], reverse=True): | |
name = run_obj["name"] | |
if name not in latest_by_name: | |
latest_by_name[name] = run_obj | |
entries = [] | |
for run_obj in sorted(latest_by_name.values(), key=lambda x: x["name"]): | |
name = run_obj["name"] | |
sha = run_obj["head_sha"][:7] | |
status = run_obj["conclusion"] or run_obj["status"] | |
time = run_obj["created_at"] | |
url = run_obj["html_url"] | |
entries.append(f"{name:<30} {status:<10} {sha} {time} {url}") | |
if not entries: | |
print("No workflow runs found.") | |
return | |
# pipe to fzf | |
try: | |
selected = run(f'printf "%s\n" "{chr(10).join(entries)}" | fzf') | |
url = selected.split()[-1] | |
run(f'open "{url}"' if os.name == "posix" else f'start {url}') | |
except subprocess.CalledProcessError: | |
print("No selection made.") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment