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

Factor out a high-level githubClient interface for all operations. #26

Merged
merged 3 commits into from
Aug 18, 2020

Conversation

luxas
Copy link
Collaborator

@luxas luxas commented Aug 17, 2020

This allows us to
a) see, in a consistent way, how all API operations using *github.Client are done, to make sure that
- pagination works
- all returned values are validated first
- HTTP errors are handled consistently
b) later, create mock implementations of the githubClient interface for unit testing of the client
c) focus on high-level operations in the main clients, not Github API details or pagination/validation/error handling.

cc @twelho @dinosk please review

@luxas luxas added this to the v0.0.1 milestone Aug 17, 2020
@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2020

Codecov Report

Merging #26 into master will decrease coverage by 1.24%.
The diff coverage is 28.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #26      +/-   ##
==========================================
- Coverage   54.86%   53.62%   -1.25%     
==========================================
  Files          22       23       +1     
  Lines        1068     1130      +62     
==========================================
+ Hits          586      606      +20     
- Misses        447      484      +37     
- Partials       35       40       +5     
Impacted Files Coverage Δ
github/auth.go 57.27% <ø> (ø)
github/client_organization_teams.go 0.00% <0.00%> (ø)
github/client_repositories_user.go 0.00% <0.00%> (ø)
github/client_repository_deploykey.go 0.00% <0.00%> (ø)
github/client_repository_teamaccess.go 0.00% <0.00%> (ø)
github/resource_deploykey.go 0.00% <0.00%> (ø)
github/resource_teamaccess.go 22.22% <0.00%> (+4.04%) ⬆️
github/githubclient.go 27.15% <27.15%> (ø)
github/resource_organization.go 84.00% <50.00%> (-6.48%) ⬇️
github/client_organizations.go 70.00% <66.66%> (-1.43%) ⬇️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 971412c...13f3fbe. Read the comment docs.

Copy link

@twelho twelho left a comment

Choose a reason for hiding this comment

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

A couple nits, otherwise LGTM 🥇
Thanks @luxas!

return nil, err
}
keys = append(keys, k)
keys = append(keys, newDeployKey(c, apiObj))
Copy link

Choose a reason for hiding this comment

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

Add comment for consistency with other similar cases: // apiObj is already validated at ListKeys

@@ -17,6 +17,8 @@ limitations under the License.
package github

import (
"fmt"

"github.com/google/go-github/v32/github"

Copy link

Choose a reason for hiding this comment

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

Unnecessary newline

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Stefan wanted our internal imports to be separate from external, so I'll hold this for now

// validateOrganizationAPI validates the apiObj received from the server, to make sure that it is
// valid for our use.
func validateOrganizationAPI(apiObj *github.Organization) error {
if apiObj.Login == nil {
Copy link

Choose a reason for hiding this comment

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

This could probably use validateAPIObject like validateDeployKeyAPI does, wdyt?

@luxas luxas changed the title Carving out a high-level githubClient interface for all operations. Factor out a high-level githubClient interface for all operations. Aug 18, 2020
Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@luxas luxas merged commit ee897f0 into master Aug 18, 2020
@luxas luxas deleted the github_client_interface branch August 18, 2020 14:28
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.

4 participants