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

Add support for GitHub Actions cache API #2604

Merged
merged 4 commits into from Jan 5, 2023

Conversation

alidevhere
Copy link
Contributor

@alidevhere alidevhere commented Dec 20, 2022

@gmlewis Ready for review. Please mention if something needs a change.
Thanks

Fixes: #2584.

@google-cla
Copy link

google-cla bot commented Dec 20, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gmlewis gmlewis changed the title Issue # 2584 Add support for GitHub Actions cache API Dec 20, 2022
@codecov
Copy link

codecov bot commented Dec 20, 2022

Codecov Report

Merging #2604 (7e6570e) into master (c5583e7) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2604      +/-   ##
==========================================
+ Coverage   97.99%   98.01%   +0.01%     
==========================================
  Files         127      128       +1     
  Lines       10948    11034      +86     
==========================================
+ Hits        10729    10815      +86     
  Misses        150      150              
  Partials       69       69              
Impacted Files Coverage Δ
github/actions_cache.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @alidevhere !

//
// GitHub API docs: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#list-github-actions-caches-for-a-repository
type ActionsCacheList struct {
TotalCount *int64 `json:"total_count,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this one is safe to leave as *int (not *int64 as we tend to reserve that for really large numbers or numeric IDs).

//
//GitHub API docs: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#get-github-actions-cache-usage-for-a-repository
type ActionsCacheUsage struct {
FullName *string `json:"full_name"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

We tend to add omitempty when are not sure if the GitHub server will populate the field...
but if we are confident that this will be a populated field, then we can get rid of the pointer and make this a string instead of a *string.

//GitHub API docs: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#get-github-actions-cache-usage-for-a-repository
type ActionsCacheUsage struct {
FullName *string `json:"full_name"`
ActiveCacheUsageSize *int64 `json:"active_caches_size_in_bytes"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

We try to match the name of the field to avoid confusion, so this would be ActiveCachesSizeInBytes, and I think this one is fine to leave as an int64.

type ActionsCacheUsage struct {
FullName *string `json:"full_name"`
ActiveCacheUsageSize *int64 `json:"active_caches_size_in_bytes"`
ActiveCachesCount *int64 `json:"active_caches_count"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking that this one should probably be an int.

ActiveCachesCount *int64 `json:"active_caches_count"`
}

// ActionsCacheUsageList represents a list repositories with GitHub Actions cache usage for an organization.
Copy link
Collaborator

Choose a reason for hiding this comment

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

"list repositories" => "list of repositories"

github/actions_cache.go Show resolved Hide resolved
return cacheUsage, res, err
}

// Gets the total GitHub Actions cache usage for an enterprise. The data fetched using this API is refreshed approximately every 5 minutes,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Gets the total GitHub Actions cache usage for an enterprise. The data fetched using this API is refreshed approximately every 5 minutes,
// GetTotalCacheUsageForEnterprise gets the total GitHub Actions cache usage for an enterprise. The data fetched using this API is refreshed approximately every 5 minutes,

github/actions_cache.go Show resolved Hide resolved
u := fmt.Sprintf("enterprises/%v/actions/cache/usage", enterprise)

req, err := s.client.NewRequest("GET", u, nil)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please delete this blank line. See above.


cacheUsage := new(TotalCacheUsage)
res, err := s.client.Do(ctx, req, cacheUsage)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please delete this blank line. See above.

@alidevhere
Copy link
Contributor Author

@gmlewis I have made all requested changes and re ran all tests and commands.

Please review again and do mention if something is still missing.
Thanks 😃

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @alidevhere !
Just a few more tweaks, please, then I think we will be ready for a second LGTM+Approval from any other contributor to this repo before merging.

//
// GitHub API docs: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#get-github-actions-cache-usage-for-an-enterprise
type TotalCacheUsage struct {
TotalActiveCacheUsageSizeInBytes int64 `json:"total_active_caches_size_in_bytes"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
TotalActiveCacheUsageSizeInBytes int64 `json:"total_active_caches_size_in_bytes"`
TotalActiveCachesUsageSizeInBytes int64 `json:"total_active_caches_size_in_bytes"`

Comment on lines 67 to 72
Ref string `url:"ref,omitempty"`
Key string `url:"key,omitempty"`
// Can be one of: "created_at", "last_accessed_at", "size_in_bytes". Default: "last_accessed_at"
Sort string `url:"sort,omitempty"`
// Can be one of: "asc", "desc" Default: desc
Direction string `url:"direction,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Ref string `url:"ref,omitempty"`
Key string `url:"key,omitempty"`
// Can be one of: "created_at", "last_accessed_at", "size_in_bytes". Default: "last_accessed_at"
Sort string `url:"sort,omitempty"`
// Can be one of: "asc", "desc" Default: desc
Direction string `url:"direction,omitempty"`
Ref *string `url:"ref,omitempty"`
Key *string `url:"key,omitempty"`
// Can be one of: "created_at", "last_accessed_at", "size_in_bytes". Default: "last_accessed_at"
Sort *string `url:"sort,omitempty"`
// Can be one of: "asc", "desc" Default: desc
Direction *string `url:"direction,omitempty"`

@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Dec 22, 2022
Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

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

Thank you, @alidevhere !
LGTM.

Awaiting second LGTM+Approval from any other contributor to this repo before merging.

Copy link
Contributor

@valbeat valbeat left a comment

Choose a reason for hiding this comment

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

LGTM!

@gmlewis gmlewis removed the NeedsReview PR is awaiting a review before merging. label Jan 5, 2023
@gmlewis
Copy link
Collaborator

gmlewis commented Jan 5, 2023

Thank you, @valbeat !
Merging.

@gmlewis gmlewis merged commit 8ec1e49 into google:master Jan 5, 2023
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.

Actions.Cache from github API v3 is not implemented
3 participants