Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
84 changes: 62 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,76 @@
# Visit https://golangci-lint.run/ for usage documentation
# and information on other useful linters

version: "2"
run:
deadline: 3m
modules-download-mode: vendor

issues:
max-per-linter: 0
max-same-issues: 0

linters:
disable-all: true
default: none

enable:
- copyloopvar
- durationcheck
- errcheck
- exportloopref
# - forcetypeassert
# - godot
- gofmt
- gosimple
- errname
- errorlint
# - forcetypeassert TODO: Re-enable when we can fix the issues
- godot
- govet
- ineffassign
- makezero
- misspell
# - nilerr
# - predeclared
- modernize
- nilerr
- predeclared
- staticcheck
- tenv
- unconvert
# - unparam
- unparam
- unused
- vet
- usetesting

exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
rules:
- path: _test\.go
linters:
- unparam
text: always receives

issues:
max-issues-per-linter: 0
max-same-issues: 0

formatters:
enable:
- gofmt
- gofumpt
- goimports

settings:
gofmt:
simplify: true
rewrite-rules:
- pattern: interface{}
replacement: any
- pattern: a[b:len(a)]
replacement: a[b:]
gofumpt:
module-path: github.com/integrations/terraform-provider-github
extra-rules: true
goimports:
local-prefixes:
- github.com/integrations/terraform-provider-github

linters-settings:
errcheck:
ignore: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema:ForceNew|Set,fmt:.*,io:Close
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
18 changes: 4 additions & 14 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
TEST?=$$(go list ./... |grep -v 'vendor')
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=github

default: build

tools:
go install github.com/client9/misspell/cmd/[email protected]
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.1
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.0

build: fmtcheck
CGO_ENABLED=0 go build -ldflags="-s -w" ./...

fmt:
@echo "==> Fixing source code with gofmt..."
gofmt -s -w $(GOFMT_FILES)
@echo "==> Fixing source code with golangci-lint..."
golangci-lint fmt ./...

fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
Expand All @@ -38,15 +37,6 @@ test-compile:
fi
CGO_ENABLED=0 go test -c $(TEST) $(TESTARGS)

vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi

website:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
Expand All @@ -65,4 +55,4 @@ ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

.PHONY: build test testacc vet fmt fmtcheck lint tools test-compile website website-lint website-test
.PHONY: build test testacc fmt fmtcheck lint tools test-compile website website-lint website-test
3 changes: 1 addition & 2 deletions github/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GenerateOAuthTokenFromApp(baseURL, appID, appInstallationID, pemData string
return token, nil
}

func getInstallationAccessToken(baseURL string, jwt string, installationID string) (string, error) {
func getInstallationAccessToken(baseURL, jwt, installationID string) (string, error) {
if baseURL != "https://api.github.com/" && !GHECDataResidencyMatch.MatchString(baseURL) {
baseURL += "api/v3/"
}
Expand Down Expand Up @@ -87,7 +87,6 @@ func generateAppJWT(appID string, now time.Time, pemData []byte) (string, error)
jose.SigningKey{Algorithm: jose.RS256, Key: privateKey},
(&jose.SignerOptions{}).WithType("JWT"),
)

if err != nil {
return "", err
}
Expand Down
1 change: 0 additions & 1 deletion github/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ func TestGetInstallationAccessToken(t *testing.T) {
defer ts.Close()

accessToken, err := getInstallationAccessToken(ts.URL+"/", fakeJWT, testGitHubAppInstallationID)

if err != nil {
t.Logf("Unexpected error: %s", err)
t.Fail()
Expand Down
9 changes: 2 additions & 7 deletions github/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ type Owner struct {
// https://[hostname].ghe.com instances expect paths that behave similar to GitHub.com, not GitHub Enterprise Server.
var GHECDataResidencyMatch = regexp.MustCompile(`^https:\/\/[a-zA-Z0-9.\-]*\.ghe\.com$`)

func RateLimitedHTTPClient(client *http.Client, writeDelay time.Duration, readDelay time.Duration, retryDelay time.Duration, parallelRequests bool, retryableErrors map[int]bool, maxRetries int) *http.Client {

func RateLimitedHTTPClient(client *http.Client, writeDelay, readDelay, retryDelay time.Duration, parallelRequests bool, retryableErrors map[int]bool, maxRetries int) *http.Client {
client.Transport = NewEtagTransport(client.Transport)
client.Transport = NewRateLimitTransport(client.Transport, WithWriteDelay(writeDelay), WithReadDelay(readDelay), WithParallelRequests(parallelRequests))
client.Transport = logging.NewSubsystemLoggingHTTPTransport("GitHub", client.Transport)
Expand All @@ -59,7 +58,6 @@ func RateLimitedHTTPClient(client *http.Client, writeDelay time.Duration, readDe
}

func (c *Config) AuthenticatedHTTPClient() *http.Client {

ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: c.Token},
Expand All @@ -79,7 +77,6 @@ func (c *Config) AnonymousHTTPClient() *http.Client {
}

func (c *Config) NewGraphQLClient(client *http.Client) (*githubv4.Client, error) {

uv4, err := url.Parse(c.BaseURL)
if err != nil {
return nil, err
Expand All @@ -95,7 +92,6 @@ func (c *Config) NewGraphQLClient(client *http.Client) (*githubv4.Client, error)
}

func (c *Config) NewRESTClient(client *http.Client) (*github.Client, error) {

uv3, err := url.Parse(c.BaseURL)
if err != nil {
return nil, err
Expand Down Expand Up @@ -143,8 +139,7 @@ func (c *Config) ConfigureOwner(owner *Owner) (*Owner, error) {

// Meta returns the meta parameter that is passed into subsequent resources
// https://godoc.org/github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema#ConfigureFunc
func (c *Config) Meta() (interface{}, error) {

func (c *Config) Meta() (any, error) {
var client *http.Client
if c.Anonymous() {
client = c.AnonymousHTTPClient()
Expand Down
18 changes: 1 addition & 17 deletions github/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,12 @@ func TestGHECDataResidencyMatch(t *testing.T) {
}

func TestAccConfigMeta(t *testing.T) {

// FIXME: Skip test runs during travis lint checking
if testToken == "" {
return
}

t.Run("returns an anonymous client for the v3 REST API", func(t *testing.T) {

config := Config{BaseURL: "https://api.github.com/"}
meta, err := config.Meta()
if err != nil {
Expand All @@ -86,18 +84,14 @@ func TestAccConfigMeta(t *testing.T) {
if err != nil {
t.Fatalf("failed to validate returned client without error: %s", err.Error())
}

})

t.Run("returns an anonymous client for the v4 GraphQL API", func(t *testing.T) {

// https://developer.github.com/v4/guides/forming-calls/#authenticating-with-graphql
t.Skip("anonymous client for the v4 GraphQL API is unsupported")

})

t.Run("returns a v3 REST API client to manage individual resources", func(t *testing.T) {

config := Config{
Token: testToken,
BaseURL: "https://api.github.com/",
Expand All @@ -113,11 +107,9 @@ func TestAccConfigMeta(t *testing.T) {
if err != nil {
t.Fatalf("failed to validate returned client without error: %s", err.Error())
}

})

t.Run("returns a v3 REST API client with max retries", func(t *testing.T) {

config := Config{
Token: testToken,
BaseURL: "https://api.github.com/",
Expand All @@ -138,11 +130,9 @@ func TestAccConfigMeta(t *testing.T) {
if err != nil {
t.Fatalf("failed to validate returned client without error: %s", err.Error())
}

})

t.Run("returns a v4 GraphQL API client to manage individual resources", func(t *testing.T) {

config := Config{
Token: testToken,
BaseURL: "https://api.github.com/",
Expand All @@ -162,11 +152,9 @@ func TestAccConfigMeta(t *testing.T) {
if err != nil {
t.Fatalf("failed to validate returned client without error: %s", err.Error())
}

})

t.Run("returns a v3 REST API client to manage organization resources", func(t *testing.T) {

config := Config{
Token: testToken,
BaseURL: "https://api.github.com/",
Expand All @@ -183,11 +171,9 @@ func TestAccConfigMeta(t *testing.T) {
if err != nil {
t.Fatalf("failed to validate returned client without error: %s", err.Error())
}

})

t.Run("returns a v4 GraphQL API client to manage organization resources", func(t *testing.T) {

config := Config{
Token: testToken,
BaseURL: "https://api.github.com/",
Expand All @@ -205,7 +191,7 @@ func TestAccConfigMeta(t *testing.T) {
ViewerCanAdminister githubv4.Boolean
} `graphql:"organization(login: $login)"`
}
variables := map[string]interface{}{
variables := map[string]any{
"login": githubv4.String(testOrganization),
}
err = client.Query(context.Background(), &query, variables)
Expand All @@ -216,7 +202,5 @@ func TestAccConfigMeta(t *testing.T) {
if query.Organization.ViewerCanAdminister != true {
t.Fatalf("unexpected response when validating client")
}

})

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func dataSourceGithubActionsEnvironmentPublicKey() *schema.Resource {
}
}

func dataSourceGithubActionsEnvironmentPublicKeyRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceGithubActionsEnvironmentPublicKeyRead(d *schema.ResourceData, meta any) error {
client := meta.(*Owner).v3client
owner := meta.(*Owner).name
repository := d.Get("repository").(string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import (
)

func TestAccGithubActionsEnvironmentPublicKeyDataSource(t *testing.T) {

randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

t.Run("queries a repository environment public key without error", func(t *testing.T) {

config := fmt.Sprintf(`
resource "github_repository" "test" {
name = "tf-acc-test-%[1]s"
Expand Down Expand Up @@ -60,6 +58,5 @@ func TestAccGithubActionsEnvironmentPublicKeyDataSource(t *testing.T) {
t.Run("with an organization account", func(t *testing.T) {
testCase(t, organization)
})

})
}
4 changes: 2 additions & 2 deletions github/data_source_github_actions_environment_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func dataSourceGithubActionsEnvironmentSecrets() *schema.Resource {
}
}

func dataSourceGithubActionsEnvironmentSecretsRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceGithubActionsEnvironmentSecretsRead(d *schema.ResourceData, meta any) error {
client := meta.(*Owner).v3client
owner := meta.(*Owner).name
var repoName string
Expand Down Expand Up @@ -109,7 +109,7 @@ func dataSourceGithubActionsEnvironmentSecretsRead(d *schema.ResourceData, meta
}

d.SetId(buildTwoPartID(repoName, envName))
d.Set("secrets", all_secrets)
_ = d.Set("secrets", all_secrets)

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

func TestAccGithubActionsEnvironmentSecretsDataSource(t *testing.T) {

t.Run("queries actions secrets from an environment", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

Expand Down
4 changes: 2 additions & 2 deletions github/data_source_github_actions_environment_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func dataSourceGithubActionsEnvironmentVariables() *schema.Resource {
}
}

func dataSourceGithubActionsEnvironmentVariablesRead(d *schema.ResourceData, meta interface{}) error {
func dataSourceGithubActionsEnvironmentVariablesRead(d *schema.ResourceData, meta any) error {
client := meta.(*Owner).v3client
owner := meta.(*Owner).name
var repoName string
Expand Down Expand Up @@ -109,7 +109,7 @@ func dataSourceGithubActionsEnvironmentVariablesRead(d *schema.ResourceData, met
}

d.SetId(buildTwoPartID(repoName, envName))
d.Set("variables", all_variables)
_ = d.Set("variables", all_variables)

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

func TestAccGithubActionsEnvironmentVariablesDataSource(t *testing.T) {

t.Run("queries actions variables from an environment", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

Expand Down
Loading
Loading