|
19 | 19 | """Verification orchestration and summary display.""" |
20 | 20 |
|
21 | 21 | import tempfile |
| 22 | +import webbrowser |
22 | 23 | from pathlib import Path |
23 | 24 |
|
24 | 25 | from rich.panel import Panel |
@@ -112,6 +113,55 @@ def show_verification_summary( |
112 | 113 | console.print(nested_table) |
113 | 114 |
|
114 | 115 |
|
| 116 | +def offer_open_and_approve( |
| 117 | + org: str, repo: str, commit_hash: str, sub_path: str = "", |
| 118 | + ci_mode: bool = False, |
| 119 | +) -> str | None: |
| 120 | + """Offer to open the action in a browser and/or approve it. |
| 121 | +
|
| 122 | + Returns "approve" if the user chose to approve, None otherwise. |
| 123 | + """ |
| 124 | + if ci_mode: |
| 125 | + return None |
| 126 | + |
| 127 | + action_url = f"https://github.com/{org}/{repo}/tree/{commit_hash}" |
| 128 | + if sub_path: |
| 129 | + action_url += f"/{sub_path}" |
| 130 | + |
| 131 | + urls = [ |
| 132 | + ("Source tree", action_url), |
| 133 | + ("Commit", f"https://github.com/{org}/{repo}/commit/{commit_hash}"), |
| 134 | + ("Repository", f"https://github.com/{org}/{repo}"), |
| 135 | + ] |
| 136 | + |
| 137 | + console.print() |
| 138 | + console.print("[bold]Quick links:[/bold]") |
| 139 | + for label, url in urls: |
| 140 | + console.print(f" [link={url}]{label}: {url}[/link]") |
| 141 | + |
| 142 | + console.print() |
| 143 | + console.print( |
| 144 | + " [bold]o[/bold] = open in browser, " |
| 145 | + "[bold]a[/bold] = approve action, " |
| 146 | + "[bold]Enter[/bold]/[bold]q[/bold] = done" |
| 147 | + ) |
| 148 | + |
| 149 | + while True: |
| 150 | + try: |
| 151 | + choice = console.input(" > ").strip().lower() |
| 152 | + except EOFError: |
| 153 | + break |
| 154 | + if choice == "o": |
| 155 | + webbrowser.open(action_url) |
| 156 | + console.print(" [dim]Opened in browser[/dim]") |
| 157 | + continue |
| 158 | + if choice == "a": |
| 159 | + return "approve" |
| 160 | + break |
| 161 | + |
| 162 | + return None |
| 163 | + |
| 164 | + |
115 | 165 | def verify_single_action( |
116 | 166 | action_ref: str, gh: GitHubClient | None = None, ci_mode: bool = False, |
117 | 167 | cache: bool = True, show_build_steps: bool = False, |
@@ -303,4 +353,6 @@ def verify_single_action( |
303 | 353 | ) |
304 | 354 | ) |
305 | 355 |
|
| 356 | + offer_open_and_approve(org, repo, commit_hash, sub_path, ci_mode=ci_mode) |
| 357 | + |
306 | 358 | return all_match |
0 commit comments