-
Notifications
You must be signed in to change notification settings - Fork 36
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
Various cleanup fixes #20
Changes from 18 commits
da528dd
b16591c
8f700e3
8e56293
609d6f8
a7ab67e
b99ef75
26f371c
593d595
644238f
86165a8
908e153
3201aae
45d37bc
a823924
4e207eb
8e6f973
d4b45c7
695828d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
run: | ||
# timeout for analysis, e.g. 30s, 5m, default is 1m | ||
timeout: 1m | ||
tests: false | ||
|
||
linters: | ||
enable: | ||
# Default | ||
- govet | ||
- errcheck | ||
- staticcheck | ||
- unused | ||
- gosimple | ||
- structcheck | ||
- varcheck | ||
- ineffassign | ||
- deadcode | ||
- typecheck | ||
# Extra, see list of https://golangci-lint.run/usage/linters/ | ||
- bodyclose | ||
- golint | ||
# - rowserrcheck is not applicable here | ||
- stylecheck | ||
- gosec | ||
# - interfacer is deprecated | ||
- unconvert | ||
- dupl | ||
- goconst | ||
- gocyclo | ||
- gocognit | ||
- asciicheck | ||
- gofmt | ||
- goimports | ||
- maligned | ||
# - depguard is not applicable here | ||
- misspell | ||
# - lll allow long lines for now, maybe revisit this later | ||
- unparam | ||
- dogsled | ||
- nakedret | ||
- prealloc | ||
- scopelint | ||
- gocritic | ||
- gochecknoinits | ||
- gochecknoglobals | ||
# - godox don't error although there are TODOs in the code | ||
- funlen | ||
- whitespace | ||
# - wsl allow "non-ideomatic" whitespace formattings for now | ||
- goprintffuncname | ||
- gomnd | ||
- goerr113 | ||
# - gomodguard is not applicable here | ||
- godot | ||
# - testpackage is not applicable here | ||
# - nestif is covered by gocognit | ||
# - exportloopref is covered by scopelint | ||
- exhaustive | ||
- nolintlint |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,6 @@ limitations under the License. | |
package bitbucket | ||
|
||
import ( | ||
// Dummy import until we have the implementation ready. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a |
||
_ "github.com/ktrysmt/go-bitbucket" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ import ( | |
) | ||
|
||
const ( | ||
// defaultDomain specifies the default domain used as the backend | ||
// defaultDomain specifies the default domain used as the backend. | ||
defaultDomain = "github.com" | ||
// patUsername is the "username" for the basic auth authentication flow | ||
// when using a personal access token as the "password". This string could | ||
|
@@ -40,21 +40,21 @@ const ( | |
|
||
var ( | ||
// ErrInvalidClientOptions is the error returned when calling NewClient() with | ||
// invalid options (e.g. specifying mutually exclusive options) | ||
// invalid options (e.g. specifying mutually exclusive options). | ||
ErrInvalidClientOptions = errors.New("invalid options given to NewClient()") | ||
// ErrDestructiveCallDisallowed happens when the client isn't set up with WithDestructiveAPICalls() | ||
// but a destructive action is called. | ||
ErrDestructiveCallDisallowed = errors.New("a destructive call was blocked because it wasn't allowed by the client") | ||
) | ||
|
||
// clientOptions is the struct that tracks data about what options have been set | ||
// It is private so that the user must use the With... functions | ||
// It is private so that the user must use the With... functions. | ||
type clientOptions struct { | ||
// Domain specifies the backing domain, which can be arbitrary if the user uses | ||
// GitHub Enterprise. If unset, defaultDomain will be used. | ||
Domain *string | ||
|
||
// ClientFactory is a way to aquire a *http.Client, possibly with auth credentials | ||
// ClientFactory is a way to acquire a *http.Client, possibly with auth credentials | ||
ClientFactory ClientFactory | ||
|
||
// EnableDestructiveAPICalls is a flag to tell whether destructive API calls like | ||
|
@@ -79,6 +79,7 @@ func WithOAuth2Token(oauth2Token string) ClientOption { | |
if opts.ClientFactory != nil { | ||
return fmt.Errorf("authentication http.Client already configured: %w", ErrInvalidClientOptions) | ||
} | ||
|
||
opts.ClientFactory = &oauth2Auth{oauth2Token} | ||
return nil | ||
} | ||
|
@@ -102,7 +103,7 @@ func WithPersonalAccessToken(patToken string) ClientOption { | |
} | ||
} | ||
|
||
// WithClientFactory initializes a Client with a given ClientFactory, used for aquiring the *http.Client later. | ||
// WithClientFactory initializes a Client with a given ClientFactory, used for acquiring the *http.Client later. | ||
// clientFactory must not be nil. | ||
// WithClientFactory is mutually exclusive with WithOAuth2Token and WithPersonalAccessToken. | ||
func WithClientFactory(clientFactory ClientFactory) ClientOption { | ||
|
@@ -150,31 +151,31 @@ func WithDestructiveAPICalls(destructiveActions bool) ClientOption { | |
} | ||
} | ||
|
||
// ClientFactory is a way to aquire a *http.Client, possibly with auth credentials | ||
// ClientFactory is a way to acquire a *http.Client, possibly with auth credentials. | ||
type ClientFactory interface { | ||
// Client returns a *http.Client, possibly with auth credentials | ||
// Client returns a *http.Client, possibly with auth credentials. | ||
Client(ctx context.Context) *http.Client | ||
} | ||
|
||
// oauth2Auth is an implementation of ClientFactory | ||
// oauth2Auth is an implementation of ClientFactory. | ||
type oauth2Auth struct { | ||
token string | ||
} | ||
|
||
// Client returns a *http.Client, possibly with auth credentials | ||
// Client returns a *http.Client, possibly with auth credentials. | ||
func (a *oauth2Auth) Client(ctx context.Context) *http.Client { | ||
ts := oauth2.StaticTokenSource( | ||
&oauth2.Token{AccessToken: a.token}, | ||
) | ||
return oauth2.NewClient(ctx, ts) | ||
} | ||
|
||
// patAuth is an implementation of ClientFactory | ||
// patAuth is an implementation of ClientFactory. | ||
type patAuth struct { | ||
token string | ||
} | ||
|
||
// Client returns a *http.Client, possibly with auth credentials | ||
// Client returns a *http.Client, possibly with auth credentials. | ||
func (a *patAuth) Client(ctx context.Context) *http.Client { | ||
auth := github.BasicAuthTransport{ | ||
Username: patUsername, | ||
|
@@ -223,6 +224,7 @@ func NewClient(ctx context.Context, optFns ...ClientOption) (gitprovider.Client, | |
// the default. | ||
var gh *github.Client | ||
var domain string | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary space? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I started adding all these spaces because of the whitespace linter wsl, but then was just like "nah, I don't care" and left half-way through 😂 |
||
if opts.Domain == nil || *opts.Domain == defaultDomain { | ||
// No domain or the default github.com used | ||
domain = defaultDomain | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,10 @@ import ( | |
"github.com/fluxcd/go-git-providers/gitprovider" | ||
) | ||
|
||
// TeamsClient implements the gitprovider.TeamsClient interface | ||
// TeamsClient implements the gitprovider.TeamsClient interface. | ||
var _ gitprovider.TeamsClient = &TeamsClient{} | ||
|
||
// TeamsClient handles teams organization-wide | ||
// TeamsClient handles teams organization-wide. | ||
type TeamsClient struct { | ||
*clientContext | ||
ref gitprovider.OrganizationRef | ||
|
@@ -50,13 +50,17 @@ func (c *TeamsClient) Get(ctx context.Context, teamName string) (gitprovider.Tea | |
return resp, listErr | ||
}) | ||
if err != nil { | ||
return nil, handleHTTPError(err) | ||
return nil, err | ||
} | ||
|
||
logins := make([]string, 0, len(apiObjs)) | ||
for _, apiObj := range apiObjs { | ||
// TODO: Maybe check for non-empty logins? | ||
logins = append(logins, apiObj.GetLogin()) | ||
// Make sure login isn't nil | ||
if apiObj.Login == nil { | ||
return nil, fmt.Errorf("didn't expect login to be nil for user: %+v: %w", apiObj, gitprovider.ErrInvalidServerData) | ||
} | ||
|
||
logins = append(logins, *apiObj.Login) | ||
} | ||
|
||
return &team{ | ||
|
@@ -69,7 +73,7 @@ func (c *TeamsClient) Get(ctx context.Context, teamName string) (gitprovider.Tea | |
}, nil | ||
} | ||
|
||
// List all teams (recursively, in terms of subgroups) within the specific organization | ||
// List all teams (recursively, in terms of subgroups) within the specific organization. | ||
// | ||
// List returns all available organizations, using multiple paginated requests if needed. | ||
func (c *TeamsClient) List(ctx context.Context) ([]gitprovider.Team, error) { | ||
|
@@ -83,7 +87,7 @@ func (c *TeamsClient) List(ctx context.Context) ([]gitprovider.Team, error) { | |
return resp, listErr | ||
}) | ||
if err != nil { | ||
return nil, handleHTTPError(err) | ||
return nil, err | ||
} | ||
|
||
// Use .Get() to get detailed information about each member | ||
|
@@ -99,6 +103,7 @@ func (c *TeamsClient) List(ctx context.Context) ([]gitprovider.Team, error) { | |
if err != nil { | ||
return nil, err | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another space character here. |
||
teams = append(teams, team) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,10 @@ import ( | |
"github.com/fluxcd/go-git-providers/gitprovider" | ||
) | ||
|
||
// OrganizationsClient implements the gitprovider.OrganizationsClient interface | ||
// OrganizationsClient implements the gitprovider.OrganizationsClient interface. | ||
var _ gitprovider.OrganizationsClient = &OrganizationsClient{} | ||
|
||
// OrganizationsClient operates on organizations the user has access to. | ||
type OrganizationsClient struct { | ||
*clientContext | ||
} | ||
|
@@ -64,7 +65,7 @@ func (c *OrganizationsClient) List(ctx context.Context) ([]gitprovider.Organizat | |
return resp, listErr | ||
}) | ||
if err != nil { | ||
return nil, handleHTTPError(err) | ||
return nil, err | ||
} | ||
|
||
orgs := make([]gitprovider.Organization, 0, len(apiObjs)) | ||
|
@@ -73,6 +74,7 @@ func (c *OrganizationsClient) List(ctx context.Context) ([]gitprovider.Organizat | |
if apiObj.Login == nil { | ||
return nil, fmt.Errorf("didn't expect login to be nil for org: %+v: %w", apiObj, gitprovider.ErrInvalidServerData) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space |
||
orgs = append(orgs, newOrganization(c.clientContext, apiObj, gitprovider.OrganizationRef{ | ||
Domain: c.domain, | ||
Organization: *apiObj.Login, | ||
|
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.
ideomatic
➡idiomatic