-
Notifications
You must be signed in to change notification settings - Fork 58
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
E2E List cmd and added API calls #3
Conversation
ghRepo "github.com/cli/go-gh/pkg/repository" | ||
) | ||
|
||
type cacheInfo struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now I see this is the only data model. Do we need a separate class to maintain models?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should, we'd need one more wrapper model for parsing the API response as we also have total count in our list api response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another good yardstick would be to see if same model is being used in multiple files/packages. If yes, then it may need to moved to dedicated directory/class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, this may seem redundant today but it may be important to define the layout of the project cleanly.
@@ -0,0 +1,90 @@ | |||
package cmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason to name the package as cmd
. If that is to specify that this package contains comands, then client.go
and utils.go
should not be part of it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmd
was the default package created by cobra
. We can update this to sometime like actions-cache
.
Reason for keeping client.go
and util.go
part of the same package was thats how it was being done in the gh-s we have been trying to use as reference.
We can remove them from this package but then we will have to explicitly import them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would personally prefer to keep client and utils out and have cmd
package only for commands code. This seems redundant today given the simplicity of the project, but once it starts growing it will get harder to manage.
cmd
name seems okay as it points to "command" module if I get it right which is essentially the command handler.
@@ -0,0 +1,63 @@ | |||
package cmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another similar suggestion - rather than one single utils file containing 3 different types of utils, would it be better to have a utils package which will have repoUtils, parseUtils and formatter as different files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will refactor and create multiple packages in the next PR. Its already in draft state
order, _ := cmd.Flags().GetString("order") | ||
sort, _ := cmd.Flags().GetString("sort") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the validation will be added later. Isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added now
@@ -21,20 +25,38 @@ var listCmd = &cobra.Command{ | |||
Short: "Lists the actions cache", | |||
Long: `Lists the actions cache`, | |||
Run: func(cmd *cobra.Command, args []string) { | |||
repo, _ := cmd.Flags().GetString("repo") | |||
COMMAND = "list" | |||
r, _ := cmd.Flags().GetString("repo") | |||
branch, _ := cmd.Flags().GetString("branch") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API expects the branch to be in full ref format. CLI should prepend that if user has not specified that.
cc @anuragc617 who may have better thoughts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is being handled while creating query params in generateQueryParams
|
||
fmt.Printf("Showing %d of %d cache entries in %s/%s\n", totalShownCacheEntry(len(caches)), len(caches), repo.Owner(), repo.Name()) | ||
for _, cache := range caches { | ||
fmt.Printf("%s\t [%s]\t %s\t %s\n", cache.Key, formatCacheSize(cache.Size), cache.Ref, cache.LastAccessedAt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are not showing version here, there might be duplicate lines in the output here (same key and ref). Is that expected? Should it be changed?
Or: Add a TODO to display version here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be taken in next PR after confirmation from the designer.
@@ -6,11 +6,13 @@ import ( | |||
"github.com/spf13/cobra" | |||
) | |||
|
|||
const VERSION = "0.0.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this version number expected to come from? Will cli tell us which extension version is installed?
if totalCaches < limit { | ||
return totalCaches | ||
} | ||
return limit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ternary operator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golang doesnt have ternary operators.
actionsCachesResult := apiResults["actions_caches"].([]interface{}) | ||
|
||
var caches []cacheInfo | ||
for _, item := range actionsCachesResult { | ||
caches = append(caches, cacheInfo{ | ||
Key: item.(map[string]interface{})["key"].(string), | ||
Ref: item.(map[string]interface{})["ref"].(string), | ||
LastAccessedAt: item.(map[string]interface{})["last_accessed_at"].(string), | ||
Size: item.(map[string]interface{})["size_in_bytes"].(float64), | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not use unmarshalling here to directly convert to the target datatype?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in deleteCaches as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are doing that in the next draft PR.
@anuragc617 / @tiwarishub you may want to review this from golang best practices perspective. |
Pending Items
We will take this up in next PR as the initial PR was to create MVP. |
Aim for the PR is to get early feedback and allow Sankalp to integrate his UI side changes with
delete
APIProgress
Added functions for getting:-
Added utils functions to:-
repo
flag and current directoryCompleted happy path for List Command with basic stdout.
Upcoming changes