Skip to content
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

refactor: helper function for getToken for cache reset + error handling #133

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

srikarmanikonda
Copy link

I included a quick helper function to simplify code reading for getting a token in cache reset + added some error messages for users to see if cache resets with no args

Copy link
Member

@jacobwgillespie jacobwgillespie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you for this! 🎉 I left a few comments below, let me know if anything isn't clear, etc.

}
if token == "" {
return fmt.Errorf("missing API token, please run `depot login`")
token, err := getToken()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the build and bake commands are already using a helper function, you might be able to use the same one here as well:

token = helpers.ResolveToken(context.Background(), token)

Comment on lines -28 to +42
var cwd string
if len(args) > 0 {
cwd, _ = filepath.Abs(args[0])
cwd, err := filepath.Abs(args[0])
if err != nil {
return fmt.Errorf("unable to determine absolute path: %w", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic from before isn't really easy to follow, sorry about that. What's happening is that cache reset can take either 0 or 1 arguments. If no arguments are specified, then the cwd variable will contain an empty string "".

Then if an empty string passed to helpers.ResolveProjectID(projectID, cwd) as the cwd, that function will actually resolve the current working directory.

So we do only want to try to resolve args[0] if len(args) > 0.

Maybe to make it clearer, we could rename the cwd variable here cwdOverride or projectDir or something that would make it more clear?

We could also move the resolution of cwd, _ := filepath.Abs(...) into the helper function itself, I imagine every command has that part duplicated currently.

Comment on lines +49 to +51
if projectID == "" {
return errors.Errorf("unknown project ID (run `depot init` or use --project or $DEPOT_PROJECT_ID)")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line is duplicated:

Suggested change
if projectID == "" {
return errors.Errorf("unknown project ID (run `depot init` or use --project or $DEPOT_PROJECT_ID)")
}

@jacobwgillespie
Copy link
Member

Nice I think I got the Actions CI workflows to work for PRs as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants