Skip to content

Commit ec3dc33

Browse files
fix: use stable PR route for webview links
Amp-Thread-ID: https://ampcode.com/threads/T-019fd419-4685-7716-9fc1-72028e39526a Co-authored-by: Ivan Milev <ivanmilevtues@gmail.com>
1 parent d6e869d commit ec3dc33

4 files changed

Lines changed: 31 additions & 46 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ Review mode does not need `contents: write`: PR-specific generated files are sto
316316
| `comment_header` | review | `Architecture review` | Heading for the PR comment. |
317317
| `trigger_command` | review | `/codeboarding` | Slash command for trusted on-demand runs. |
318318
| `cta_base_url` | review | empty | Click-proxy base URL: deep-links the editor link into VS Code/Cursor and adds a "get the extension" link (tracks owner/repo/pr). Empty links to the extension listing instead (GitHub strips `vscode:`/`cursor:` from comments). |
319-
| `webview_base_url` | review | `https://app.codeboarding.org` | Hosted webview base URL. The PR comment links to an artifact-backed head-vs-comparison-branch architecture diff. Set empty to disable the browser link. |
319+
| `webview_base_url` | review | `https://app.codeboarding.org` | Hosted webview base URL. The PR comment uses the stable `/{owner}/{repo}/pull/{pr}` route for an artifact-backed head-vs-comparison-branch architecture diff. Set empty to disable the browser link. |
320320
| `output_dir` | sync | `.codeboarding` | Directory the rendered docs and analysis metadata are committed to. Owned by the action: pre-existing top-level `.md` files in it are deleted on every run. |
321321
| `output_format` | sync | `.md` | Output format. Only `.md` is supported. |
322322
| `target_branch` | sync | `${{ github.ref_name }}` | In `push` strategy, the branch the docs are pushed to. In `pull_request` strategy, the PR base branch. |

‎action.yml‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ inputs:
6868
required: false
6969
default: ''
7070
webview_base_url:
71-
description: 'Review mode: hosted webview base URL. The PR comment links to an artifact-backed head-vs-comparison-branch architecture diff; review mode does not commit generated files to PR branches. Set empty to disable the browser link.'
71+
description: 'Review mode: hosted webview base URL. The PR comment uses the stable /{owner}/{repo}/pull/{pr} route for an artifact-backed head-vs-comparison-branch architecture diff; review mode does not commit generated files to PR branches. Set empty to disable the browser link.'
7272
required: false
7373
default: 'https://app.codeboarding.org'
7474
trigger_command:
@@ -1322,7 +1322,6 @@ runs:
13221322
DIAGRAM_MD: ${{ steps.diagram.outputs.diagram_md }}
13231323
BASE_ANALYSIS: ${{ steps.analyze.outputs.base_analysis }}
13241324
HEAD_ANALYSIS: ${{ steps.analyze.outputs.head_analysis }}
1325-
RUN_ID: ${{ github.run_id }}
13261325
CHANGED_COUNT: ${{ steps.diagram.outputs.n_changed }}
13271326
CHANGED: ${{ steps.diagram.outputs.changed }}
13281327
RENDERED: ${{ steps.diagram.outputs.rendered }}
@@ -1351,13 +1350,12 @@ runs:
13511350
cta() {
13521351
local extra=()
13531352
# ARTIFACT_NAME presence is the readiness gate (an analysis artifact was
1354-
# uploaded for this run). The short webview link itself needs only the run id
1355-
# — the webview re-derives head/base/artifact from the run + its metadata.
1353+
# uploaded for this run). The stable webview link identifies the repository
1354+
# and PR; the webview resolves their latest artifact.
13561355
if [ -n "$WEBVIEW_BASE" ] && [ -n "$ARTIFACT_NAME" ]; then
13571356
extra+=(
13581357
--webview-ready
13591358
--webview-base "$WEBVIEW_BASE"
1360-
--run-id "$RUN_ID"
13611359
)
13621360
fi
13631361
python3 "$ACTION_PATH/scripts/build_cta.py" \

‎scripts/build_cta.py‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
VS Code" — that merges the hosted-webview link with the editor link(s), preceded by
55
a warning banner when real health findings exist. The "browser" link (a no-install
66
hosted webview) is included only when ``webview_ready``; it's a short GitHub-style
7-
link (``/owner/repo/pull/<pr>?run=<run_id>``) that the webview resolves to this PR's
8-
uploaded analysis artifact for the run. With a click proxy (``cta_base``) the
7+
link (``/owner/repo/pull/<pr>``) that the webview resolves to this PR's latest
8+
uploaded analysis artifact. With a click proxy (``cta_base``) the
99
editor link routes through it (owner/repo/pr tracked) and deep-links into the editor
1010
(the proxy redirects to a ``vscode:``/``cursor:`` URL), and a separate "install the
1111
extension" link is appended. Without a proxy GitHub's comment sanitizer strips custom
@@ -66,19 +66,17 @@ def webview_url(
6666
repo: str,
6767
*,
6868
pr: str = "",
69-
run_id: str = "",
7069
) -> str | None:
7170
"""Return the hosted-webview PR deep-link, or None.
7271
73-
A GitHub-style short link: ``{base}/{owner}/{repo}/pull/{pr}?run={run_id}``. The
74-
webview re-derives the head SHA, base SHA, and artifact name from the workflow
75-
run's uploaded artifact (+ its metadata.json), so the link carries only the PR
76-
number and the run id — short, and stable across re-runs.
72+
A stable GitHub-style short link: ``{base}/{owner}/{repo}/pull/{pr}``. The
73+
webview resolves the latest uploaded analysis artifact for the repository and
74+
PR, so the link remains unchanged across workflow runs.
7775
"""
78-
if not (webview_base and owner and repo and pr and run_id):
76+
if not (webview_base and owner and repo and pr):
7977
return None
8078
base = webview_base.rstrip("/")
81-
return f"{base}/{owner}/{repo}/pull/{pr}?{urlencode({'run': run_id})}"
79+
return f"{base}/{owner}/{repo}/pull/{pr}"
8280

8381

8482
def _join_or(items: list[str]) -> str:
@@ -100,7 +98,6 @@ def build_cta(
10098
*,
10199
webview_base: str = "",
102100
webview_ready: bool = False,
103-
run_id: str = "",
104101
) -> str:
105102
"""Return the markdown CTA footer: a health-warning banner plus an editor link.
106103
@@ -111,8 +108,8 @@ def build_cta(
111108
The ⚠️ banner shows whenever ``issues > 0``.
112109
113110
When ``webview_ready`` an "explore in browser" line deep-links the hosted webview
114-
to this PR's diff (``/owner/repo/pull/<pr>?run=<run_id>``); the webview re-derives
115-
the head/base/artifact from the run, so only the PR number and run id are needed.
111+
to this PR's diff (``/owner/repo/pull/<pr>``); the webview resolves the latest
112+
artifact for the repository and PR.
116113
"""
117114
parts: list[str] = []
118115
if issues > 0:
@@ -138,7 +135,7 @@ def link(path: str, **extra: str) -> str:
138135
# "in your browser or VS Code" / "in VS Code".
139136
targets: list[str] = []
140137
if webview_ready:
141-
wv = webview_url(webview_base, owner, repo, pr=pr, run_id=run_id)
138+
wv = webview_url(webview_base, owner, repo, pr=pr)
142139
if wv:
143140
targets.append(f"your [**browser**]({wv})")
144141
targets += [f"[**{_EDITOR_LABEL[e]}**]({editor_href[e]})" for e in editors]
@@ -161,7 +158,6 @@ def main() -> int:
161158
p.add_argument("--repo-path", required=True, type=Path, help="Path to the analyzed repo checkout")
162159
p.add_argument("--issues", default="0", help="Real architecture-issue count (0 -> no warning banner)")
163160
p.add_argument("--webview-base", default="", help="Hosted webview base URL (e.g. https://app.codeboarding.org)")
164-
p.add_argument("--run-id", default="", help="GitHub Actions run id containing the PR analysis artifact")
165161
p.add_argument(
166162
"--webview-ready",
167163
action="store_true",
@@ -183,7 +179,6 @@ def main() -> int:
183179
issues,
184180
webview_base=args.webview_base,
185181
webview_ready=args.webview_ready,
186-
run_id=args.run_id,
187182
)
188183
)
189184
return 0

‎tests/test_build_cta.py‎

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -80,28 +80,22 @@ class TestWebviewUrl(unittest.TestCase):
8080
WV = "https://app.codeboarding.org"
8181

8282
def test_url_is_github_style_pr_path(self):
83-
url = bc.webview_url(self.WV, "Org", "Repo", pr="9", run_id="123")
84-
self.assertEqual(url, "https://app.codeboarding.org/Org/Repo/pull/9?run=123")
85-
86-
def test_url_carries_only_pr_path_and_run(self):
87-
# Head/base SHAs and the artifact name/url are re-derived by the webview, so
88-
# none of them appear in the short link.
89-
url = bc.webview_url(self.WV, "o", "r", pr="9", run_id="123")
90-
self.assertIn("/o/r/pull/9", url)
91-
self.assertIn("run=123", url)
92-
self.assertNotIn("ref=", url)
93-
self.assertNotIn("compare=", url)
94-
self.assertNotIn("artifact", url)
95-
self.assertNotIn("repo=o%2Fr", url) # not the old query-style link
96-
97-
def test_url_none_without_pr_or_run(self):
98-
self.assertIsNone(bc.webview_url(self.WV, "o", "r", pr="9")) # no run
99-
self.assertIsNone(bc.webview_url(self.WV, "o", "r", run_id="123")) # no pr
100-
self.assertIsNone(bc.webview_url("", "o", "r", pr="9", run_id="123")) # no base
83+
url = bc.webview_url(self.WV, "Org", "Repo", pr="9")
84+
self.assertEqual(url, "https://app.codeboarding.org/Org/Repo/pull/9")
85+
86+
def test_url_carries_only_stable_pr_path(self):
87+
url = bc.webview_url(self.WV, "o", "r", pr="9")
88+
self.assertEqual(url, "https://app.codeboarding.org/o/r/pull/9")
89+
self.assertNotIn("?", url)
90+
self.assertNotIn("run", url)
91+
92+
def test_url_none_without_pr_or_base(self):
93+
self.assertIsNone(bc.webview_url(self.WV, "o", "r")) # no pr
94+
self.assertIsNone(bc.webview_url("", "o", "r", pr="9")) # no base
10195

10296
def test_trailing_slash_in_webview_base_is_normalized(self):
103-
a = bc.webview_url("https://app.codeboarding.org/", "o", "r", pr="9", run_id="1")
104-
b = bc.webview_url("https://app.codeboarding.org", "o", "r", pr="9", run_id="1")
97+
a = bc.webview_url("https://app.codeboarding.org/", "o", "r", pr="9")
98+
b = bc.webview_url("https://app.codeboarding.org", "o", "r", pr="9")
10599
self.assertEqual(a, b)
106100
self.assertNotIn(".org//", a)
107101

@@ -115,11 +109,11 @@ def test_cta_includes_browser_link_when_ready(self):
115109
issues=0,
116110
webview_base=self.WV,
117111
webview_ready=True,
118-
run_id="123",
119112
)
120113
self.assertIn("Explore this PR", out)
121114
self.assertIn("your [**browser**](", out)
122-
self.assertIn("/Org/Repo/pull/9?run=123", out)
115+
self.assertIn("https://app.codeboarding.org/Org/Repo/pull/9", out)
116+
self.assertNotIn("?run=", out)
123117
self.assertIn("VS Code", out) # editor merged into the same line
124118

125119
def test_cta_omits_browser_link_when_not_ready(self):
@@ -133,7 +127,6 @@ def test_cta_omits_browser_link_when_not_ready(self):
133127
issues=0,
134128
webview_base=self.WV,
135129
webview_ready=False,
136-
run_id="123",
137130
)
138131
self.assertNotIn("/pull/", out) # no browser link
139132
self.assertNotIn("[**browser**]", out)
@@ -150,7 +143,6 @@ def test_cta_omits_browser_link_when_ready_but_no_base_url(self):
150143
issues=0,
151144
webview_base="",
152145
webview_ready=True,
153-
run_id="123",
154146
)
155147
self.assertNotIn("[**browser**]", out)
156148
self.assertNotIn("/pull/", out)
@@ -167,7 +159,7 @@ class TestMergedExploreLine(unittest.TestCase):
167159
WV = "https://app.codeboarding.org"
168160

169161
def _ready(self, repo, cta=""):
170-
return bc.build_cta(cta, "o", "r", "1", repo, webview_base=self.WV, webview_ready=True, run_id="123")
162+
return bc.build_cta(cta, "o", "r", "1", repo, webview_base=self.WV, webview_ready=True)
171163

172164
def test_browser_and_single_editor_joined_with_or(self):
173165
out = self._ready(repo_with()) # default VS Code

0 commit comments

Comments
 (0)