Add support for GitHub Actions cache API#2604
Conversation
|
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. |
Codecov Report
@@ 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
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @alidevhere !
github/actions_cache.go
Outdated
| // | ||
| // 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"` |
There was a problem hiding this comment.
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/actions_cache.go
Outdated
| // | ||
| //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"` |
There was a problem hiding this comment.
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/actions_cache.go
Outdated
| //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"` |
There was a problem hiding this comment.
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.
github/actions_cache.go
Outdated
| type ActionsCacheUsage struct { | ||
| FullName *string `json:"full_name"` | ||
| ActiveCacheUsageSize *int64 `json:"active_caches_size_in_bytes"` | ||
| ActiveCachesCount *int64 `json:"active_caches_count"` |
There was a problem hiding this comment.
I'm thinking that this one should probably be an int.
github/actions_cache.go
Outdated
| ActiveCachesCount *int64 `json:"active_caches_count"` | ||
| } | ||
|
|
||
| // ActionsCacheUsageList represents a list repositories with GitHub Actions cache usage for an organization. |
There was a problem hiding this comment.
"list repositories" => "list of repositories"
github/actions_cache.go
Outdated
| 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, |
There was a problem hiding this comment.
| // 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
Outdated
| u := fmt.Sprintf("enterprises/%v/actions/cache/usage", enterprise) | ||
|
|
||
| req, err := s.client.NewRequest("GET", u, nil) | ||
|
|
There was a problem hiding this comment.
Please delete this blank line. See above.
github/actions_cache.go
Outdated
|
|
||
| cacheUsage := new(TotalCacheUsage) | ||
| res, err := s.client.Do(ctx, req, cacheUsage) | ||
|
|
There was a problem hiding this comment.
Please delete this blank line. See above.
|
@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. |
gmlewis
left a comment
There was a problem hiding this comment.
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/actions_cache.go
Outdated
| // | ||
| // 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"` |
There was a problem hiding this comment.
| TotalActiveCacheUsageSizeInBytes int64 `json:"total_active_caches_size_in_bytes"` | |
| TotalActiveCachesUsageSizeInBytes int64 `json:"total_active_caches_size_in_bytes"` |
github/actions_cache.go
Outdated
| 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"` |
There was a problem hiding this comment.
| 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"` |
8cf0e07 to
7e6570e
Compare
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @alidevhere !
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.
|
Thank you, @valbeat ! |
@gmlewis Ready for review. Please mention if something needs a change.
Thanks
Fixes: #2584.