Skip to content

Commit 2b7bd80

Browse files
authored
Merge pull request #671 from apache/offer-open-and-approve
Add interactive open-in-browser and approve flow
2 parents 4deec7d + 3f8fb8f commit 2b7bd80

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

utils/verify_action_build/verification.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"""Verification orchestration and summary display."""
2020

2121
import tempfile
22+
import webbrowser
2223
from pathlib import Path
2324

2425
from rich.panel import Panel
@@ -112,6 +113,55 @@ def show_verification_summary(
112113
console.print(nested_table)
113114

114115

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+
115165
def verify_single_action(
116166
action_ref: str, gh: GitHubClient | None = None, ci_mode: bool = False,
117167
cache: bool = True, show_build_steps: bool = False,
@@ -303,4 +353,6 @@ def verify_single_action(
303353
)
304354
)
305355

356+
offer_open_and_approve(org, repo, commit_hash, sub_path, ci_mode=ci_mode)
357+
306358
return all_match

0 commit comments

Comments
 (0)