@@ -18,7 +18,7 @@ import {visitFiles} from "./files.js";
18
18
import type { Logger } from "./logger.js" ;
19
19
import type { AuthEffects } from "./observableApiAuth.js" ;
20
20
import { defaultEffects as defaultAuthEffects , formatUser , loginInner , validWorkspaces } from "./observableApiAuth.js" ;
21
- import { ObservableApiClient } from "./observableApiClient.js" ;
21
+ import { ObservableApiClient , getObservableUiOrigin } from "./observableApiClient.js" ;
22
22
import type {
23
23
DeployManifestFile ,
24
24
GetCurrentUserResponse ,
@@ -36,6 +36,8 @@ const DEPLOY_POLL_MAX_MS = 1000 * 60 * 5;
36
36
const DEPLOY_POLL_INTERVAL_MS = 1000 * 5 ;
37
37
const BUILD_AGE_WARNING_MS = 1000 * 60 * 5 ;
38
38
39
+ const OBSERVABLE_UI_ORIGIN = getObservableUiOrigin ( ) ;
40
+
39
41
export function formatGitUrl ( url : string ) {
40
42
return new URL ( url ) . pathname . slice ( 1 ) . replace ( / \. g i t $ / , "" ) ;
41
43
}
@@ -252,18 +254,20 @@ class Deployer {
252
254
. map ( ( d ) => d . split ( / \s / g) ) ;
253
255
const gitHub = remotes . find ( ( [ , url ] ) => url . startsWith ( "https://github.com/" ) ) ;
254
256
if ( gitHub ) {
255
- const repoName = formatGitUrl ( gitHub [ 1 ] ) ;
257
+ const [ ownerName , repoName ] = formatGitUrl ( gitHub [ 1 ] ) . split ( "/" ) ;
256
258
// Get current branch
257
259
const branch = (
258
260
await promisify ( exec ) ( "git rev-parse --abbrev-ref HEAD" , { cwd : this . deployOptions . config . root } )
259
261
) . stdout ;
260
- let authedRepo = await this . apiClient . getGitHubRepository ( repoName ) ;
262
+ let authedRepo = await this . apiClient . getGitHubRepository ( ownerName , repoName ) ;
261
263
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 ) ;
264
268
this . effects . clack . log . info (
265
269
`Authorize Observable to access the ${ bold ( repoName ) } repository: ${ link (
266
- "https://github.com/apps/observable-data-apps-dev/installations/select_target"
270
+ authUrl
267
271
) } `
268
272
) ;
269
273
const spinner = this . effects . clack . spinner ( ) ;
@@ -275,7 +279,7 @@ class Deployer {
275
279
spinner . stop ( "Waiting for repository to be authorized timed out." ) ;
276
280
throw new CliError ( "Repository authorization failed" ) ;
277
281
}
278
- authedRepo = await this . apiClient . getGitHubRepository ( repoName ) ;
282
+ authedRepo = await this . apiClient . getGitHubRepository ( ownerName , repoName ) ;
279
283
if ( authedRepo ) spinner . stop ( "Repository authorized." ) ;
280
284
}
281
285
}
0 commit comments