dtdemo

package
v0.160.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 20 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dtdemo provides the SSH demo's welcome screen, Save-to-GitHub workspace module, and in-memory per-session GitHub authentication state.

Index

Constants

View Source
const (
	// ModuleID is the datatugui root module ID for Save-to-GitHub.
	ModuleID = "demo_save"
	// ModuleText is the menu label for Save-to-GitHub.
	ModuleText = "Save to GitHub"
	// GitHubScope is the minimum OAuth scope required to fork a public repo
	// and push to the visitor's fork.
	GitHubScope = "public_repo"
	// DefaultSaveBranch is the default branch name on the visitor's fork.
	DefaultSaveBranch = "datatug-demo"
	// SaveNotConfiguredNotice is displayed in the Save module when the demo
	// server was started against a non-GitHub repository.
	SaveNotConfiguredNotice = "Saving to GitHub is not configured on this demo server."
	// ExternalDatabasesNotice states that external databases are not part of the repo.
	ExternalDatabasesNotice = "" /* 151-byte string literal not displayed */
	// SessionWarning is shown just before the supervisor ends a session.
	SessionWarning = "Your SSH demo session ends in one minute or less."
)

Variables

This section is empty.

Functions

func ClassifyChanges

func ClassifyChanges(repoDir string, changes []demogit.Change) (projectFiles, dbFiles []demogit.Change)

ClassifyChanges splits workspace changes into project files and database files (*.sqlite, *.db, SQLite sidecars, and inGitDB data directories).

func FormatErrorFor

func FormatErrorFor(err error, canonical demogit.Repo) string

FormatErrorFor turns a demogit or device-flow error into plain words for the visitor.

func NewSaveScreen

func NewSaveScreen(cfg Config) nav.Screen

NewSaveScreen constructs the Save-to-GitHub workspace screen.

func SaveModule

func SaveModule(cfg Config) datatugui.Module

SaveModule returns the Save-to-GitHub root module entry for the workspace menu.

func ScopeExplanation

func ScopeExplanation(canonical demogit.Repo) string

ScopeExplanation explains what the public_repo OAuth scope allows and how DataTug uses and discards the token.

func SessionWarningAt

func SessionWarningAt(deadline time.Time) time.Time

SessionWarningAt returns when to warn, or zero when there is no deadline.

Types

type AuthState

type AuthState struct {
	// contains filtered or unexported fields
}

AuthState holds one visitor's GitHub sign-in state in process memory only. The token is never persisted, logged, written to git config, or printed.

func NewAuthState

func NewAuthState() *AuthState

NewAuthState creates an empty in-memory GitHub sign-in state.

func (*AuthState) Clear

func (a *AuthState) Clear()

Clear forgets the in-memory token and login.

func (*AuthState) Login

func (a *AuthState) Login() string

Login returns the authenticated GitHub username if known.

func (*AuthState) Set

func (a *AuthState) Set(token, login string)

Set records the GitHub access token and optional login in memory.

func (*AuthState) SetLogin

func (a *AuthState) SetLogin(login string)

SetLogin records the authenticated GitHub username.

func (*AuthState) SignedIn

func (a *AuthState) SignedIn() bool

SignedIn reports whether an access token is held in memory.

func (*AuthState) String

func (a *AuthState) String() string

String redacts the token so AuthState can never leak secrets through fmt.

func (*AuthState) Token

func (a *AuthState) Token() string

Token returns the in-memory access token, or "" when not signed in.

type Config

type Config struct {
	Canonical      demogit.Repo
	RepoDir        string
	ProjectDir     string
	SaveBranch     string
	GitHubClientID string
	Deadline       time.Time
	Auth           *AuthState

	// Optional overrides for the device-flow screen in tests.
	RequestDeviceCode func(ctx context.Context, clientID, scope string) (*ghauth.DeviceCodeResponse, error)
	PollForToken      func(ctx context.Context, clientID, clientSecret, deviceCode string, interval int, onAttempt func(int)) (*oauth2.Token, error)
}

Config holds the session-wide parameters shared by the welcome screen and the Save-to-GitHub workspace module.

func (Config) GitHubEnabled

func (c Config) GitHubEnabled() bool

GitHubEnabled reports whether GitHub sign-in, fork opening, and saving are configured for this demo session (i.e. Canonical names a GitHub owner/repo).

type GitClient

type GitClient interface {
	User(ctx context.Context) (string, error)
	FindFork(ctx context.Context) (demogit.Repo, error)
	EnsureFork(ctx context.Context) (fork demogit.Repo, created bool, err error)
	Save(ctx context.Context, repoDir string, fork demogit.Repo, opts demogit.SaveOptions) (demogit.SaveResult, error)
	Open(ctx context.Context, fork demogit.Repo, destDir, projectDir string) (branch string, err error)
	NewBranchName() string
}

GitClient is the subset of *demogit.Client used by dtdemo screens. Production uses demogit.New; tests substitute a fake through newGitClient.

type WelcomeModel

type WelcomeModel struct {
	// contains filtered or unexported fields
}

WelcomeModel is the Bubble Tea model shown at the start of an SSH demo session before the full DataTug workspace launches.

func NewWelcomeModel

func NewWelcomeModel(cfg Config) WelcomeModel

NewWelcomeModel creates the initial welcome screen model.

func (WelcomeModel) Init

func (m WelcomeModel) Init() tea.Cmd

Init implements tea.Model.

func (WelcomeModel) Result

func (m WelcomeModel) Result() WelcomeResult

Result returns the visitor's outcome once the model quits.

func (WelcomeModel) Update

func (m WelcomeModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements tea.Model.

func (WelcomeModel) View

func (m WelcomeModel) View() tea.View

View implements tea.Model.

type WelcomeOutcome

type WelcomeOutcome int

WelcomeOutcome describes how the visitor left the demo welcome screen.

const (
	// OutcomeQuit means the visitor quit before entering the workspace.
	OutcomeQuit WelcomeOutcome = iota
	// OutcomeExplore means the visitor chose to explore the fresh demo template.
	OutcomeExplore
	// OutcomeOpenedFork means the visitor signed in and opened their fork into RepoDir.
	OutcomeOpenedFork
)

type WelcomeResult

type WelcomeResult struct {
	Outcome WelcomeOutcome
	Fork    demogit.Repo
	Branch  string
}

WelcomeResult is the outcome of the welcome screen.

func RunWelcome

func RunWelcome(cfg Config, opts ...tea.ProgramOption) (WelcomeResult, error)

RunWelcome displays the demo welcome screen and returns the visitor's choice.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL