fix(pull-requests): render private GitHub images in PR bodies #8446
ClosedXanacas(GitHub profile, opens in a new tab)wants to merge 14 commits into
main fromrefs/pull/8446/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/assets/GitHubAttachmentProxy.ts lines 48 to 67OutdatedResolvedby Xanacas(GitHub profile, opens in a new tab)@@ -0,0 +47,21 @@47+48+ const resolveAttachmentLocation: GitHubAttachmentProxy["Service"]["resolveAttachmentLocation"] = (49+ url,50+ ) =>51+ Effect.gen(function* () {52+ const token = yield* readToken;53+ const request = HttpClientRequest.get(url, {54+ headers: token === null ? {} : { authorization: `token ${token}` },55+ });56+ const response = yield* httpClient57+ .execute(request)58+ .pipe(Effect.provideService(FetchHttpClient.RequestInit, { redirect: "manual" }));59+ if (response.status < 300 || response.status >= 400) return null;60+ const location = response.headers["location"];61+ return location !== undefined && location.startsWith("https://") ? location : null;62+ }).pipe(63+ Effect.tapError((cause) =>64+ Effect.logWarning("Failed to resolve a GitHub attachment.", { url, cause }),65+ ),66+ Effect.orElseSucceed(() => null),67+ );
- packages/client-runtime/src/markdownImages.ts lines 89 to 91Resolvedby Xanacas(GitHub profile, opens in a new tab)@@ -76,4 +80,6 @@7680 return { _tag: "Blocked" };7781 }7882 if (DIRECT_IMAGE_SOURCE_PATTERN.test(source)) {79- return { _tag: "Direct", uri: source };83+ return isGitHubUserAttachmentUrl(source)84+ ? { _tag: "GitHubAttachment", url: source }85+ : { _tag: "Direct", uri: source };
- apps/mobile/src/features/threads/ThreadFeed.tsx line 1635OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1624,5 +1626,10 @@16241626 return (16251627 <ThreadMarkdownImage16261628 environmentId={props.environmentId}1627- threadId={props.threadId}1628- path={imageSource.path}1629+ resource={1630+ imageSource._tag === "GitHubAttachment"1631+ ? { _tag: "github-attachment", url: imageSource.url }1632+ : { _tag: "workspace-file", threadId: props.threadId, path: imageSource.path }1633+ }1634+ sourceKey={imageSource._tag === "GitHubAttachment" ? imageSource.url : imageSource.path}1635+ {...(imageSource._tag === "GitHubAttachment" ? { fallbackUri: imageSource.url } : {})}
- apps/web/src/components/ChatMarkdown.tsx lines 2177 to 2183OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2161,3 +2170,14 @@21612170 />21622171 );21632172 }2173+ if (imageSource._tag === "GitHubAttachment") {2174+ if (environmentId === null) {2175+ // No environment to proxy through; public uploads still load directly.2176+ return (2177+ <img2178+ {...props}2179+ src={imageSource.url}2180+ alt={altText}2181+ loading="lazy"2182+ className={cn(props.className, CHAT_MARKDOWN_IMAGE_SIZE_CLASS_NAME)}2183+ />
- @@ -288,3 +298,6 @@288298 fileName = path.basename(resolved.relativePath);289299 break;290300 }301+ case "github-attachment": {302+ const url = input.resource.url;303+ if (!isGitHubUserAttachmentUrl(url)) {
- apps/web/src/components/ChatMarkdown.tsx lines 2194 to 2205OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2161,3 +2191,15 @@21612191 />21622192 );21632193 }2194+ if (imageSource._tag === "GitHubAttachment") {2195+ if (environmentId === null) {2196+ // No environment to proxy through; public uploads still load directly.2197+ return <ChatMarkdownDirectAttachmentImage url={imageSource.url} alt={altText} />;2198+ }2199+ return (2200+ <ChatMarkdownAssetImage2201+ environmentId={environmentId}2202+ resource={{ _tag: "github-attachment", url: imageSource.url }}2203+ alt={altText}2204+ fallbackUrl={imageSource.url}2205+ />
- apps/web/src/components/ChatMarkdown.tsx line 2416OutdatedResolvedby Xanacas(GitHub profile, opens in a new tab)@@ -2372,3 +2409,8 @@23722409 />23732410 );23742411 }2412+ if (imageSource._tag === "GitHubAttachment") {2413+ if (environmentId === null) {2414+ // No environment to proxy through; public uploads still load directly.2415+ return (2416+ <ChatMarkdownDirectAttachmentImage
- apps/server/src/assets/GitHubAttachmentProxy.ts line 56OutdatedResolvedby Xanacas(GitHub profile, opens in a new tab)@@ -0,0 +36,21 @@36+ args: ["auth", "token", "--hostname", "github.com"],37+ })38+ .pipe(39+ Effect.map((output) => {40+ const trimmed = output.stdout.trim();41+ return trimmed.length > 0 ? trimmed : null;42+ }),43+ Effect.orElseSucceed(() => null),44+ ),45+ TOKEN_CACHE_TTL,46+ );47+48+ const resolveAttachmentLocation: GitHubAttachmentProxy["Service"]["resolveAttachmentLocation"] = (49+ url,50+ ) =>51+ Effect.gen(function* () {52+ const token = yield* readToken;53+ const request = HttpClientRequest.get(url, {54+ headers: token === null ? {} : { authorization: `token ${token}` },55+ });56+ const response = yield* httpClient
- apps/web/src/components/ChatMarkdown.tsx lines 2416 to 2420OutdatedResolvedby Xanacas(GitHub profile, opens in a new tab)@@ -2372,3 +2409,12 @@23722409 />23732410 );23742411 }2412+ if (imageSource._tag === "GitHubAttachment") {2413+ if (environmentId === null) {2414+ // No environment to proxy through; public uploads still load directly.2415+ return (2416+ <ChatMarkdownDirectAttachmentImage2417+ url={imageSource.url}2418+ alt={altText}2419+ style={authoredSizeStyle}2420+ />
- apps/mobile/src/features/threads/ThreadFeed.tsx line 2000Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1990,8 +2018,6 @@19902018 return (19912019 <ThreadMarkdownImage19922020 environmentId={props.environmentId}1993- resource={{1994- _tag: "workspace-file",1995- threadId: props.threadId,1996- path: imageSource.path,1997- }}2021+ resource={2022+ imageSource._tag === "GitHubAttachment"2023+ ? { _tag: "github-attachment", url: imageSource.uri }
Xanacas(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
faf14ea4-c819-4b05-8b99-be736ecc7ffcYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Comment `@coderabbitai help` to get the list of available commands.