MCPcopy Index your code
hub / github.com/rilldata/rill / githubFlow

Function githubFlow

cli/cmd/project/connect_github.go:408–482  ·  view source on GitHub ↗
(ctx context.Context, ch *cmdutil.Helper, gitRemote string)

Source from the content-addressed store, hash-verified

406}
407
408func githubFlow(ctx context.Context, ch *cmdutil.Helper, gitRemote string) (*adminv1.GetGithubRepoStatusResponse, error) {
409 // Get the admin client
410 c, err := ch.Client()
411 if err != nil {
412 return nil, err
413 }
414
415 // Check for access to the Github repo
416 res, err := c.GetGithubRepoStatus(ctx, &adminv1.GetGithubRepoStatusRequest{
417 Remote: gitRemote,
418 })
419 if err != nil {
420 return nil, err
421 }
422
423 // If the user has not already granted access, open browser and poll for access
424 if !res.HasAccess {
425 if !ch.Interactive {
426 return nil, fmt.Errorf("the GitHub connect flow requires an interactive terminal to grant access to the GitHub repository. Please run this command in an interactive terminal and follow the instructions to grant access.")
427 }
428 // Emit start telemetry
429 ch.Telemetry(ctx).RecordBehavioralLegacy(activity.BehavioralEventGithubConnectedStart)
430
431 // Print instructions to grant access
432 ch.Print("Rill projects deploy continuously when you push changes to Github.\n")
433 ch.Print("You need to grant Rill read only access to your repository on Github.\n\n")
434
435 // Wait three seconds before opening the browser
436 select {
437 case <-time.After(3 * time.Second):
438 case <-ctx.Done():
439 return nil, ctx.Err()
440 }
441 ch.Print("Open this URL in your browser to grant Rill access to Github:\n\n")
442 ch.Print("\t" + res.GrantAccessUrl + "\n\n")
443
444 // Open browser if possible
445 if ch.Interactive {
446 _ = browser.Open(res.GrantAccessUrl)
447 }
448
449 // Poll for permission granted
450 pollCtx, cancel := context.WithTimeout(ctx, pollTimeout)
451 defer cancel()
452 for {
453 select {
454 case <-pollCtx.Done():
455 return nil, pollCtx.Err()
456 case <-time.After(pollInterval):
457 // Ready to check again.
458 }
459
460 // Poll for access to the Github URL
461 pollRes, err := c.GetGithubRepoStatus(ctx, &adminv1.GetGithubRepoStatusRequest{
462 Remote: gitRemote,
463 })
464 if err != nil {
465 return nil, err

Callers 1

ConnectGithubFlowFunction · 0.85

Calls 11

OpenFunction · 0.92
SplitGithubRemoteFunction · 0.92
TelemetryMethod · 0.80
PrintMethod · 0.80
DoneMethod · 0.80
PrintfSuccessMethod · 0.80
GetGithubRepoStatusMethod · 0.65
ErrorfMethod · 0.65
ErrMethod · 0.65
ClientMethod · 0.45

Tested by

no test coverage detected