Skip to content

Commit 75cbf50

Browse files
committed
link to internal interstitial screen instead of directly to github
1 parent 8c75f52 commit 75cbf50

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/deploy.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {visitFiles} from "./files.js";
1818
import type {Logger} from "./logger.js";
1919
import type {AuthEffects} from "./observableApiAuth.js";
2020
import {defaultEffects as defaultAuthEffects, formatUser, loginInner, validWorkspaces} from "./observableApiAuth.js";
21-
import {ObservableApiClient} from "./observableApiClient.js";
21+
import {ObservableApiClient, getObservableUiOrigin} from "./observableApiClient.js";
2222
import type {
2323
DeployManifestFile,
2424
GetCurrentUserResponse,
@@ -36,6 +36,8 @@ const DEPLOY_POLL_MAX_MS = 1000 * 60 * 5;
3636
const DEPLOY_POLL_INTERVAL_MS = 1000 * 5;
3737
const BUILD_AGE_WARNING_MS = 1000 * 60 * 5;
3838

39+
const OBSERVABLE_UI_ORIGIN = getObservableUiOrigin();
40+
3941
export function formatGitUrl(url: string) {
4042
return new URL(url).pathname.slice(1).replace(/\.git$/, "");
4143
}
@@ -252,18 +254,20 @@ class Deployer {
252254
.map((d) => d.split(/\s/g));
253255
const gitHub = remotes.find(([, url]) => url.startsWith("https://github.com/"));
254256
if (gitHub) {
255-
const repoName = formatGitUrl(gitHub[1]);
257+
const [ownerName, repoName] = formatGitUrl(gitHub[1]).split("/");
256258
// Get current branch
257259
const branch = (
258260
await promisify(exec)("git rev-parse --abbrev-ref HEAD", {cwd: this.deployOptions.config.root})
259261
).stdout;
260-
let authedRepo = await this.apiClient.getGitHubRepository(repoName);
262+
let authedRepo = await this.apiClient.getGitHubRepository(ownerName, repoName);
261263
if (!authedRepo) {
262-
// repo not auth’ed; link to auth page and poll for auth
263-
// TODO: link to internal page that bookends the flow and handles the no-oauth-token case more gracefully
264+
// Repo is not authorized; link to auth page and poll for auth
265+
const authUrl = new URL("/auth-github", OBSERVABLE_UI_ORIGIN);
266+
authUrl.searchParams.set("owner", ownerName);
267+
authUrl.searchParams.set("repo", repoName);
264268
this.effects.clack.log.info(
265269
`Authorize Observable to access the ${bold(repoName)} repository: ${link(
266-
"https://github.com/apps/observable-data-apps-dev/installations/select_target"
270+
authUrl
267271
)}`
268272
);
269273
const spinner = this.effects.clack.spinner();
@@ -275,7 +279,7 @@ class Deployer {
275279
spinner.stop("Waiting for repository to be authorized timed out.");
276280
throw new CliError("Repository authorization failed");
277281
}
278-
authedRepo = await this.apiClient.getGitHubRepository(repoName);
282+
authedRepo = await this.apiClient.getGitHubRepository(ownerName, repoName);
279283
if (authedRepo) spinner.stop("Repository authorized.");
280284
}
281285
}

src/observableApiClient.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ export class ObservableApiClient {
126126
return await this._fetch<GetProjectResponse>(url, {method: "GET"});
127127
}
128128

129-
async getGitHubRepository(repoName): Promise<GetGitHubRepositoryResponse | null> {
130-
const [owner, repo] = repoName.split("/");
131-
const url = new URL(`/cli/github/repository?owner=${owner}&repo=${repo}`, this._apiOrigin);
129+
async getGitHubRepository(ownerName, repoName): Promise<GetGitHubRepositoryResponse | null> {
130+
const url = new URL(`/cli/github/repository?owner=${ownerName}&repo=${repoName}`, this._apiOrigin);
132131
try {
133132
return await this._fetch<GetGitHubRepositoryResponse>(url, {method: "GET"});
134133
} catch (err) {

0 commit comments

Comments
 (0)