这是indexloc提供的服务,不要输入任何密码
Skip to content

Fix remote cache config detection to support just slug #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func newSyncCache(config *config.Config, remoteOnly bool) Cache {
if config.Cache.Dir != "" && !remoteOnly {
mplex.caches = append(mplex.caches, newFsCache(config))
}
if config.Token != "" && config.TeamId != "" {
if (config.Token != "" && config.TeamId != "") || (config.Token != "" && config.TeamSlug != "") {
fmt.Println(ui.Dim("• Remote computation caching enabled (experimental)"))
mplex.caches = append(mplex.caches, newHTTPCache(config))
}
Expand Down
42 changes: 2 additions & 40 deletions cli/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config,
}
partialConfig.Token = userConfig.Token

enverr := envconfig.Process("turbo", partialConfig)
enverr := envconfig.Process("TURBO", partialConfig)
if enverr != nil {
return nil, fmt.Errorf("invalid environment variable: %w", err)
}
Expand All @@ -113,7 +113,6 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config,
}
}

shouldEnsureTeam := false
// Process arguments looking for `-v` flags to control the log level.
// This overrides whatever the env var set.
var outArgs []string
Expand Down Expand Up @@ -151,7 +150,6 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config,
partialConfig.Token = arg[len("--token="):]
case strings.HasPrefix(arg, "--team="):
partialConfig.TeamSlug = arg[len("--team="):]
shouldEnsureTeam = true
default:
outArgs = append(outArgs, arg)
}
Expand Down Expand Up @@ -191,46 +189,10 @@ func ParseAndValidate(args []string, ui cli.Ui, turboVersion string) (c *Config,

c.ApiClient.SetToken(partialConfig.Token)

if shouldEnsureTeam || partialConfig.TeamSlug != "" {
if err := c.ensureTeam(); err != nil {
return c, err
}
}

return c, nil
}

func (c *Config) ensureTeam() error {
// if c.Token == "" {
// if IsCI() {
// fmt.Println(ui.Warn("no token has been provided, but you specified a Turborepo team and project. If this is intended (e.g. a pull request on an open source GitHub project from an outside contributor triggered this), you can ignore this warning. Otherwise, please run `turbo login`, pass `--token` flag, or set `TURBO_TOKEN` environment variable to enable remote caching. In the meantime, turbo will attempt to continue with local caching."))
// return nil
// }
// return fmt.Errorf("no credentials found. Please run `turbo login`, pass `--token` flag, or set TURBO_TOKEN environment variable")
// }
// req, err := graphql.NewGetTeamRequest(c.ApiUrl, &graphql.GetTeamVariables{
// Slug: (*graphql.String)(&c.TeamSlug),
// })
// if err != nil {
// return fmt.Errorf("could not fetch team information: %w", err)
// }
// req.Header.Set("Authorization", "Bearer "+c.Token)
// res, resErr := req.Execute(c.GraphQLClient.Client)
// if resErr != nil {
// return fmt.Errorf("could not fetch team information: %w", resErr)
// }

// if res.Team.ID == "" {
// return fmt.Errorf("could not fetch team information. Check the spelling of `%v` and make sure that the %v team exists on turborepo.com and that you have access to it", c.TeamSlug, c.TeamSlug)
// }

// c.TeamId = res.Team.ID
// c.TeamSlug = res.Team.Slug

return nil
}

// IsLogged returns true if the user is logged into turborepo.com
// IsLoggedIn returns true if the user is logged into a Remote Cache
func (c *Config) IsLoggedIn() bool {
return c.Token != ""
}
Expand Down