From 67956ca230c8449de0ca6697677adc11a8e7f4cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Wysoki=C5=84ski?= Date: Sun, 26 Nov 2023 14:16:32 +0100 Subject: [PATCH] chore: update golangci-lint and its config (#17) --- .github/workflows/ci.yml | 2 +- .golangci.yml | 392 +++++++++++++++++- .pre-commit-config.yaml | 2 +- Makefile | 2 +- internal/data_source_repository.go | 29 +- internal/data_source_repository_cron.go | 29 +- internal/data_source_repository_registry.go | 32 +- internal/data_source_repository_secret.go | 34 +- internal/data_source_repository_test.go | 12 +- internal/data_source_secret.go | 22 +- internal/data_source_user.go | 22 +- internal/internal_test.go | 45 +- internal/models.go | 9 +- internal/provider.go | 9 +- internal/resource_repository.go | 36 +- internal/resource_repository_cron.go | 41 +- internal/resource_repository_cron_test.go | 24 +- internal/resource_repository_registry.go | 47 ++- internal/resource_repository_registry_test.go | 35 +- internal/resource_repository_secret.go | 51 ++- internal/resource_repository_secret_test.go | 30 +- internal/resource_repository_test.go | 48 ++- internal/resource_secret.go | 21 +- internal/resource_user.go | 19 +- 24 files changed, 841 insertions(+), 152 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 501b2b4..2510f57 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: - run: make generate && go mod tidy && git diff --exit-code go.mod docs/ examples/ - uses: golangci/golangci-lint-action@v3 with: - version: v1.54 + version: v1.55 - name: Gitea 1.20 & Woodpecker 1.0 run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... env: diff --git a/.golangci.yml b/.golangci.yml index 1396e07..dd0ffb1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,7 +10,6 @@ linters: - bodyclose - bidichk - exportloopref - - depguard - errcheck - gocritic - gosec @@ -30,8 +29,6 @@ linters: - nestif - thelper - nonamedreturns - - gocyclo - - gomnd - tenv - testpackage - noctx @@ -51,27 +48,19 @@ linters: - predeclared - promlinter - wastedassign + - testifylint + - inamedparam + - sloglint + - revive linters-settings: tagliatelle: case: rules: json: camel - tfsdk: snake + bun: snake lll: - line-length: 150 - gocyclo: - min-complexity: 10 - depguard: - rules: - main: - files: - - "$all" - deny: - - pkg: reflect - desc: Please don't use reflect package - - pkg: github.com/pkg/errors - desc: Should be replaced by standard lib errors package + line-length: 120 govet: enable: - asmdecl @@ -109,18 +98,375 @@ linters-settings: - unsafeptr - unusedresult - unusedwrite - gomnd: - ignored-functions: - - strconv.FormatInt - - strconv.ParseInt + testifylint: + enable-all: true + sloglint: + attr-only: true + revive: + rules: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#add-constant + - name: add-constant + severity: warning + disabled: true + arguments: + - maxLitCount: "3" + allowStrs: "\"\"" + ignoreFuncs: os.Exit,wg.Add,make + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#argument-limit + - name: argument-limit + severity: warning + disabled: true + arguments: [4] + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#atomic + - name: atomic + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#banned-characters + - name: banned-characters + severity: warning + disabled: true + arguments: [] + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bare-return + - name: bare-return + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#blank-imports + - name: blank-imports + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr + - name: bool-literal-in-expr + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#call-to-gc + - name: call-to-gc + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#cognitive-complexity + - name: cognitive-complexity + severity: warning + disabled: true + arguments: [7] + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#comment-spacings + - name: comment-spacings + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#confusing-naming + - name: confusing-naming + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#confusing-results + - name: confusing-results + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#constant-logical-expr + - name: constant-logical-expr + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-as-argument + - name: context-as-argument + severity: error + disabled: false + arguments: + - allowTypesBefore: "*testing.T,testing.TB" + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-keys-type + - name: context-keys-type + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#cyclomatic + - name: cyclomatic + severity: warning + disabled: false + arguments: [10] + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#datarace + - name: datarace + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#deep-exit + - name: deep-exit + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#defer + - name: defer + severity: error + disabled: false + arguments: + - [call-chain, loop] + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#dot-imports + - name: dot-imports + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#duplicated-imports + - name: duplicated-imports + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#early-return + - name: early-return + severity: error + disabled: false + arguments: + - preserveScope + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-block + - name: empty-block + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines + - name: empty-lines + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#enforce-map-style + - name: enforce-map-style + severity: error + disabled: false + arguments: + - make + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-naming + - name: error-naming + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-return + - name: error-return + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-strings + - name: error-strings + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#errorf + - name: errorf + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#exported + - name: exported + severity: warning + disabled: true + arguments: + - preserveScope + - checkPrivateReceivers + - sayRepetitiveInsteadOfStutters + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#file-header + - name: file-header + severity: warning + disabled: true + arguments: + - This is the text that must appear at the top of source files. + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#flag-parameter + - name: flag-parameter + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#function-result-limit + - name: function-result-limit + severity: warning + disabled: false + arguments: [3] + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#function-length + - name: function-length + severity: warning + disabled: true + arguments: [10, 0] + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#get-return + - name: get-return + severity: warning + disabled: true + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#identical-branches + - name: identical-branches + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#if-return + - name: if-return + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#increment-decrement + - name: increment-decrement + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#indent-error-flow + - name: indent-error-flow + severity: warning + disabled: false + arguments: + - preserveScope + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-alias-naming + - name: import-alias-naming + severity: warning + disabled: false + arguments: + - ^[a-z][a-z0-9]{0,}$ + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#imports-blacklist + - name: imports-blacklist + severity: error + disabled: false + arguments: + - reflect + - github.com/pkg/errors + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing + - name: import-shadowing + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#line-length-limit + - name: line-length-limit + severity: warning + # lll is enabled + disabled: true + arguments: [80] + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#max-public-structs + - name: max-public-structs + severity: warning + disabled: true + arguments: [3] + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#modifies-parameter + - name: modifies-parameter + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#modifies-value-receiver + - name: modifies-value-receiver + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#nested-structs + - name: nested-structs + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#optimize-operands-order + - name: optimize-operands-order + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#package-comments + - name: package-comments + severity: warning + disabled: true + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range + - name: range + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range-val-in-closure + - name: range-val-in-closure + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range-val-address + - name: range-val-address + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#receiver-naming + - name: receiver-naming + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#redundant-import-alias + - name: redundant-import-alias + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#redefines-builtin-id + - name: redefines-builtin-id + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-of-int + - name: string-of-int + severity: warning + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-format + - name: string-format + severity: warning + disabled: true + arguments: + - - core.WriteError[1].Message + - /^([^A-Z]|$)/ + - must not start with a capital letter + - - fmt.Errorf[0] + - /(^|[^\.!?])$/ + - must not end in punctuation + - - panic + - /^[^\n]*$/ + - must not contain line breaks + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag + - name: struct-tag + arguments: + - json,inline + - bson,outline,gnu + severity: warning + # tagliatelle is enabled + disabled: true + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#superfluous-else + - name: superfluous-else + severity: error + disabled: false + arguments: + - preserveScope + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#time-equal + - name: time-equal + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#time-naming + - name: time-naming + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-naming + - name: var-naming + severity: error + disabled: false + arguments: + - [] # AllowList + - [] # DenyList + - - upperCaseConst: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-declaration + - name: var-declaration + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unconditional-recursion + - name: unconditional-recursion + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-naming + - name: unexported-naming + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-return + - name: unexported-return + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unhandled-error + - name: unhandled-error + severity: warning + disabled: false + arguments: + - fmt.Printf + - fmt.Println + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unnecessary-stmt + - name: unnecessary-stmt + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unreachable-code + - name: unreachable-code + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter + - name: unused-parameter + severity: error + disabled: false + arguments: + - allowRegex: ^_ + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver + - name: unused-receiver + severity: error + disabled: true + arguments: + - allowRegex: ^_ + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#useless-break + - name: useless-break + severity: error + disabled: false + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#waitgroup-by-value + - name: waitgroup-by-value + severity: warning + disabled: false + issues: exclude-rules: # Exclude some linters from running on tests files. - path: _test\.go linters: - - dupl - - gocyclo + - gosec + - path: _test\.go + text: deep-exit - linters: - lll source: "^//go:generate " diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ba3868d..b672273 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,6 +6,6 @@ repos: stages: [commit-msg] additional_dependencies: ['@commitlint/config-conventional'] - repo: https://github.com/golangci/golangci-lint - rev: v1.54.2 + rev: v1.55.2 hooks: - id: golangci-lint diff --git a/Makefile b/Makefile index d63dfaa..729dadb 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ install-tfplugindocs: .PHONY: install-golangci-lint install-golangci-lint: @echo "Installing github.com/golangci/golangci-lint..." - @(test -f $(GOLANGCI_LINT_PATH) && echo "github.com/golangci/golangci-lint is already installed. Skipping...") || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.54.2 + @(test -f $(GOLANGCI_LINT_PATH) && echo "github.com/golangci/golangci-lint is already installed. Skipping...") || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.55.2 .PHONY: install-tools install-tools: install-golangci-lint install-tfplugindocs diff --git a/internal/data_source_repository.go b/internal/data_source_repository.go index 6a3859d..5a07217 100644 --- a/internal/data_source_repository.go +++ b/internal/data_source_repository.go @@ -20,11 +20,19 @@ func newRepositoryDataSource() datasource.DataSource { return &repositoryDataSource{} } -func (d *repositoryDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *repositoryDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_repository" } -func (d *repositoryDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *repositoryDataSource) Schema( + _ context.Context, + _ datasource.SchemaRequest, + resp *datasource.SchemaResponse, +) { resp.Schema = schema.Schema{ MarkdownDescription: "Use this data source to retrieve information about a repository.", Attributes: map[string]schema.Attribute{ @@ -91,8 +99,9 @@ func (d *repositoryDataSource) Schema(_ context.Context, _ datasource.SchemaRequ Description: "when true, every pipeline needs to be approved before being executed", }, "allow_pull_requests": schema.BoolAttribute{ - Computed: true, - Description: "Enables handling webhook's pull request event. If disabled, then pipeline won't run for pull requests.", + Computed: true, + Description: "Enables handling webhook's pull request event." + + " If disabled, then pipeline won't run for pull requests.", }, "config_file": schema.StringAttribute{ Computed: true, @@ -103,13 +112,18 @@ func (d *repositoryDataSource) Schema(_ context.Context, _ datasource.SchemaRequ "netrc_only_trusted": schema.BoolAttribute{ Computed: true, MarkdownDescription: "whether netrc credentials should be only injected into trusted containers, " + + //nolint:lll "see [the docs](https://woodpecker-ci.org/docs/usage/project-settings#only-inject-netrc-credentials-into-trusted-containers) for more info", }, }, } } -func (d *repositoryDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *repositoryDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { // Prevent panic if the provider has not been configured. if req.ProviderData == nil { return @@ -119,7 +133,10 @@ func (d *repositoryDataSource) Configure(_ context.Context, req datasource.Confi if !ok { resp.Diagnostics.AddError( "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + fmt.Sprintf( + "Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), ) return } diff --git a/internal/data_source_repository_cron.go b/internal/data_source_repository_cron.go index bc1bd97..ac0c4c7 100644 --- a/internal/data_source_repository_cron.go +++ b/internal/data_source_repository_cron.go @@ -20,11 +20,19 @@ func newRepositoryCronDataSource() datasource.DataSource { return &repositoryCronDataSource{} } -func (d *repositoryCronDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *repositoryCronDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_repository_cron" } -func (d *repositoryCronDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *repositoryCronDataSource) Schema( + _ context.Context, + _ datasource.SchemaRequest, + resp *datasource.SchemaResponse, +) { resp.Schema = schema.Schema{ MarkdownDescription: "Use this data source to retrieve information about a cron job in a specific repository.", Attributes: map[string]schema.Attribute{ @@ -60,7 +68,11 @@ func (d *repositoryCronDataSource) Schema(_ context.Context, _ datasource.Schema } } -func (d *repositoryCronDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *repositoryCronDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { // Prevent panic if the provider has not been configured. if req.ProviderData == nil { return @@ -70,7 +82,10 @@ func (d *repositoryCronDataSource) Configure(_ context.Context, req datasource.C if !ok { resp.Diagnostics.AddError( "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + fmt.Sprintf( + "Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), ) return } @@ -78,7 +93,11 @@ func (d *repositoryCronDataSource) Configure(_ context.Context, req datasource.C d.client = client } -func (d *repositoryCronDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *repositoryCronDataSource) Read( + ctx context.Context, + req datasource.ReadRequest, + resp *datasource.ReadResponse, +) { var data repositoryCronModel resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) diff --git a/internal/data_source_repository_registry.go b/internal/data_source_repository_registry.go index 6ed83a8..9fc85e2 100644 --- a/internal/data_source_repository_registry.go +++ b/internal/data_source_repository_registry.go @@ -20,13 +20,22 @@ func newRepositoryRegistryDataSource() datasource.DataSource { return &repositoryRegistryDataSource{} } -func (d *repositoryRegistryDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *repositoryRegistryDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_repository_registry" } -func (d *repositoryRegistryDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *repositoryRegistryDataSource) Schema( + _ context.Context, + _ datasource.SchemaRequest, + resp *datasource.SchemaResponse, +) { resp.Schema = schema.Schema{ - MarkdownDescription: "Use this data source to retrieve information about a container registry in a specific repository.", + MarkdownDescription: "Use this data source to retrieve information about a container registry" + + " in a specific repository.", Attributes: map[string]schema.Attribute{ "id": schema.Int64Attribute{ Computed: true, @@ -52,7 +61,11 @@ func (d *repositoryRegistryDataSource) Schema(_ context.Context, _ datasource.Sc } } -func (d *repositoryRegistryDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *repositoryRegistryDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { // Prevent panic if the provider has not been configured. if req.ProviderData == nil { return @@ -62,7 +75,10 @@ func (d *repositoryRegistryDataSource) Configure(_ context.Context, req datasour if !ok { resp.Diagnostics.AddError( "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + fmt.Sprintf( + "Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), ) return } @@ -70,7 +86,11 @@ func (d *repositoryRegistryDataSource) Configure(_ context.Context, req datasour d.client = client } -func (d *repositoryRegistryDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *repositoryRegistryDataSource) Read( + ctx context.Context, + req datasource.ReadRequest, + resp *datasource.ReadResponse, +) { var data repositoryRegistryDataSourceModel resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) diff --git a/internal/data_source_repository_secret.go b/internal/data_source_repository_secret.go index 4cf64af..ee65f05 100644 --- a/internal/data_source_repository_secret.go +++ b/internal/data_source_repository_secret.go @@ -21,11 +21,19 @@ func newRepositorySecretDataSource() datasource.DataSource { return &repositorySecretDataSource{} } -func (d *repositorySecretDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *repositorySecretDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_repository_secret" } -func (d *repositorySecretDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) { +func (d *repositorySecretDataSource) Schema( + _ context.Context, + _ datasource.SchemaRequest, + resp *datasource.SchemaResponse, +) { resp.Schema = schema.Schema{ MarkdownDescription: "Use this data source to retrieve information about a secret in a specific repository.", Attributes: map[string]schema.Attribute{ @@ -47,8 +55,9 @@ func (d *repositorySecretDataSource) Schema(_ context.Context, _ datasource.Sche Description: "events for which the secret is available (push, tag, pull_request, deployment, cron, manual)", }, "plugins_only": schema.BoolAttribute{ - Computed: true, - MarkdownDescription: "whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)", + Computed: true, + MarkdownDescription: "whether secret is only available for " + + "[plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)", }, "images": schema.SetAttribute{ ElementType: types.StringType, @@ -59,7 +68,11 @@ func (d *repositorySecretDataSource) Schema(_ context.Context, _ datasource.Sche } } -func (d *repositorySecretDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *repositorySecretDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { // Prevent panic if the provider has not been configured. if req.ProviderData == nil { return @@ -69,7 +82,10 @@ func (d *repositorySecretDataSource) Configure(_ context.Context, req datasource if !ok { resp.Diagnostics.AddError( "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + fmt.Sprintf( + "Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), ) return } @@ -77,7 +93,11 @@ func (d *repositorySecretDataSource) Configure(_ context.Context, req datasource d.client = client } -func (d *repositorySecretDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { +func (d *repositorySecretDataSource) Read( + ctx context.Context, + req datasource.ReadRequest, + resp *datasource.ReadResponse, +) { var data repositorySecretDataSourceModel resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) diff --git a/internal/data_source_repository_test.go b/internal/data_source_repository_test.go index 668ef03..d475779 100644 --- a/internal/data_source_repository_test.go +++ b/internal/data_source_repository_test.go @@ -29,7 +29,11 @@ data "woodpecker_repository" "test_repo" { `, repo.FullName), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.woodpecker_repository.test_repo", "id"), - resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "forge_remote_id", strconv.FormatInt(repo.ID, 10)), + resource.TestCheckResourceAttr( + "data.woodpecker_repository.test_repo", + "forge_remote_id", + strconv.FormatInt(repo.ID, 10), + ), resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "name", repo.Name), resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "owner", repo.Owner.UserName), resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "full_name", repo.FullName), @@ -39,7 +43,11 @@ data "woodpecker_repository" "test_repo" { resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "scm", "git"), resource.TestCheckResourceAttrSet("data.woodpecker_repository.test_repo", "timeout"), resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "visibility", "public"), - resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "is_private", strconv.FormatBool(repo.Private)), + resource.TestCheckResourceAttr( + "data.woodpecker_repository.test_repo", + "is_private", + strconv.FormatBool(repo.Private), + ), resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "is_trusted", "false"), resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "is_gated", "false"), resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "allow_pull_requests", "true"), diff --git a/internal/data_source_secret.go b/internal/data_source_secret.go index dd5172c..d50538b 100644 --- a/internal/data_source_secret.go +++ b/internal/data_source_secret.go @@ -21,7 +21,11 @@ func newSecretDataSource() datasource.DataSource { return &secretDataSource{} } -func (d *secretDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *secretDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_secret" } @@ -43,8 +47,9 @@ func (d *secretDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, Description: "events for which the secret is available (push, tag, pull_request, deployment, cron, manual)", }, "plugins_only": schema.BoolAttribute{ - Computed: true, - MarkdownDescription: "whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)", + Computed: true, + MarkdownDescription: "whether secret is only available for " + + "[plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)", }, "images": schema.SetAttribute{ ElementType: types.StringType, @@ -55,7 +60,11 @@ func (d *secretDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, } } -func (d *secretDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *secretDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { // Prevent panic if the provider has not been configured. if req.ProviderData == nil { return @@ -65,7 +74,10 @@ func (d *secretDataSource) Configure(_ context.Context, req datasource.Configure if !ok { resp.Diagnostics.AddError( "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + fmt.Sprintf( + "Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), ) return } diff --git a/internal/data_source_user.go b/internal/data_source_user.go index 2421707..0de54c9 100644 --- a/internal/data_source_user.go +++ b/internal/data_source_user.go @@ -20,7 +20,11 @@ func newUserDataSource() datasource.DataSource { return &userDataSource{} } -func (d *userDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { +func (d *userDataSource) Metadata( + _ context.Context, + req datasource.MetadataRequest, + resp *datasource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_user" } @@ -33,8 +37,9 @@ func (d *userDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, r Description: "the user's id", }, "login": schema.StringAttribute{ - Required: true, - Description: "The user's login. Use an empty string \"\" to retrieve information about the currently authenticated user.", + Required: true, + Description: "The user's login. " + + "Use an empty string \"\" to retrieve information about the currently authenticated user.", }, "email": schema.StringAttribute{ Computed: true, @@ -56,7 +61,11 @@ func (d *userDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, r } } -func (d *userDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { +func (d *userDataSource) Configure( + _ context.Context, + req datasource.ConfigureRequest, + resp *datasource.ConfigureResponse, +) { // Prevent panic if the provider has not been configured. if req.ProviderData == nil { return @@ -66,7 +75,10 @@ func (d *userDataSource) Configure(_ context.Context, req datasource.ConfigureRe if !ok { resp.Diagnostics.AddError( "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + fmt.Sprintf( + "Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), ) return } diff --git a/internal/internal_test.go b/internal/internal_test.go index 00e1ebc..cdd28a9 100644 --- a/internal/internal_test.go +++ b/internal/internal_test.go @@ -48,7 +48,13 @@ func TestMain(m *testing.M) { giteaClient = newGiteaClient(resourceGitea.httpURL, resourceGitea.user) - resourceWoodpecker := runWoodpecker(pool, network, resourceGitea.httpURL, resourceGitea.privateHTTPURL, resourceGitea.user) + resourceWoodpecker := runWoodpecker( + pool, + network, + resourceGitea.httpURL, + resourceGitea.privateHTTPURL, + resourceGitea.user, + ) deferFuncs = append(deferFuncs, func() { _ = resourceWoodpecker.Close() }) @@ -68,7 +74,6 @@ func TestMain(m *testing.M) { } os.Exit(code) - } func newDockertestPool() *dockertest.Pool { @@ -103,7 +108,8 @@ type giteaResource struct { func runGitea(pool *dockertest.Pool, network *dockertest.Network) giteaResource { repo, tag := getGiteaRepoTag() - gitea, err := pool.RunWithOptions(&dockertest.RunOptions{ + + giteaRsc, err := pool.RunWithOptions(&dockertest.RunOptions{ Repository: repo, Tag: tag, Networks: []*dockertest.Network{network}, @@ -120,13 +126,13 @@ func runGitea(pool *dockertest.Pool, network *dockertest.Network) giteaResource log.Fatalf("couldn't run gitea: %s", err) } - if err = gitea.Expire(giteaContainerExpInSec); err != nil { + if err = giteaRsc.Expire(giteaContainerExpInSec); err != nil { log.Fatal(err) } httpURL := &urlpkg.URL{ Scheme: "http", - Host: getHostPort(gitea, "3000/tcp"), + Host: getHostPort(giteaRsc, "3000/tcp"), } if err = pool.Retry(func() error { @@ -158,13 +164,13 @@ func runGitea(pool *dockertest.Pool, network *dockertest.Network) giteaResource } return giteaResource{ - docker: gitea, + docker: giteaRsc, httpURL: httpURL, privateHTTPURL: &urlpkg.URL{ Scheme: httpURL.Scheme, - Host: gitea.GetIPInNetwork(network) + ":3000", + Host: giteaRsc.GetIPInNetwork(network) + ":3000", }, - user: createGiteaUser(pool, gitea), + user: createGiteaUser(pool, giteaRsc), } } @@ -174,7 +180,8 @@ func (r giteaResource) Close() error { const defaultGiteaImage = "gitea/gitea:1.20" -func getGiteaRepoTag() (string, string) { +//nolint:nonamedreturns +func getGiteaRepoTag() (repository string, tag string) { val := os.Getenv("GITEA_IMAGE") if val == "" { val = defaultGiteaImage @@ -182,7 +189,7 @@ func getGiteaRepoTag() (string, string) { return docker.ParseRepositoryTag(val) } -func createGiteaUser(pool *dockertest.Pool, gitea *dockertest.Resource) *urlpkg.Userinfo { +func createGiteaUser(pool *dockertest.Pool, giteaRsc *dockertest.Resource) *urlpkg.Userinfo { username := strings.ReplaceAll(uuid.NewString(), "-", "") password := uuid.NewString() @@ -190,7 +197,7 @@ func createGiteaUser(pool *dockertest.Pool, gitea *dockertest.Resource) *urlpkg. stdErrBuf := bytes.NewBuffer(nil) exec, err := pool.Client.CreateExec(docker.CreateExecOptions{ - Container: gitea.Container.ID, + Container: giteaRsc.Container.ID, User: "git", Cmd: []string{ "gitea", @@ -259,7 +266,7 @@ func runWoodpecker( } repo, tag := getWoodpeckerRepoTag() - woodpecker, err := pool.RunWithOptions(&dockertest.RunOptions{ + woodpeckerRsc, err := pool.RunWithOptions(&dockertest.RunOptions{ Repository: repo, Tag: tag, Networks: []*dockertest.Network{network}, @@ -295,7 +302,7 @@ func runWoodpecker( log.Fatalf("couldn't run woodpecker: %s", err) } - if err = woodpecker.Expire(woodpeckerContainerExpInSec); err != nil { + if err = woodpeckerRsc.Expire(woodpeckerContainerExpInSec); err != nil { log.Fatal(err) } @@ -328,7 +335,7 @@ func runWoodpecker( } return woodpeckerResource{ - docker: woodpecker, + docker: woodpeckerRsc, httpURL: httpURL, token: newWoodpeckerTokenProvider(oauthApp, giteaUser, giteaPublicURL, httpURL).token(), } @@ -340,7 +347,8 @@ func (r woodpeckerResource) Close() error { const defaultWoodpeckerImage = "woodpeckerci/woodpecker-server:v1.0.2" -func getWoodpeckerRepoTag() (string, string) { +//nolint:nonamedreturns +func getWoodpeckerRepoTag() (repo string, tag string) { val := os.Getenv("WOODPECKER_IMAGE") if val == "" { val = defaultWoodpeckerImage @@ -453,7 +461,12 @@ func (p woodpeckerTokenProvider) get(ctx context.Context, url string) *http.Resp return p.do(p.newRequestWithContext(ctx, http.MethodGet, url, nil)) } -func (p woodpeckerTokenProvider) newRequestWithContext(ctx context.Context, method string, url string, body io.Reader) *http.Request { +func (p woodpeckerTokenProvider) newRequestWithContext( + ctx context.Context, + method string, + url string, + body io.Reader, +) *http.Request { req, err := http.NewRequestWithContext(ctx, method, url, body) if err != nil { log.Fatalf("couldn't construct request for url %s: %s", url, err) diff --git a/internal/models.go b/internal/models.go index c459882..41d5f45 100644 --- a/internal/models.go +++ b/internal/models.go @@ -268,7 +268,9 @@ func (m *repositoryRegistryResourceModel) setValues(_ context.Context, registry return nil } -func (m *repositoryRegistryResourceModel) toWoodpeckerModel(_ context.Context) (*woodpecker.Registry, diag.Diagnostics) { +func (m *repositoryRegistryResourceModel) toWoodpeckerModel( + _ context.Context, +) (*woodpecker.Registry, diag.Diagnostics) { return &woodpecker.Registry{ ID: m.ID.ValueInt64(), Address: m.Address.ValueString(), @@ -286,7 +288,10 @@ type repositoryRegistryDataSourceModel struct { Email types.String `tfsdk:"email"` } -func (m *repositoryRegistryDataSourceModel) setValues(_ context.Context, registry *woodpecker.Registry) diag.Diagnostics { +func (m *repositoryRegistryDataSourceModel) setValues( + _ context.Context, + registry *woodpecker.Registry, +) diag.Diagnostics { m.ID = types.Int64Value(registry.ID) m.Address = types.StringValue(registry.Address) m.Username = types.StringValue(registry.Username) diff --git a/internal/provider.go b/internal/provider.go index 43844d1..528e541 100644 --- a/internal/provider.go +++ b/internal/provider.go @@ -36,7 +36,8 @@ func (p *woodpeckerProvider) Metadata(_ context.Context, _ provider.MetadataRequ func (p *woodpeckerProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) { resp.Schema = schema.Schema{ - MarkdownDescription: "A Terraform provider used to interact with [Woodpecker CI](https://woodpecker-ci.org/) resources.", + MarkdownDescription: "A Terraform provider used to interact with" + + " [Woodpecker CI](https://woodpecker-ci.org/) resources.", Attributes: map[string]schema.Attribute{ "server": schema.StringAttribute{ Optional: true, @@ -76,7 +77,11 @@ func (p *woodpeckerProvider) Resources(_ context.Context) []func() resource.Reso } } -func (p *woodpeckerProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { +func (p *woodpeckerProvider) Configure( + ctx context.Context, + req provider.ConfigureRequest, + resp *provider.ConfigureResponse, +) { cfg := newProviderConfig(ctx, req, resp) if resp.Diagnostics.HasError() { return diff --git a/internal/resource_repository.go b/internal/resource_repository.go index f3f511f..dadcf4e 100644 --- a/internal/resource_repository.go +++ b/internal/resource_repository.go @@ -31,7 +31,11 @@ func newRepositoryResource() resource.Resource { return &repositoryResource{} } -func (r *repositoryResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *repositoryResource) Metadata( + _ context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_repository" } @@ -157,9 +161,10 @@ func (r *repositoryResource) Schema(_ context.Context, _ resource.SchemaRequest, }, }, "allow_pull_requests": schema.BoolAttribute{ - Optional: true, - Computed: true, - Description: "Enables handling webhook's pull request event. If disabled, then pipeline won't run for pull requests.", + Optional: true, + Computed: true, + Description: "Enables handling webhook's pull request event." + + " If disabled, then pipeline won't run for pull requests.", PlanModifiers: []planmodifier.Bool{ boolplanmodifier.UseStateForUnknown(), }, @@ -190,8 +195,10 @@ func (r *repositoryResource) Schema(_ context.Context, _ resource.SchemaRequest, "netrc_only_trusted": schema.BoolAttribute{ Optional: true, Computed: true, - MarkdownDescription: "whether netrc credentials should be only injected into trusted containers, " + - "see [the docs](https://woodpecker-ci.org/docs/usage/project-settings#only-inject-netrc-credentials-into-trusted-containers) for more info", + MarkdownDescription: "whether netrc credentials should be only injected into trusted containers, see" + + //nolint:lll + " [the docs](https://woodpecker-ci.org/docs/usage/project-settings#only-inject-netrc-credentials-into-trusted-containers)" + + " for more info", PlanModifiers: []planmodifier.Bool{ boolplanmodifier.UseStateForUnknown(), }, @@ -200,7 +207,11 @@ func (r *repositoryResource) Schema(_ context.Context, _ resource.SchemaRequest, } } -func (r *repositoryResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *repositoryResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { // Prevent panic if the provider has not been configured. if req.ProviderData == nil { return @@ -210,7 +221,10 @@ func (r *repositoryResource) Configure(_ context.Context, req resource.Configure if !ok { resp.Diagnostics.AddError( "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + fmt.Sprintf( + "Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), ) return } @@ -342,6 +356,10 @@ func (r *repositoryResource) Delete(ctx context.Context, req resource.DeleteRequ // from provider logic. } -func (r *repositoryResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *repositoryResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("full_name"), req.ID)...) } diff --git a/internal/resource_repository_cron.go b/internal/resource_repository_cron.go index 8979daf..cb8a677 100644 --- a/internal/resource_repository_cron.go +++ b/internal/resource_repository_cron.go @@ -27,7 +27,11 @@ func newRepositoryCronResource() resource.Resource { return &repositoryCronResource{} } -func (r *repositoryCronResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *repositoryCronResource) Metadata( + _ context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_repository_cron" } @@ -86,7 +90,11 @@ func (r *repositoryCronResource) Schema(_ context.Context, _ resource.SchemaRequ } } -func (r *repositoryCronResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *repositoryCronResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { // Prevent panic if the provider has not been configured. if req.ProviderData == nil { return @@ -96,7 +104,10 @@ func (r *repositoryCronResource) Configure(_ context.Context, req resource.Confi if !ok { resp.Diagnostics.AddError( "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + fmt.Sprintf( + "Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), ) return } @@ -104,7 +115,11 @@ func (r *repositoryCronResource) Configure(_ context.Context, req resource.Confi r.client = client } -func (r *repositoryCronResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *repositoryCronResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { var data repositoryCronModel resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -153,7 +168,11 @@ func (r *repositoryCronResource) Read(ctx context.Context, req resource.ReadRequ resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } -func (r *repositoryCronResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *repositoryCronResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { var data repositoryCronModel resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -181,7 +200,11 @@ func (r *repositoryCronResource) Update(ctx context.Context, req resource.Update resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } -func (r *repositoryCronResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *repositoryCronResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { var data repositoryCronModel resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -197,7 +220,11 @@ func (r *repositoryCronResource) Delete(ctx context.Context, req resource.Delete resp.State.RemoveResource(ctx) } -func (r *repositoryCronResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *repositoryCronResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { idParts := strings.Split(req.ID, importStateIDSeparator) if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { diff --git a/internal/resource_repository_cron_test.go b/internal/resource_repository_cron_test.go index b5b217c..74d94b3 100644 --- a/internal/resource_repository_cron_test.go +++ b/internal/resource_repository_cron_test.go @@ -42,7 +42,11 @@ resource "woodpecker_repository_cron" "test_cron" { `, repo.ID, name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_cron.test_cron", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "repository_id", strconv.FormatInt(repo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_cron.test_cron", + "repository_id", + strconv.FormatInt(repo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "name", name), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@daily"), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", ""), @@ -61,7 +65,11 @@ resource "woodpecker_repository_cron" "test_cron" { `, repo.ID, name, branch.Name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_cron.test_cron", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "repository_id", strconv.FormatInt(repo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_cron.test_cron", + "repository_id", + strconv.FormatInt(repo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "name", name), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@every 5m"), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", branch.Name), @@ -79,7 +87,11 @@ resource "woodpecker_repository_cron" "test_cron" { //`, repo.ID, name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_cron.test_cron", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "repository_id", strconv.FormatInt(repo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_cron.test_cron", + "repository_id", + strconv.FormatInt(repo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "name", name), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@daily"), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", branch.Name), @@ -108,7 +120,11 @@ resource "woodpecker_repository_cron" "test_cron" { }, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_cron.test_cron", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "repository_id", strconv.FormatInt(newRepo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_cron.test_cron", + "repository_id", + strconv.FormatInt(newRepo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "name", name), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@daily"), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", ""), diff --git a/internal/resource_repository_registry.go b/internal/resource_repository_registry.go index 5f03204..2df5185 100644 --- a/internal/resource_repository_registry.go +++ b/internal/resource_repository_registry.go @@ -27,11 +27,19 @@ func newRepositoryRegistryResource() resource.Resource { return &repositoryRegistryResource{} } -func (r *repositoryRegistryResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *repositoryRegistryResource) Metadata( + _ context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_repository_registry" } -func (r *repositoryRegistryResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { +func (r *repositoryRegistryResource) Schema( + _ context.Context, + _ resource.SchemaRequest, + resp *resource.SchemaResponse, +) { resp.Schema = schema.Schema{ MarkdownDescription: "This resource allows you to add/remove container registries for specific repositories." + " When applied, a new registry will be created." + @@ -80,7 +88,11 @@ func (r *repositoryRegistryResource) Schema(_ context.Context, _ resource.Schema } } -func (r *repositoryRegistryResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *repositoryRegistryResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { // Prevent panic if the provider has not been configured. if req.ProviderData == nil { return @@ -90,7 +102,10 @@ func (r *repositoryRegistryResource) Configure(_ context.Context, req resource.C if !ok { resp.Diagnostics.AddError( "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + fmt.Sprintf( + "Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), ) return } @@ -98,7 +113,11 @@ func (r *repositoryRegistryResource) Configure(_ context.Context, req resource.C r.client = client } -func (r *repositoryRegistryResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *repositoryRegistryResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { var data repositoryRegistryResourceModel resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -154,7 +173,11 @@ func (r *repositoryRegistryResource) Read(ctx context.Context, req resource.Read resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } -func (r *repositoryRegistryResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *repositoryRegistryResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { var data repositoryRegistryResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -182,7 +205,11 @@ func (r *repositoryRegistryResource) Update(ctx context.Context, req resource.Up resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } -func (r *repositoryRegistryResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *repositoryRegistryResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { var data repositoryRegistryResourceModel resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -198,7 +225,11 @@ func (r *repositoryRegistryResource) Delete(ctx context.Context, req resource.De resp.State.RemoveResource(ctx) } -func (r *repositoryRegistryResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *repositoryRegistryResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { idParts := strings.Split(req.ID, importStateIDSeparator) if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { diff --git a/internal/resource_repository_registry_test.go b/internal/resource_repository_registry_test.go index 4e0ac16..194d61b 100644 --- a/internal/resource_repository_registry_test.go +++ b/internal/resource_repository_registry_test.go @@ -43,7 +43,11 @@ resource "woodpecker_repository_registry" "test_registry" { `, repo.ID, address), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "repository_id", strconv.FormatInt(repo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_registry.test_registry", + "repository_id", + strconv.FormatInt(repo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "address", address), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"), @@ -61,7 +65,11 @@ resource "woodpecker_repository_registry" "test_registry" { `, repo.ID, address), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "repository_id", strconv.FormatInt(repo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_registry.test_registry", + "repository_id", + strconv.FormatInt(repo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "address", address), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test2"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test2"), @@ -79,7 +87,11 @@ resource "woodpecker_repository_registry" "test_registry" { //`, repo.ID, address), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "repository_id", strconv.FormatInt(repo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_registry.test_registry", + "repository_id", + strconv.FormatInt(repo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "address", address), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"), @@ -104,12 +116,19 @@ resource "woodpecker_repository_registry" "test_registry" { `, repo.ID, newAddress), ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ - plancheck.ExpectResourceAction("woodpecker_repository_registry.test_registry", plancheck.ResourceActionReplace), + plancheck.ExpectResourceAction( + "woodpecker_repository_registry.test_registry", + plancheck.ResourceActionReplace, + ), }, }, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "repository_id", strconv.FormatInt(repo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_registry.test_registry", + "repository_id", + strconv.FormatInt(repo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "address", newAddress), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"), @@ -131,7 +150,11 @@ resource "woodpecker_repository_registry" "test_registry" { }, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "repository_id", strconv.FormatInt(newRepo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_registry.test_registry", + "repository_id", + strconv.FormatInt(newRepo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "address", newAddress), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"), diff --git a/internal/resource_repository_secret.go b/internal/resource_repository_secret.go index 628e402..7278666 100644 --- a/internal/resource_repository_secret.go +++ b/internal/resource_repository_secret.go @@ -33,13 +33,18 @@ func newRepositorySecretResource() resource.Resource { return &repositorySecretResource{} } -func (r *repositorySecretResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { +func (r *repositorySecretResource) Metadata( + _ context.Context, + req resource.MetadataRequest, + resp *resource.MetadataResponse, +) { resp.TypeName = req.ProviderTypeName + "_repository_secret" } func (r *repositorySecretResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ - MarkdownDescription: "This resource allows you to add/remove secrets that are only available to specific repositories." + + MarkdownDescription: "This resource allows you to add/remove secrets that" + + " are only available to specific repositories." + " When applied, a new secret will be created." + " When destroyed, that secret will be removed." + " For more information see [the Woodpecker docs](https://woodpecker-ci.org/docs/usage/secrets).", @@ -87,9 +92,10 @@ func (r *repositorySecretResource) Schema(_ context.Context, _ resource.SchemaRe }, }, "plugins_only": schema.BoolAttribute{ - Optional: true, - Computed: true, - MarkdownDescription: "whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)", + Optional: true, + Computed: true, + MarkdownDescription: "whether secret is only available for" + + " [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)", PlanModifiers: []planmodifier.Bool{ boolplanmodifier.UseStateForUnknown(), }, @@ -107,7 +113,11 @@ func (r *repositorySecretResource) Schema(_ context.Context, _ resource.SchemaRe } } -func (r *repositorySecretResource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { +func (r *repositorySecretResource) Configure( + _ context.Context, + req resource.ConfigureRequest, + resp *resource.ConfigureResponse, +) { // Prevent panic if the provider has not been configured. if req.ProviderData == nil { return @@ -117,7 +127,10 @@ func (r *repositorySecretResource) Configure(_ context.Context, req resource.Con if !ok { resp.Diagnostics.AddError( "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + fmt.Sprintf( + "Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), ) return } @@ -125,7 +138,11 @@ func (r *repositorySecretResource) Configure(_ context.Context, req resource.Con r.client = client } -func (r *repositorySecretResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { +func (r *repositorySecretResource) Create( + ctx context.Context, + req resource.CreateRequest, + resp *resource.CreateResponse, +) { var data repositorySecretResourceModel resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) @@ -174,7 +191,11 @@ func (r *repositorySecretResource) Read(ctx context.Context, req resource.ReadRe resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } -func (r *repositorySecretResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { +func (r *repositorySecretResource) Update( + ctx context.Context, + req resource.UpdateRequest, + resp *resource.UpdateResponse, +) { var data repositorySecretResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) @@ -202,7 +223,11 @@ func (r *repositorySecretResource) Update(ctx context.Context, req resource.Upda resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } -func (r *repositorySecretResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { +func (r *repositorySecretResource) Delete( + ctx context.Context, + req resource.DeleteRequest, + resp *resource.DeleteResponse, +) { var data repositorySecretResourceModel resp.Diagnostics.Append(req.State.Get(ctx, &data)...) @@ -218,7 +243,11 @@ func (r *repositorySecretResource) Delete(ctx context.Context, req resource.Dele resp.State.RemoveResource(ctx) } -func (r *repositorySecretResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *repositorySecretResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { idParts := strings.Split(req.ID, importStateIDSeparator) if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { diff --git a/internal/resource_repository_secret_test.go b/internal/resource_repository_secret_test.go index 15b2494..49d7c48 100644 --- a/internal/resource_repository_secret_test.go +++ b/internal/resource_repository_secret_test.go @@ -46,7 +46,11 @@ resource "woodpecker_repository_secret" "test_secret" { `, repo.ID, name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "repository_id", strconv.FormatInt(repo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_secret.test_secret", + "repository_id", + strconv.FormatInt(repo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "name", name), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"), @@ -66,7 +70,11 @@ resource "woodpecker_repository_secret" "test_secret" { `, repo.ID, name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "repository_id", strconv.FormatInt(repo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_secret.test_secret", + "repository_id", + strconv.FormatInt(repo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "name", name), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123123"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"), @@ -86,7 +94,11 @@ resource "woodpecker_repository_secret" "test_secret" { //`, repo.ID, name), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "repository_id", strconv.FormatInt(repo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_secret.test_secret", + "repository_id", + strconv.FormatInt(repo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "name", name), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123123"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"), @@ -119,7 +131,11 @@ resource "woodpecker_repository_secret" "test_secret" { }, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "repository_id", strconv.FormatInt(repo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_secret.test_secret", + "repository_id", + strconv.FormatInt(repo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "name", newName), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123New"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"), @@ -142,7 +158,11 @@ resource "woodpecker_repository_secret" "test_secret" { }, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"), - resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "repository_id", strconv.FormatInt(newRepo.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository_secret.test_secret", + "repository_id", + strconv.FormatInt(newRepo.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "name", newName), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123New"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"), diff --git a/internal/resource_repository_test.go b/internal/resource_repository_test.go index 4e4d2c8..4f61933 100644 --- a/internal/resource_repository_test.go +++ b/internal/resource_repository_test.go @@ -38,7 +38,11 @@ resource "woodpecker_repository" "test_repo" { `, repo1.FullName), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "id"), - resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "forge_remote_id", strconv.FormatInt(repo1.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository.test_repo", + "forge_remote_id", + strconv.FormatInt(repo1.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "name", repo1.Name), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo1.Owner.UserName), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "full_name", repo1.FullName), @@ -48,7 +52,11 @@ resource "woodpecker_repository" "test_repo" { resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "scm", "git"), resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "timeout"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "visibility", "public"), - resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_private", strconv.FormatBool(repo1.Private)), + resource.TestCheckResourceAttr( + "woodpecker_repository.test_repo", + "is_private", + strconv.FormatBool(repo1.Private), + ), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_trusted", "true"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "false"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"), @@ -69,7 +77,11 @@ resource "woodpecker_repository" "test_repo" { `, repo1.FullName), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "id"), - resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "forge_remote_id", strconv.FormatInt(repo1.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository.test_repo", + "forge_remote_id", + strconv.FormatInt(repo1.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "name", repo1.Name), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo1.Owner.UserName), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "full_name", repo1.FullName), @@ -79,7 +91,11 @@ resource "woodpecker_repository" "test_repo" { resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "scm", "git"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "timeout", "30"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "visibility", "private"), - resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_private", strconv.FormatBool(repo1.Private)), + resource.TestCheckResourceAttr( + "woodpecker_repository.test_repo", + "is_private", + strconv.FormatBool(repo1.Private), + ), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_trusted", "false"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "true"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"), @@ -96,7 +112,11 @@ resource "woodpecker_repository" "test_repo" { //`, repo1.FullName), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "id"), - resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "forge_remote_id", strconv.FormatInt(repo1.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository.test_repo", + "forge_remote_id", + strconv.FormatInt(repo1.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "name", repo1.Name), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo1.Owner.UserName), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "full_name", repo1.FullName), @@ -106,7 +126,11 @@ resource "woodpecker_repository" "test_repo" { resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "scm", "git"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "timeout", "15"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "visibility", "private"), - resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_private", strconv.FormatBool(repo1.Private)), + resource.TestCheckResourceAttr( + "woodpecker_repository.test_repo", + "is_private", + strconv.FormatBool(repo1.Private), + ), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_trusted", "false"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "true"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"), @@ -133,7 +157,11 @@ resource "woodpecker_repository" "test_repo" { }, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "id"), - resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "forge_remote_id", strconv.FormatInt(repo2.ID, 10)), + resource.TestCheckResourceAttr( + "woodpecker_repository.test_repo", + "forge_remote_id", + strconv.FormatInt(repo2.ID, 10), + ), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "name", repo2.Name), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo2.Owner.UserName), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "full_name", repo2.FullName), @@ -143,7 +171,11 @@ resource "woodpecker_repository" "test_repo" { resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "scm", "git"), resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "timeout"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "visibility", "public"), - resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_private", strconv.FormatBool(repo2.Private)), + resource.TestCheckResourceAttr( + "woodpecker_repository.test_repo", + "is_private", + strconv.FormatBool(repo2.Private), + ), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_trusted", "false"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "false"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"), diff --git a/internal/resource_secret.go b/internal/resource_secret.go index f60af52..64067d4 100644 --- a/internal/resource_secret.go +++ b/internal/resource_secret.go @@ -37,7 +37,8 @@ func (r *secretResource) Metadata(_ context.Context, req resource.MetadataReques func (r *secretResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ - MarkdownDescription: "This resource allows you to add/remove global secrets. When applied, a new secret will be created." + + MarkdownDescription: "This resource allows you to add/remove global secrets." + + " When applied, a new secret will be created." + " When destroyed, that secret will be removed." + " For more information see [the Woodpecker docs](https://woodpecker-ci.org/docs/usage/secrets).", Attributes: map[string]schema.Attribute{ @@ -77,9 +78,10 @@ func (r *secretResource) Schema(_ context.Context, _ resource.SchemaRequest, res }, }, "plugins_only": schema.BoolAttribute{ - Optional: true, - Computed: true, - MarkdownDescription: "whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)", + Optional: true, + Computed: true, + MarkdownDescription: "whether secret is only available for" + + " [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)", PlanModifiers: []planmodifier.Bool{ boolplanmodifier.UseStateForUnknown(), }, @@ -107,7 +109,10 @@ func (r *secretResource) Configure(_ context.Context, req resource.ConfigureRequ if !ok { resp.Diagnostics.AddError( "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + fmt.Sprintf( + "Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), ) return } @@ -208,6 +213,10 @@ func (r *secretResource) Delete(ctx context.Context, req resource.DeleteRequest, resp.State.RemoveResource(ctx) } -func (r *secretResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *secretResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), req.ID)...) } diff --git a/internal/resource_user.go b/internal/resource_user.go index 535c3b3..7cfc7e8 100644 --- a/internal/resource_user.go +++ b/internal/resource_user.go @@ -32,10 +32,10 @@ func (r *userResource) Metadata(_ context.Context, req resource.MetadataRequest, func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ - MarkdownDescription: `Provides a user resource. - - -This resource allows you to add/remove users. When applied, a new user will be created. When destroyed, that user will be removed.`, + MarkdownDescription: "Provides a user resource." + + "\n\n\nThis resource allows you to add/remove users." + + " When applied, a new user will be created." + + " When destroyed, that user will be removed.", Attributes: map[string]schema.Attribute{ "id": schema.Int64Attribute{ Computed: true, @@ -96,7 +96,10 @@ func (r *userResource) Configure(_ context.Context, req resource.ConfigureReques if !ok { resp.Diagnostics.AddError( "Unexpected Data Source Configure Type", - fmt.Sprintf("Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + fmt.Sprintf( + "Expected woodpecker.Client, got: %T. Please report this issue to the provider developers.", + req.ProviderData, + ), ) return } @@ -199,6 +202,10 @@ func (r *userResource) Delete(ctx context.Context, req resource.DeleteRequest, r // from provider logic. } -func (r *userResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { +func (r *userResource) ImportState( + ctx context.Context, + req resource.ImportStateRequest, + resp *resource.ImportStateResponse, +) { resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("login"), req.ID)...) }