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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
22 changes: 22 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Lint
on:
push:
paths-ignore:
- '**.md'
- 'releases.json'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- name: Set up Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod

- name: Lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.14.0
43 changes: 43 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: "2"
linters:
settings:
staticcheck:
checks:
# S1002 - should omit comparison to bool constant
# Justification (opinion): comparison to bool constant can be clearer in some cases
- -S1002
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofumpt
# Disabled this formatter temporarily because it reports too many issues.
# - golines
- gci
settings:
# Disabled this formatter temporarily because it reports too many issues.
# golines:
# max-len: 120
gci:
sections:
- standard
- default
- blank
- dot
- alias
- localmodule
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Issues will be triaged and modified (if necessary) by the [CODEOWNERS](CODEOWNER

This project employs [branch protection](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/managing-a-branch-protection-rule); the `main` branch is protected. Therefore, your changes MUST be committed to a branch and submitted as a pull request. Also, this project requires the use of [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for all commit messages. Using Conventional Commits enables this project to autogenerate its [CHANGELOG.md](../CHANGELOG.md) and release notes.

Your pull request must pass `golangci-lint`. For instructions, see "Linting and formatting" in the [Developer Guide](README.md#linting-and-formatting).

### Your Pull Request is Merged! Now What?

Congratulations! :tada: And thank you very much for your contribution to this project!
Expand Down
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: test lint fmt

test:
go test -v ./...

.PHONY: check-golangci-lint
check-golangci-lint:
@command -v golangci-lint >/dev/null 2>&1 || { \
echo "golangci-lint is not installed. See https://golangci-lint.run for instructions."; \
exit 1; \
}

.PHONY: lint
lint: check-golangci-lint
golangci-lint run ./...

.PHONY: fmt
fmt: check-golangci-lint
golangci-lint fmt ./...
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,23 @@ and add a Visual Studio Code workspace setting (`.vscode/settings.json`) for the
"go.testEnvFile": "${workspaceFolder}/.env"
}
```

### Linting and formatting

We use [golangci-lint](https://golangci-lint.run) to lint and format the code. The configuration is in `.golangci.yml`.
The pull request workflow runs golangci-lint, and your pull request must pass it.

See the [golangci-lint website](https://golangci-lint.run) for the install instructions.

To format the code, and then find lint issues, run these commands in the root folder:

```shell
golangci-lint fmt ./...
golangci-lint run ./...
```

If you have make, you can run make fmt and make lint instead.

## Release

Once your pull request has been approved:
Expand Down
3 changes: 2 additions & 1 deletion examples/accounts/create_azure_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"net/url"

uuid "github.com/google/uuid"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/accounts"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
uuid "github.com/google/uuid"
)

func CreateAzureOIDCExample() {
Expand Down
3 changes: 2 additions & 1 deletion examples/accounts/create_azure_service_principal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"fmt"
"net/url"

uuid "github.com/google/uuid"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/accounts"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
uuid "github.com/google/uuid"
)

func CreateAzureServicePrincipalExample() {
Expand Down
3 changes: 2 additions & 1 deletion examples/accounts/create_azure_subscription_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"net/url"

uuid "github.com/google/uuid"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/accounts"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
uuid "github.com/google/uuid"
)

func CreateAzureSubscriptionAccountExample() {
Expand Down
1 change: 0 additions & 1 deletion examples/deployment_processes/get_steps_using_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func GetStepsUsingRoleExample() {
// Loop through list
for _, project := range projects {
deploymentProcess, err := client.DeploymentProcesses.GetByID(project.DeploymentProcessID)

if err != nil {
_ = fmt.Errorf("error: %w", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package examples

import (
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/libraryvariablesets"
"net/url"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/libraryvariablesets"
)

func GetLibraryVariableSetByIDExample() {
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/delete_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package examples

import (
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projects"
"net/url"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projects"
)

// DeleteProjectExample provides an example of how to delete a project from
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/get_project_by_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package examples

import (
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projects"
"net/url"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projects"
)

func GetProjectByIDExample() {
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/update_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package examples

import (
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projects"
"net/url"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projects"
)

func UpdateProjectExample() {
Expand Down
2 changes: 1 addition & 1 deletion examples/spaces/delete_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package examples

import (
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
"net/url"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
)

// DeleteSpaceExample provides an example of how to delete a space from Octopus
Expand Down
2 changes: 1 addition & 1 deletion examples/spaces/get_space_by_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package examples

import (
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
"net/url"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
)

// GetSpaceByIDExample provides an example of how to get a space from Octopus
Expand Down
3 changes: 2 additions & 1 deletion examples/teams/create_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package examples

import (
"fmt"
"net/url"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/teams"
"net/url"
)

func CreateTeamExample() {
Expand Down
2 changes: 1 addition & 1 deletion examples/user_roles/delete_user_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package examples

import (
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/userroles"
"net/url"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/userroles"
)

// DeleteUserRoleExample provides an example of how to delete a user role from
Expand Down
2 changes: 1 addition & 1 deletion examples/users/delete_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package examples

import (
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/users"
"net/url"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/users"
)

// DeleteUserExample provides an example of how to delete a user from Octopus
Expand Down
2 changes: 1 addition & 1 deletion internal/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ func PrettyJSON(data interface{}) string {
encoder := json.NewEncoder(buffer)
encoder.SetIndent("", "\t")

encoder.Encode(data)
_ = encoder.Encode(data)
return buffer.String()
}
4 changes: 2 additions & 2 deletions internal/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package internal
import (
"testing"

uuid "github.com/google/uuid"
"github.com/stretchr/testify/assert"

uuid "github.com/google/uuid"
)

func TestValidateRequiredUUID(t *testing.T) {
Expand Down Expand Up @@ -90,5 +91,4 @@ func TestTrimTemplate(t *testing.T) {
template = "/api/users/{userId}/apikeys"
result = TrimTemplate(template)
assert.Equal(t, "/api/users", result)

}
5 changes: 3 additions & 2 deletions internal/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"strings"
"time"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/constants"
"github.com/dghubble/sling"
"github.com/google/uuid"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/constants"
)

const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
Expand All @@ -26,7 +27,7 @@ func GetRandomString(length int) string {

func GetRandomName() string {
fullName := fmt.Sprintf("test-id %s", uuid.New())
fullName = fullName[0:44] //Some names in Octopus have a max limit of 50 characters (such as Environment Name)
fullName = fullName[0:44] // Some names in Octopus have a max limit of 50 characters (such as Environment Name)
return fullName
}

Expand Down
3 changes: 2 additions & 1 deletion internal/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package internal

import (
"fmt"
"github.com/google/uuid"
"regexp"
"strings"

"github.com/google/uuid"
)

// ValidateStringInSlice checks if a string is in the given slice
Expand Down
5 changes: 3 additions & 2 deletions pkg/accounts/account.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package accounts

import (
"github.com/go-playground/validator/v10"
"github.com/go-playground/validator/v10/non-standard/validators"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/resources"
validation "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/validation"
"github.com/go-playground/validator/v10"
"github.com/go-playground/validator/v10/non-standard/validators"
)

// IAccount defines the interface for accounts.
Expand Down
6 changes: 4 additions & 2 deletions pkg/accounts/account_resource.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package accounts

import (
"github.com/go-playground/validator/v10"

uuid "github.com/google/uuid"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
resources "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/resources"
validation "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/validation"
"github.com/go-playground/validator/v10"
uuid "github.com/google/uuid"
)

// AccountResource represents account details used for deployments, including
Expand Down
5 changes: 3 additions & 2 deletions pkg/accounts/account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"testing"
"time"

"github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/kinbiko/jsonassert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/OctopusDeploy/go-octopusdeploy/v2/internal"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
)

func TestAccountResource(t *testing.T) {
Expand Down
Loading
Loading