Skip to content

Commit e1d5dc1

Browse files
committed
Show the github url
1 parent 19e03d5 commit e1d5dc1

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

packages/playground/website/src/components/github-private-repo-auth-modal/index.tsx

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
11
import { Modal } from '../modal';
2-
import { useAppDispatch } from '../../lib/state/redux/store';
2+
import { useAppDispatch, useAppSelector } from '../../lib/state/redux/store';
33
import { setActiveModal } from '../../lib/state/redux/slice-ui';
44
import { Icon } from '@wordpress/components';
55
import { GitHubIcon } from '../../github/github';
66
import css from '../../github/github-oauth-guard/style.module.css';
77

88
const OAUTH_FLOW_URL = 'oauth.php?redirect=1';
99

10+
function extractRepoName(url: string): string {
11+
try {
12+
// Handle CORS-proxied URLs - extract the actual GitHub URL
13+
const corsProxyPrefixes = [
14+
'https://wordpress-playground-cors-proxy.net/?',
15+
'http://127.0.0.1:5263/cors-proxy.php?',
16+
];
17+
let githubUrl = url;
18+
for (const prefix of corsProxyPrefixes) {
19+
if (url.startsWith(prefix)) {
20+
githubUrl = url.substring(prefix.length);
21+
break;
22+
}
23+
}
24+
25+
// Extract owner/repo from GitHub URL
26+
const match = githubUrl.match(/github\.com\/([^\/]+\/[^\/]+)/);
27+
return match ? match[1] : url;
28+
} catch {
29+
return url;
30+
}
31+
}
32+
1033
export function GitHubPrivateRepoAuthModal() {
1134
const dispatch = useAppDispatch();
35+
const repoUrl = useAppSelector((state) => state.ui.githubAuthRepoUrl);
36+
37+
const displayRepoName = repoUrl ? extractRepoName(repoUrl) : '';
1238

1339
// Remove the modal parameter from the redirect URI
1440
// so it doesn't persist after OAuth completes
@@ -27,11 +53,16 @@ export function GitHubPrivateRepoAuthModal() {
2753
<div>
2854
<p>
2955
This blueprint requires access to a private GitHub
30-
repository.
56+
repository:
57+
</p>
58+
<p>
59+
<strong>
60+
<code>github.com/{displayRepoName}</code>
61+
</strong>
3162
</p>
3263
<p>
33-
To continue, please connect your GitHub account with
34-
WordPress Playground.
64+
If you have a GitHub account with access to this repository,
65+
you can connect it to continue.
3566
</p>
3667

3768
<p>

packages/playground/website/src/lib/state/redux/boot-site-client.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ import { setupPostMessageRelay } from '@php-wasm/web';
1717
import { startPlaygroundWeb } from '@wp-playground/client';
1818
import type { PlaygroundClient } from '@wp-playground/remote';
1919
import { getRemoteUrl } from '../../config';
20-
import { setActiveModal, setActiveSiteError } from './slice-ui';
20+
import {
21+
setActiveModal,
22+
setActiveSiteError,
23+
setGitHubAuthRepoUrl,
24+
} from './slice-ui';
2125
import type { PlaygroundDispatch, PlaygroundReduxState } from './store';
2226
import { selectSiteBySlug } from './slice-sites';
2327
// @ts-ignore
@@ -204,6 +208,14 @@ export function bootSiteClient(
204208
'GitHubAuthenticationError' ||
205209
(e as any).cause?.name === 'GitHubAuthenticationError'
206210
) {
211+
// Extract repo URL from the error
212+
const repoUrl =
213+
(e as any).repoUrl ||
214+
(e as any).cause?.repoUrl ||
215+
undefined;
216+
if (repoUrl) {
217+
dispatch(setGitHubAuthRepoUrl(repoUrl));
218+
}
207219
dispatch(setActiveModal(modalSlugs.GITHUB_PRIVATE_REPO_AUTH));
208220
} else {
209221
dispatch(setActiveSiteError('site-boot-failed'));

packages/playground/website/src/lib/state/redux/slice-ui.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface UIState {
1717
error?: SiteError;
1818
};
1919
activeModal: string | null;
20+
githubAuthRepoUrl?: string;
2021
offline: boolean;
2122
siteManagerIsOpen: boolean;
2223
siteManagerSection: SiteManagerSection;
@@ -88,6 +89,12 @@ const uiSlice = createSlice({
8889

8990
state.activeModal = action.payload;
9091
},
92+
setGitHubAuthRepoUrl: (
93+
state,
94+
action: PayloadAction<string | undefined>
95+
) => {
96+
state.githubAuthRepoUrl = action.payload;
97+
},
9198
setOffline: (state, action: PayloadAction<boolean>) => {
9299
state.offline = action.payload;
93100
},
@@ -139,6 +146,7 @@ export const listenToOnlineOfflineEventsMiddleware: Middleware =
139146
export const {
140147
setActiveModal,
141148
setActiveSiteError,
149+
setGitHubAuthRepoUrl,
142150
setOffline,
143151
setSiteManagerOpen,
144152
setSiteManagerSection,

0 commit comments

Comments
 (0)