Repository navigation
refactor!: Rename InstallationTokenOptions to CreateInstallationTokenRequest, pass it by value, and remove CreateInstallationTokenListRepos - #4700
Conversation
…stRepoOptions` to `...Request` types and pass them by value
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4700 +/- ##
==========================================
- Coverage 98.64% 98.64% -0.01%
==========================================
Files 204 204
Lines 19089 19080 -9
==========================================
- Hits 18831 18822 -9
Misses 258 258 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| // | ||
| //meta:operation POST /app/installations/{installation_id}/access_tokens | ||
| func (s *AppsService) CreateInstallationTokenListRepos(ctx context.Context, id int64, body *InstallationTokenListRepoOptions) (*InstallationToken, *Response, error) { | ||
| func (s *AppsService) CreateInstallationTokenListRepos(ctx context.Context, id int64, body CreateInstallationTokenListReposRequest) (*InstallationToken, *Response, error) { |
There was a problem hiding this comment.
If we change CreateInstallationTokenRequest.RepositoryIDs from omitempty to omitzero, we can remove the CreateInstallationTokenListRepos method, as it was introduced specifically to allow passing an empty RepositoryIDs slice. However, this would be a breaking change. Thoughts?
There was a problem hiding this comment.
Agreed, done in f0efe56: CreateInstallationTokenRequest.RepositoryIDs now uses omitzero, and CreateInstallationTokenListRepos and its request type are removed. The nil/empty/non-empty test moved to CreateInstallationToken. I also merged master to resolve the conflict.
…ateInstallationToken` Use `omitzero` for `CreateInstallationTokenRequest.RepositoryIDs` so that `CreateInstallationToken` can send an empty `repository_ids` array, which was the only reason for the separate method and request type.
InstallationTokenOptions and InstallationTokenListRepoOptions to ...Request types and pass them by valueInstallationTokenOptions to CreateInstallationTokenRequest, pass it by value, and remove CreateInstallationTokenListRepos
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @JamBalaya56562 and @Not-Dhananjay-Mishra!
LGTM.
Merging.
Updates #3644.
BREAKING CHANGE:
InstallationTokenOptionsis renamed toCreateInstallationTokenRequestandAppsService.CreateInstallationTokennow takes it by value;AppsService.CreateInstallationTokenListReposandInstallationTokenListRepoOptionsare removed in favor ofAppsService.CreateInstallationToken, whoseCreateInstallationTokenRequest.RepositoryIDsnow usesomitzeroso an empty slice is sent as[].POST /app/installations/{installation_id}/access_tokenshas a request body schema with only the optionalrepositories,repository_ids, andpermissions, so no fields are added or removed.CreateInstallationTokenListReposwas added in #3155 (for #3106) only becauseomitemptycould not send an emptyrepository_idsarray. Withjson:"repository_ids,omitzero",CreateInstallationTokencan send it: nil is omitted and[]int64{}is sent as[], so the separate method and request type are no longer needed. Callers ofCreateInstallationTokenListReposcan switch toCreateInstallationTokenwithRepositoryIDs: []int64{}. A caller that already passes an empty slice toCreateInstallationTokennow sends[]instead of omitting the field.With a value parameter, the zero value now sends
{}instead of no body. I checked with a throwaway GitHub App (Metadata read, one selected repository) that no body,{},{"repository_ids":null}, and{"repository_ids":[]}all return the same 201 response, and that each token can access the same repositories (GET /installation/repositories).InstallationTokenOptionsandInstallationTokenListRepoOptionsare removed frombody-allowed-pointer-typesandbody-allowed-wrong-names, and the tests check the request body withtestJSONBodyandtestJSONBodyRaw.The method name already starts with the verb of the GitHub docs operation name ("Create an installation access token for an app"), so it is not renamed.
Verified locally:
go build ./...,go vet -tags integration ./test/integration/,script/test.sh -covermode atomic ./...(all modules, without-race),script/generate.sh --check,script/lint.shincludingcustom-gcl, andscript/check-schema-fields.shreports nothing for this type. (It still reports the 4EnterpriseUpdateBudgetwarnings that master has since #4693; #4699 fixes them.)