Skip to content

Commit 702d288

Browse files
committed
[projects] handle private GitHub projects on Config Page
1 parent 483de9a commit 702d288

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

components/dashboard/src/projects/ConfigureProject.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export default function () {
7373
const [prebuildInstance, setPrebuildInstance] = useState<WorkspaceInstance | undefined>();
7474
const { isDark } = useContext(ThemeContext);
7575

76-
const [showAuthBanner, setShowAuthBanner] = useState<{ host: string } | undefined>(undefined);
76+
const [showAuthBanner, setShowAuthBanner] = useState<{ host: string, scope?: string } | undefined>(undefined);
7777

7878
useEffect(() => {
7979
// Disable editing while loading, or when the config comes from Git.
@@ -99,7 +99,11 @@ export default function () {
9999
try {
100100
await detectProjectConfiguration(project);
101101
} catch (error) {
102-
if (error && error.code === ErrorCodes.NOT_AUTHENTICATED) {
102+
if (error && error.message && error.message.includes("NotFound")) {
103+
const host = new URL(project.cloneUrl).hostname;
104+
const scope: string | undefined = host === "github.com" ? "repo" : undefined;
105+
setShowAuthBanner({ host: new URL(project.cloneUrl).hostname, scope });
106+
} else if (error && error.code === ErrorCodes.NOT_AUTHENTICATED) {
103107
setShowAuthBanner({ host: new URL(project.cloneUrl).hostname });
104108
} else {
105109
console.error('Getting project configuration failed', error);
@@ -135,12 +139,12 @@ export default function () {
135139
setGitpodYml(TASKS.Other);
136140
}
137141

138-
// @ts-ignore
139-
const tryAuthorize = async (host: string, onSuccess: () => void) => {
142+
const tryAuthorize = async (params: {host: string, scope?: string, onSuccess: () => void}) => {
140143
try {
141144
await openAuthorizeWindow({
142-
host,
143-
onSuccess,
145+
host: params.host,
146+
onSuccess: params.onSuccess,
147+
scopes: params.scope ? [params.scope] : undefined,
144148
onError: (error) => {
145149
console.log(error);
146150
}
@@ -150,17 +154,17 @@ export default function () {
150154
}
151155
};
152156

153-
const onConfirmShowAuthModal = async (host: string) => {
157+
const onConfirmShowAuthModal = async (host: string, scope?: string) => {
154158
setShowAuthBanner(undefined);
155-
await tryAuthorize(host, async () => {
159+
await tryAuthorize({host, onSuccess: async () => {
156160
// update remote session
157161
await getGitpodService().reconnect();
158162

159163
// retry fetching branches
160164
if (project) {
161165
detectProjectConfiguration(project);
162166
}
163-
});
167+
}});
164168
};
165169

166170
const buildProject = async (event: React.MouseEvent) => {
@@ -215,9 +219,9 @@ export default function () {
215219
No Access
216220
</div>
217221
<div className="text-center dark:text-gray-400 pb-3">
218-
Authorize {showAuthBanner.host} <br />to access project configuration.
222+
Authorize {showAuthBanner.host} <br />{showAuthBanner.scope ? (<>and grant <strong>{showAuthBanner.scope}</strong> permission</>) : ""} to access project configuration.
219223
</div>
220-
<button className={`primary mr-2 py-2`} onClick={() => onConfirmShowAuthModal(showAuthBanner.host)}>Authorize Provider</button>
224+
<button className={`primary mr-2 py-2`} onClick={() => onConfirmShowAuthModal(showAuthBanner.host, showAuthBanner.scope)}>Authorize Provider</button>
221225
</div>
222226
</div>
223227
) : (<>

0 commit comments

Comments
 (0)