chore: update golangci-lint and its config (#17)

This commit is contained in:
Dawid Wysokiński 2023-11-26 14:16:32 +01:00 committed by GitHub
parent d3ac9bd8ff
commit 67956ca230
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 841 additions and 152 deletions

View File

@ -30,7 +30,7 @@ jobs:
- run: make generate && go mod tidy && git diff --exit-code go.mod docs/ examples/ - run: make generate && go mod tidy && git diff --exit-code go.mod docs/ examples/
- uses: golangci/golangci-lint-action@v3 - uses: golangci/golangci-lint-action@v3
with: with:
version: v1.54 version: v1.55
- name: Gitea 1.20 & Woodpecker 1.0 - name: Gitea 1.20 & Woodpecker 1.0
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
env: env:

View File

@ -10,7 +10,6 @@ linters:
- bodyclose - bodyclose
- bidichk - bidichk
- exportloopref - exportloopref
- depguard
- errcheck - errcheck
- gocritic - gocritic
- gosec - gosec
@ -30,8 +29,6 @@ linters:
- nestif - nestif
- thelper - thelper
- nonamedreturns - nonamedreturns
- gocyclo
- gomnd
- tenv - tenv
- testpackage - testpackage
- noctx - noctx
@ -51,27 +48,19 @@ linters:
- predeclared - predeclared
- promlinter - promlinter
- wastedassign - wastedassign
- testifylint
- inamedparam
- sloglint
- revive
linters-settings: linters-settings:
tagliatelle: tagliatelle:
case: case:
rules: rules:
json: camel json: camel
tfsdk: snake bun: snake
lll: lll:
line-length: 150 line-length: 120
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
govet: govet:
enable: enable:
- asmdecl - asmdecl
@ -109,18 +98,375 @@ linters-settings:
- unsafeptr - unsafeptr
- unusedresult - unusedresult
- unusedwrite - unusedwrite
gomnd: testifylint:
ignored-functions: enable-all: true
- strconv.FormatInt sloglint:
- strconv.ParseInt 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: issues:
exclude-rules: exclude-rules:
# Exclude some linters from running on tests files. # Exclude some linters from running on tests files.
- path: _test\.go - path: _test\.go
linters: linters:
- dupl - gosec
- gocyclo - path: _test\.go
text: deep-exit
- linters: - linters:
- lll - lll
source: "^//go:generate " source: "^//go:generate "

View File

@ -6,6 +6,6 @@ repos:
stages: [commit-msg] stages: [commit-msg]
additional_dependencies: ['@commitlint/config-conventional'] additional_dependencies: ['@commitlint/config-conventional']
- repo: https://github.com/golangci/golangci-lint - repo: https://github.com/golangci/golangci-lint
rev: v1.54.2 rev: v1.55.2
hooks: hooks:
- id: golangci-lint - id: golangci-lint

View File

@ -22,7 +22,7 @@ install-tfplugindocs:
.PHONY: install-golangci-lint .PHONY: install-golangci-lint
install-golangci-lint: install-golangci-lint:
@echo "Installing github.com/golangci/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 .PHONY: install-tools
install-tools: install-golangci-lint install-tfplugindocs install-tools: install-golangci-lint install-tfplugindocs

View File

@ -20,11 +20,19 @@ func newRepositoryDataSource() datasource.DataSource {
return &repositoryDataSource{} 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" 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{ resp.Schema = schema.Schema{
MarkdownDescription: "Use this data source to retrieve information about a repository.", MarkdownDescription: "Use this data source to retrieve information about a repository.",
Attributes: map[string]schema.Attribute{ Attributes: map[string]schema.Attribute{
@ -92,7 +100,8 @@ func (d *repositoryDataSource) Schema(_ context.Context, _ datasource.SchemaRequ
}, },
"allow_pull_requests": schema.BoolAttribute{ "allow_pull_requests": schema.BoolAttribute{
Computed: true, Computed: true,
Description: "Enables handling webhook's pull request event. If disabled, then pipeline won't run for pull requests.", Description: "Enables handling webhook's pull request event." +
" If disabled, then pipeline won't run for pull requests.",
}, },
"config_file": schema.StringAttribute{ "config_file": schema.StringAttribute{
Computed: true, Computed: true,
@ -103,13 +112,18 @@ func (d *repositoryDataSource) Schema(_ context.Context, _ datasource.SchemaRequ
"netrc_only_trusted": schema.BoolAttribute{ "netrc_only_trusted": schema.BoolAttribute{
Computed: true, Computed: true,
MarkdownDescription: "whether netrc credentials should be only injected into trusted containers, " + 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", "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. // Prevent panic if the provider has not been configured.
if req.ProviderData == nil { if req.ProviderData == nil {
return return
@ -119,7 +133,10 @@ func (d *repositoryDataSource) Configure(_ context.Context, req datasource.Confi
if !ok { if !ok {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type", "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 return
} }

View File

@ -20,11 +20,19 @@ func newRepositoryCronDataSource() datasource.DataSource {
return &repositoryCronDataSource{} 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" 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{ resp.Schema = schema.Schema{
MarkdownDescription: "Use this data source to retrieve information about a cron job in a specific repository.", MarkdownDescription: "Use this data source to retrieve information about a cron job in a specific repository.",
Attributes: map[string]schema.Attribute{ 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. // Prevent panic if the provider has not been configured.
if req.ProviderData == nil { if req.ProviderData == nil {
return return
@ -70,7 +82,10 @@ func (d *repositoryCronDataSource) Configure(_ context.Context, req datasource.C
if !ok { if !ok {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type", "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 return
} }
@ -78,7 +93,11 @@ func (d *repositoryCronDataSource) Configure(_ context.Context, req datasource.C
d.client = client 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 var data repositoryCronModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

View File

@ -20,13 +20,22 @@ func newRepositoryRegistryDataSource() datasource.DataSource {
return &repositoryRegistryDataSource{} 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" 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{ 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{ Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{ "id": schema.Int64Attribute{
Computed: true, 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. // Prevent panic if the provider has not been configured.
if req.ProviderData == nil { if req.ProviderData == nil {
return return
@ -62,7 +75,10 @@ func (d *repositoryRegistryDataSource) Configure(_ context.Context, req datasour
if !ok { if !ok {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type", "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 return
} }
@ -70,7 +86,11 @@ func (d *repositoryRegistryDataSource) Configure(_ context.Context, req datasour
d.client = client 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 var data repositoryRegistryDataSourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

View File

@ -21,11 +21,19 @@ func newRepositorySecretDataSource() datasource.DataSource {
return &repositorySecretDataSource{} 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" 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{ resp.Schema = schema.Schema{
MarkdownDescription: "Use this data source to retrieve information about a secret in a specific repository.", MarkdownDescription: "Use this data source to retrieve information about a secret in a specific repository.",
Attributes: map[string]schema.Attribute{ Attributes: map[string]schema.Attribute{
@ -48,7 +56,8 @@ func (d *repositorySecretDataSource) Schema(_ context.Context, _ datasource.Sche
}, },
"plugins_only": schema.BoolAttribute{ "plugins_only": schema.BoolAttribute{
Computed: true, Computed: true,
MarkdownDescription: "whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)", MarkdownDescription: "whether secret is only available for " +
"[plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)",
}, },
"images": schema.SetAttribute{ "images": schema.SetAttribute{
ElementType: types.StringType, 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. // Prevent panic if the provider has not been configured.
if req.ProviderData == nil { if req.ProviderData == nil {
return return
@ -69,7 +82,10 @@ func (d *repositorySecretDataSource) Configure(_ context.Context, req datasource
if !ok { if !ok {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type", "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 return
} }
@ -77,7 +93,11 @@ func (d *repositorySecretDataSource) Configure(_ context.Context, req datasource
d.client = client 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 var data repositorySecretDataSourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)

View File

@ -29,7 +29,11 @@ data "woodpecker_repository" "test_repo" {
`, repo.FullName), `, repo.FullName),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.woodpecker_repository.test_repo", "id"), 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", "name", repo.Name),
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "owner", repo.Owner.UserName), resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "owner", repo.Owner.UserName),
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "full_name", repo.FullName), 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.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "scm", "git"),
resource.TestCheckResourceAttrSet("data.woodpecker_repository.test_repo", "timeout"), resource.TestCheckResourceAttrSet("data.woodpecker_repository.test_repo", "timeout"),
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "visibility", "public"), 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_trusted", "false"),
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "is_gated", "false"), resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "is_gated", "false"),
resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "allow_pull_requests", "true"), resource.TestCheckResourceAttr("data.woodpecker_repository.test_repo", "allow_pull_requests", "true"),

View File

@ -21,7 +21,11 @@ func newSecretDataSource() datasource.DataSource {
return &secretDataSource{} 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" resp.TypeName = req.ProviderTypeName + "_secret"
} }
@ -44,7 +48,8 @@ func (d *secretDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
}, },
"plugins_only": schema.BoolAttribute{ "plugins_only": schema.BoolAttribute{
Computed: true, Computed: true,
MarkdownDescription: "whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)", MarkdownDescription: "whether secret is only available for " +
"[plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)",
}, },
"images": schema.SetAttribute{ "images": schema.SetAttribute{
ElementType: types.StringType, 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. // Prevent panic if the provider has not been configured.
if req.ProviderData == nil { if req.ProviderData == nil {
return return
@ -65,7 +74,10 @@ func (d *secretDataSource) Configure(_ context.Context, req datasource.Configure
if !ok { if !ok {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type", "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 return
} }

View File

@ -20,7 +20,11 @@ func newUserDataSource() datasource.DataSource {
return &userDataSource{} 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" resp.TypeName = req.ProviderTypeName + "_user"
} }
@ -34,7 +38,8 @@ func (d *userDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, r
}, },
"login": schema.StringAttribute{ "login": schema.StringAttribute{
Required: true, Required: true,
Description: "The user's login. Use an empty string \"\" to retrieve information about the currently authenticated user.", Description: "The user's login. " +
"Use an empty string \"\" to retrieve information about the currently authenticated user.",
}, },
"email": schema.StringAttribute{ "email": schema.StringAttribute{
Computed: true, 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. // Prevent panic if the provider has not been configured.
if req.ProviderData == nil { if req.ProviderData == nil {
return return
@ -66,7 +75,10 @@ func (d *userDataSource) Configure(_ context.Context, req datasource.ConfigureRe
if !ok { if !ok {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type", "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 return
} }

View File

@ -48,7 +48,13 @@ func TestMain(m *testing.M) {
giteaClient = newGiteaClient(resourceGitea.httpURL, resourceGitea.user) 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() { deferFuncs = append(deferFuncs, func() {
_ = resourceWoodpecker.Close() _ = resourceWoodpecker.Close()
}) })
@ -68,7 +74,6 @@ func TestMain(m *testing.M) {
} }
os.Exit(code) os.Exit(code)
} }
func newDockertestPool() *dockertest.Pool { func newDockertestPool() *dockertest.Pool {
@ -103,7 +108,8 @@ type giteaResource struct {
func runGitea(pool *dockertest.Pool, network *dockertest.Network) giteaResource { func runGitea(pool *dockertest.Pool, network *dockertest.Network) giteaResource {
repo, tag := getGiteaRepoTag() repo, tag := getGiteaRepoTag()
gitea, err := pool.RunWithOptions(&dockertest.RunOptions{
giteaRsc, err := pool.RunWithOptions(&dockertest.RunOptions{
Repository: repo, Repository: repo,
Tag: tag, Tag: tag,
Networks: []*dockertest.Network{network}, 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) 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) log.Fatal(err)
} }
httpURL := &urlpkg.URL{ httpURL := &urlpkg.URL{
Scheme: "http", Scheme: "http",
Host: getHostPort(gitea, "3000/tcp"), Host: getHostPort(giteaRsc, "3000/tcp"),
} }
if err = pool.Retry(func() error { if err = pool.Retry(func() error {
@ -158,13 +164,13 @@ func runGitea(pool *dockertest.Pool, network *dockertest.Network) giteaResource
} }
return giteaResource{ return giteaResource{
docker: gitea, docker: giteaRsc,
httpURL: httpURL, httpURL: httpURL,
privateHTTPURL: &urlpkg.URL{ privateHTTPURL: &urlpkg.URL{
Scheme: httpURL.Scheme, 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" const defaultGiteaImage = "gitea/gitea:1.20"
func getGiteaRepoTag() (string, string) { //nolint:nonamedreturns
func getGiteaRepoTag() (repository string, tag string) {
val := os.Getenv("GITEA_IMAGE") val := os.Getenv("GITEA_IMAGE")
if val == "" { if val == "" {
val = defaultGiteaImage val = defaultGiteaImage
@ -182,7 +189,7 @@ func getGiteaRepoTag() (string, string) {
return docker.ParseRepositoryTag(val) 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(), "-", "") username := strings.ReplaceAll(uuid.NewString(), "-", "")
password := uuid.NewString() password := uuid.NewString()
@ -190,7 +197,7 @@ func createGiteaUser(pool *dockertest.Pool, gitea *dockertest.Resource) *urlpkg.
stdErrBuf := bytes.NewBuffer(nil) stdErrBuf := bytes.NewBuffer(nil)
exec, err := pool.Client.CreateExec(docker.CreateExecOptions{ exec, err := pool.Client.CreateExec(docker.CreateExecOptions{
Container: gitea.Container.ID, Container: giteaRsc.Container.ID,
User: "git", User: "git",
Cmd: []string{ Cmd: []string{
"gitea", "gitea",
@ -259,7 +266,7 @@ func runWoodpecker(
} }
repo, tag := getWoodpeckerRepoTag() repo, tag := getWoodpeckerRepoTag()
woodpecker, err := pool.RunWithOptions(&dockertest.RunOptions{ woodpeckerRsc, err := pool.RunWithOptions(&dockertest.RunOptions{
Repository: repo, Repository: repo,
Tag: tag, Tag: tag,
Networks: []*dockertest.Network{network}, Networks: []*dockertest.Network{network},
@ -295,7 +302,7 @@ func runWoodpecker(
log.Fatalf("couldn't run woodpecker: %s", err) 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) log.Fatal(err)
} }
@ -328,7 +335,7 @@ func runWoodpecker(
} }
return woodpeckerResource{ return woodpeckerResource{
docker: woodpecker, docker: woodpeckerRsc,
httpURL: httpURL, httpURL: httpURL,
token: newWoodpeckerTokenProvider(oauthApp, giteaUser, giteaPublicURL, httpURL).token(), token: newWoodpeckerTokenProvider(oauthApp, giteaUser, giteaPublicURL, httpURL).token(),
} }
@ -340,7 +347,8 @@ func (r woodpeckerResource) Close() error {
const defaultWoodpeckerImage = "woodpeckerci/woodpecker-server:v1.0.2" 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") val := os.Getenv("WOODPECKER_IMAGE")
if val == "" { if val == "" {
val = defaultWoodpeckerImage 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)) 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) req, err := http.NewRequestWithContext(ctx, method, url, body)
if err != nil { if err != nil {
log.Fatalf("couldn't construct request for url %s: %s", url, err) log.Fatalf("couldn't construct request for url %s: %s", url, err)

View File

@ -268,7 +268,9 @@ func (m *repositoryRegistryResourceModel) setValues(_ context.Context, registry
return nil 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{ return &woodpecker.Registry{
ID: m.ID.ValueInt64(), ID: m.ID.ValueInt64(),
Address: m.Address.ValueString(), Address: m.Address.ValueString(),
@ -286,7 +288,10 @@ type repositoryRegistryDataSourceModel struct {
Email types.String `tfsdk:"email"` 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.ID = types.Int64Value(registry.ID)
m.Address = types.StringValue(registry.Address) m.Address = types.StringValue(registry.Address)
m.Username = types.StringValue(registry.Username) m.Username = types.StringValue(registry.Username)

View File

@ -36,7 +36,8 @@ func (p *woodpeckerProvider) Metadata(_ context.Context, _ provider.MetadataRequ
func (p *woodpeckerProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) { func (p *woodpeckerProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
resp.Schema = schema.Schema{ 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{ Attributes: map[string]schema.Attribute{
"server": schema.StringAttribute{ "server": schema.StringAttribute{
Optional: true, 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) cfg := newProviderConfig(ctx, req, resp)
if resp.Diagnostics.HasError() { if resp.Diagnostics.HasError() {
return return

View File

@ -31,7 +31,11 @@ func newRepositoryResource() resource.Resource {
return &repositoryResource{} 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" resp.TypeName = req.ProviderTypeName + "_repository"
} }
@ -159,7 +163,8 @@ func (r *repositoryResource) Schema(_ context.Context, _ resource.SchemaRequest,
"allow_pull_requests": schema.BoolAttribute{ "allow_pull_requests": schema.BoolAttribute{
Optional: true, Optional: true,
Computed: true, Computed: true,
Description: "Enables handling webhook's pull request event. If disabled, then pipeline won't run for pull requests.", Description: "Enables handling webhook's pull request event." +
" If disabled, then pipeline won't run for pull requests.",
PlanModifiers: []planmodifier.Bool{ PlanModifiers: []planmodifier.Bool{
boolplanmodifier.UseStateForUnknown(), boolplanmodifier.UseStateForUnknown(),
}, },
@ -190,8 +195,10 @@ func (r *repositoryResource) Schema(_ context.Context, _ resource.SchemaRequest,
"netrc_only_trusted": schema.BoolAttribute{ "netrc_only_trusted": schema.BoolAttribute{
Optional: true, Optional: true,
Computed: true, Computed: true,
MarkdownDescription: "whether netrc credentials should be only injected into trusted containers, " + MarkdownDescription: "whether netrc credentials should be only injected into trusted containers, see" +
"see [the docs](https://woodpecker-ci.org/docs/usage/project-settings#only-inject-netrc-credentials-into-trusted-containers) for more info", //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{ PlanModifiers: []planmodifier.Bool{
boolplanmodifier.UseStateForUnknown(), 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. // Prevent panic if the provider has not been configured.
if req.ProviderData == nil { if req.ProviderData == nil {
return return
@ -210,7 +221,10 @@ func (r *repositoryResource) Configure(_ context.Context, req resource.Configure
if !ok { if !ok {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type", "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 return
} }
@ -342,6 +356,10 @@ func (r *repositoryResource) Delete(ctx context.Context, req resource.DeleteRequ
// from provider logic. // 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)...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("full_name"), req.ID)...)
} }

View File

@ -27,7 +27,11 @@ func newRepositoryCronResource() resource.Resource {
return &repositoryCronResource{} 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" 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. // Prevent panic if the provider has not been configured.
if req.ProviderData == nil { if req.ProviderData == nil {
return return
@ -96,7 +104,10 @@ func (r *repositoryCronResource) Configure(_ context.Context, req resource.Confi
if !ok { if !ok {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type", "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 return
} }
@ -104,7 +115,11 @@ func (r *repositoryCronResource) Configure(_ context.Context, req resource.Confi
r.client = client 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 var data repositoryCronModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) 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)...) 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 var data repositoryCronModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) 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)...) 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 var data repositoryCronModel
resp.Diagnostics.Append(req.State.Get(ctx, &data)...) 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) 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) idParts := strings.Split(req.ID, importStateIDSeparator)
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {

View File

@ -42,7 +42,11 @@ resource "woodpecker_repository_cron" "test_cron" {
`, repo.ID, name), `, repo.ID, name),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_cron.test_cron", "id"), 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", "name", name),
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@daily"), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@daily"),
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", ""), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", ""),
@ -61,7 +65,11 @@ resource "woodpecker_repository_cron" "test_cron" {
`, repo.ID, name, branch.Name), `, repo.ID, name, branch.Name),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_cron.test_cron", "id"), 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", "name", name),
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@every 5m"), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@every 5m"),
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", branch.Name), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", branch.Name),
@ -79,7 +87,11 @@ resource "woodpecker_repository_cron" "test_cron" {
//`, repo.ID, name), //`, repo.ID, name),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_cron.test_cron", "id"), 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", "name", name),
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@daily"), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@daily"),
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", branch.Name), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", branch.Name),
@ -108,7 +120,11 @@ resource "woodpecker_repository_cron" "test_cron" {
}, },
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_cron.test_cron", "id"), 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", "name", name),
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@daily"), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "schedule", "@daily"),
resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", ""), resource.TestCheckResourceAttr("woodpecker_repository_cron.test_cron", "branch", ""),

View File

@ -27,11 +27,19 @@ func newRepositoryRegistryResource() resource.Resource {
return &repositoryRegistryResource{} 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" 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{ resp.Schema = schema.Schema{
MarkdownDescription: "This resource allows you to add/remove container registries for specific repositories." + MarkdownDescription: "This resource allows you to add/remove container registries for specific repositories." +
" When applied, a new registry will be created." + " 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. // Prevent panic if the provider has not been configured.
if req.ProviderData == nil { if req.ProviderData == nil {
return return
@ -90,7 +102,10 @@ func (r *repositoryRegistryResource) Configure(_ context.Context, req resource.C
if !ok { if !ok {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type", "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 return
} }
@ -98,7 +113,11 @@ func (r *repositoryRegistryResource) Configure(_ context.Context, req resource.C
r.client = client 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 var data repositoryRegistryResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) 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)...) 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 var data repositoryRegistryResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) 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)...) 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 var data repositoryRegistryResourceModel
resp.Diagnostics.Append(req.State.Get(ctx, &data)...) 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) 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) idParts := strings.Split(req.ID, importStateIDSeparator)
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {

View File

@ -43,7 +43,11 @@ resource "woodpecker_repository_registry" "test_registry" {
`, repo.ID, address), `, repo.ID, address),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"), 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", "address", address),
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"),
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"),
@ -61,7 +65,11 @@ resource "woodpecker_repository_registry" "test_registry" {
`, repo.ID, address), `, repo.ID, address),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"), 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", "address", address),
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test2"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test2"),
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test2"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test2"),
@ -79,7 +87,11 @@ resource "woodpecker_repository_registry" "test_registry" {
//`, repo.ID, address), //`, repo.ID, address),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"), 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", "address", address),
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"),
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"),
@ -104,12 +116,19 @@ resource "woodpecker_repository_registry" "test_registry" {
`, repo.ID, newAddress), `, repo.ID, newAddress),
ConfigPlanChecks: resource.ConfigPlanChecks{ ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{ PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("woodpecker_repository_registry.test_registry", plancheck.ResourceActionReplace), plancheck.ExpectResourceAction(
"woodpecker_repository_registry.test_registry",
plancheck.ResourceActionReplace,
),
}, },
}, },
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"), 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", "address", newAddress),
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"),
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"),
@ -131,7 +150,11 @@ resource "woodpecker_repository_registry" "test_registry" {
}, },
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_registry.test_registry", "id"), 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", "address", newAddress),
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "username", "test"),
resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"), resource.TestCheckResourceAttr("woodpecker_repository_registry.test_registry", "password", "test"),

View File

@ -33,13 +33,18 @@ func newRepositorySecretResource() resource.Resource {
return &repositorySecretResource{} 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" resp.TypeName = req.ProviderTypeName + "_repository_secret"
} }
func (r *repositorySecretResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { func (r *repositorySecretResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{ 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 applied, a new secret will be created." +
" When destroyed, that secret will be removed." + " When destroyed, that secret will be removed." +
" For more information see [the Woodpecker docs](https://woodpecker-ci.org/docs/usage/secrets).", " For more information see [the Woodpecker docs](https://woodpecker-ci.org/docs/usage/secrets).",
@ -89,7 +94,8 @@ func (r *repositorySecretResource) Schema(_ context.Context, _ resource.SchemaRe
"plugins_only": schema.BoolAttribute{ "plugins_only": schema.BoolAttribute{
Optional: true, Optional: true,
Computed: true, Computed: true,
MarkdownDescription: "whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)", MarkdownDescription: "whether secret is only available for" +
" [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)",
PlanModifiers: []planmodifier.Bool{ PlanModifiers: []planmodifier.Bool{
boolplanmodifier.UseStateForUnknown(), 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. // Prevent panic if the provider has not been configured.
if req.ProviderData == nil { if req.ProviderData == nil {
return return
@ -117,7 +127,10 @@ func (r *repositorySecretResource) Configure(_ context.Context, req resource.Con
if !ok { if !ok {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type", "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 return
} }
@ -125,7 +138,11 @@ func (r *repositorySecretResource) Configure(_ context.Context, req resource.Con
r.client = client 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 var data repositorySecretResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) 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)...) 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 var data repositorySecretResourceModel
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) 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)...) 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 var data repositorySecretResourceModel
resp.Diagnostics.Append(req.State.Get(ctx, &data)...) 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) 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) idParts := strings.Split(req.ID, importStateIDSeparator)
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" { if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {

View File

@ -46,7 +46,11 @@ resource "woodpecker_repository_secret" "test_secret" {
`, repo.ID, name), `, repo.ID, name),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"), 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", "name", name),
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123"), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123"),
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"),
@ -66,7 +70,11 @@ resource "woodpecker_repository_secret" "test_secret" {
`, repo.ID, name), `, repo.ID, name),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"), 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", "name", name),
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123123"), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123123"),
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"),
@ -86,7 +94,11 @@ resource "woodpecker_repository_secret" "test_secret" {
//`, repo.ID, name), //`, repo.ID, name),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"), 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", "name", name),
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123123"), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123123"),
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"),
@ -119,7 +131,11 @@ resource "woodpecker_repository_secret" "test_secret" {
}, },
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"), 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", "name", newName),
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123New"), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123New"),
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"),
@ -142,7 +158,11 @@ resource "woodpecker_repository_secret" "test_secret" {
}, },
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository_secret.test_secret", "id"), 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", "name", newName),
resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123New"), resource.TestCheckResourceAttr("woodpecker_repository_secret.test_secret", "value", "test123New"),
resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"), resource.TestCheckTypeSetElemAttr("woodpecker_repository_secret.test_secret", "events.*", "push"),

View File

@ -38,7 +38,11 @@ resource "woodpecker_repository" "test_repo" {
`, repo1.FullName), `, repo1.FullName),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "id"), 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", "name", repo1.Name),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo1.Owner.UserName), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo1.Owner.UserName),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "full_name", repo1.FullName), 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.TestCheckResourceAttr("woodpecker_repository.test_repo", "scm", "git"),
resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "timeout"), resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "timeout"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "visibility", "public"), 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_trusted", "true"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "false"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "false"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"),
@ -69,7 +77,11 @@ resource "woodpecker_repository" "test_repo" {
`, repo1.FullName), `, repo1.FullName),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "id"), 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", "name", repo1.Name),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo1.Owner.UserName), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo1.Owner.UserName),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "full_name", repo1.FullName), 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", "scm", "git"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "timeout", "30"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "timeout", "30"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "visibility", "private"), 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_trusted", "false"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "true"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "true"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"),
@ -96,7 +112,11 @@ resource "woodpecker_repository" "test_repo" {
//`, repo1.FullName), //`, repo1.FullName),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "id"), 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", "name", repo1.Name),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo1.Owner.UserName), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo1.Owner.UserName),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "full_name", repo1.FullName), 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", "scm", "git"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "timeout", "15"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "timeout", "15"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "visibility", "private"), 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_trusted", "false"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "true"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "true"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"),
@ -133,7 +157,11 @@ resource "woodpecker_repository" "test_repo" {
}, },
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "id"), 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", "name", repo2.Name),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo2.Owner.UserName), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "owner", repo2.Owner.UserName),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "full_name", repo2.FullName), 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.TestCheckResourceAttr("woodpecker_repository.test_repo", "scm", "git"),
resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "timeout"), resource.TestCheckResourceAttrSet("woodpecker_repository.test_repo", "timeout"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "visibility", "public"), 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_trusted", "false"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "false"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "is_gated", "false"),
resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"), resource.TestCheckResourceAttr("woodpecker_repository.test_repo", "allow_pull_requests", "true"),

View File

@ -37,7 +37,8 @@ func (r *secretResource) Metadata(_ context.Context, req resource.MetadataReques
func (r *secretResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { func (r *secretResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{ 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." + " When destroyed, that secret will be removed." +
" For more information see [the Woodpecker docs](https://woodpecker-ci.org/docs/usage/secrets).", " For more information see [the Woodpecker docs](https://woodpecker-ci.org/docs/usage/secrets).",
Attributes: map[string]schema.Attribute{ Attributes: map[string]schema.Attribute{
@ -79,7 +80,8 @@ func (r *secretResource) Schema(_ context.Context, _ resource.SchemaRequest, res
"plugins_only": schema.BoolAttribute{ "plugins_only": schema.BoolAttribute{
Optional: true, Optional: true,
Computed: true, Computed: true,
MarkdownDescription: "whether secret is only available for [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)", MarkdownDescription: "whether secret is only available for" +
" [plugins](https://woodpecker-ci.org/docs/usage/plugins/plugins)",
PlanModifiers: []planmodifier.Bool{ PlanModifiers: []planmodifier.Bool{
boolplanmodifier.UseStateForUnknown(), boolplanmodifier.UseStateForUnknown(),
}, },
@ -107,7 +109,10 @@ func (r *secretResource) Configure(_ context.Context, req resource.ConfigureRequ
if !ok { if !ok {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type", "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 return
} }
@ -208,6 +213,10 @@ func (r *secretResource) Delete(ctx context.Context, req resource.DeleteRequest,
resp.State.RemoveResource(ctx) 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)...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("name"), req.ID)...)
} }

View File

@ -32,10 +32,10 @@ func (r *userResource) Metadata(_ context.Context, req resource.MetadataRequest,
func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { func (r *userResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{ resp.Schema = schema.Schema{
MarkdownDescription: `Provides a user resource. MarkdownDescription: "Provides a user resource." +
"\n\n\nThis resource allows you to add/remove users." +
" When applied, a new user will be created." +
This resource allows you to add/remove users. When applied, a new user will be created. When destroyed, that user will be removed.`, " When destroyed, that user will be removed.",
Attributes: map[string]schema.Attribute{ Attributes: map[string]schema.Attribute{
"id": schema.Int64Attribute{ "id": schema.Int64Attribute{
Computed: true, Computed: true,
@ -96,7 +96,10 @@ func (r *userResource) Configure(_ context.Context, req resource.ConfigureReques
if !ok { if !ok {
resp.Diagnostics.AddError( resp.Diagnostics.AddError(
"Unexpected Data Source Configure Type", "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 return
} }
@ -199,6 +202,10 @@ func (r *userResource) Delete(ctx context.Context, req resource.DeleteRequest, r
// from provider logic. // 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)...) resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("login"), req.ID)...)
} }