diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b222d2c0..f346163f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,34 +1,38 @@ name: ci -on: pull_request +on: + pull_request: + types: [opened, reopened, synchronize] + push: + branches: + - main jobs: go-lint: runs-on: ubuntu-latest steps: + - name: Checkout code + uses: actions/checkout@v4 - name: Install Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: - go-version: 1.23.x - - name: Checkout code - uses: actions/checkout@v3 + go-version-file: "go.mod" - name: Run linters - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v8 with: version: latest args: --timeout=3m go-test: strategy: matrix: - go-version: [1.23.x] platform: [ubuntu-latest] runs-on: ${{ matrix.platform }} steps: + - name: Checkout code + uses: actions/checkout@v4 - name: Install Go if: success() - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: - go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v3 + go-version-file: "go.mod" - name: go tests run: go test -v -covermode=count -json ./... > test.json - name: annotate go tests diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml deleted file mode 100644 index 6d34a404..00000000 --- a/.github/workflows/main.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: main ci -on: - push: - branches: - - main -jobs: - go-lint: - runs-on: ubuntu-latest - steps: - - name: Install Go - uses: actions/setup-go@v4 - with: - go-version: 1.23.x - - name: Checkout code - uses: actions/checkout@v3 - - name: Run linters - uses: golangci/golangci-lint-action@v3 - with: - version: latest - args: --timeout=3m - go-test: - strategy: - matrix: - go-version: [ 1.23.x ] - platform: [ ubuntu-latest ] - runs-on: ${{ matrix.platform }} - steps: - - name: Install Go - if: success() - uses: actions/setup-go@v4 - with: - go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v3 - - name: go tests - run: go test -v -covermode=count -json ./... > test.json - - name: annotate go tests - if: always() - uses: guyarb/golang-test-annotations@v0.5.1 - with: - test-results: test.json \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index f19f7f12..38018708 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,96 +1,116 @@ -#AUTO GENERATED CODE. UPDATE THE CONFIG IN BATON-TEMPLATE FIRST -linters-settings: - exhaustive: - default-signifies-exhaustive: true - gocritic: - enabled-checks: - - ruleguard - # The list of supported checkers can be find in https://go-critic.github.io/overview. - settings: - underef: - # Whether to skip (*x).method() calls where x is a pointer receiver. - skipRecvDeref: false - ruleguard: - rules: "${configDir}/tools/rules.go" - govet: - enable-all: true - disable: - - fieldalignment # too strict - - shadow # complains too much about shadowing errors. All research points to this being fine. - nakedret: - max-func-lines: 0 - nolintlint: - allow-no-explanation: [forbidigo, tracecheck, gomnd, gochecknoinits, makezero] - require-explanation: true - require-specific: true - revive: - ignore-generated-header: true - severity: error - rules: - - name: atomic - - name: line-length-limit - arguments: [200] - # These are functions that we use without checking the errors often. Most of these can't return an error even - # though they implement an interface that can. - - name: unhandled-error - arguments: - - fmt.Printf - - fmt.Println - - fmt.Fprint - - fmt.Fprintf - - fmt.Fprintln - - os.Stderr.Sync - - sb.WriteString - - buf.WriteString - - hasher.Write - - os.Setenv - - os.RemoveAll - - name: var-naming - arguments: [["ID", "URL", "HTTP", "API"], []] - tenv: - all: true +version: "2" linters: - disable-all: true + default: none enable: - - errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases - - gosimple # Linter for Go source code that specializes in simplifying a code - - govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string - - ineffassign # Detects when assignments to existing variables are not used - - staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks - - typecheck # Like the front-end of a Go compiler, parses and type-checks Go code - - unused # Checks Go code for unused constants, variables, functions and types - - asasalint # Check for pass []any as any in variadic func(...any) - - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers - - bidichk # Checks for dangerous unicode character sequences - - bodyclose # checks whether HTTP response body is closed successfully - - durationcheck # check for two durations multiplied together - - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. - - exhaustive # check exhaustiveness of enum switch statements - - forbidigo # Forbids identifiers - - gochecknoinits # Checks that no init functions are present in Go code - - goconst # Finds repeated strings that could be replaced by a constant - - gocritic # Provides diagnostics that check for bugs, performance and style issues. - - godot # Check if comments end in a period - - goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. - - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. - - goprintffuncname # Checks that printf-like functions are named with f at the end - - gosec # Inspects source code for security problems - - nakedret # Finds naked returns in functions greater than a specified function length - - nilerr # Finds the code that returns nil even if it checks that the error is not nil. - - noctx # noctx finds sending http request without context.Context - - nolintlint # Reports ill-formed or insufficient nolint directives - - nonamedreturns # Reports all named returns - - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. - - predeclared # find code that shadows one of Go's predeclared identifiers - - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. - - tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17 - - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes - - unconvert # Remove unnecessary type conversions - - usestdlibvars # detect the possibility to use variables/constants from the Go standard library - - whitespace # Tool for detection of leading and trailing whitespace + - asasalint + - asciicheck + - bidichk + - bodyclose + - durationcheck + - errcheck + - errorlint + - exhaustive + - forbidigo + - gochecknoinits + - goconst + - gocritic + - godot + - gomoddirectives + - goprintffuncname + - gosec + - govet + - ineffassign + - nakedret + - nilerr + - noctx + - nolintlint + - nonamedreturns + - nosprintfhostport + - predeclared + - revive + - staticcheck + - tparallel + - unconvert + - unused + - usestdlibvars + - whitespace + settings: + exhaustive: + default-signifies-exhaustive: true + gocritic: + enabled-checks: + - ruleguard + settings: + ruleguard: + rules: ${base-path}/tools/rules.go + underef: + skipRecvDeref: false + govet: + disable: + - fieldalignment + - shadow + enable-all: true + nakedret: + max-func-lines: 0 + nolintlint: + require-explanation: true + require-specific: true + allow-no-explanation: + - forbidigo + - tracecheck + - gomnd + - gochecknoinits + - makezero + revive: + severity: error + rules: + - name: atomic + - name: line-length-limit + arguments: + - 200 + - name: unhandled-error + arguments: + - fmt.Printf + - fmt.Println + - fmt.Fprint + - fmt.Fprintf + - fmt.Fprintln + - os.Stderr.Sync + - sb.WriteString + - buf.WriteString + - hasher.Write + - os.Setenv + - os.RemoveAll + - name: var-naming + arguments: + - - ID + - URL + - HTTP + - API + - [] + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - godot + source: (TODO) + paths: + - third_party$ + - builtin$ + - examples$ issues: max-same-issues: 50 - exclude-rules: - # Don't require TODO comments to end in a period - - source: "(TODO)" - linters: [godot] +formatters: + enable: + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/pkg/connector/role.go b/pkg/connector/role.go index 79ec720d..ed245e3a 100644 --- a/pkg/connector/role.go +++ b/pkg/connector/role.go @@ -25,12 +25,14 @@ const ( roleGuest = "guest" roleUser = "user" roleAdmin = "admin" + roleOwner = "owner" ) var roles = []string{ roleGuest, roleUser, roleAdmin, + roleOwner, } // Create a new connector resource for a Linear role. diff --git a/pkg/connector/user.go b/pkg/connector/user.go index 5586346c..cf0ed06e 100644 --- a/pkg/connector/user.go +++ b/pkg/connector/user.go @@ -38,6 +38,8 @@ func userResource(ctx context.Context, user *linear.User, parentResourceID *v2.R var userRole string switch { + case user.Owner: + userRole = roleOwner case user.Admin: userRole = roleAdmin case user.Guest: diff --git a/pkg/linear/client.go b/pkg/linear/client.go index b6538443..3e33dafc 100644 --- a/pkg/linear/client.go +++ b/pkg/linear/client.go @@ -170,6 +170,7 @@ func (c *Client) GetUsers(ctx context.Context, getResourceVars GetResourcesVars) organization { id } + owner } pageInfo { endCursor @@ -299,6 +300,7 @@ func (c *Client) GetOrganization(ctx context.Context, paginationVars PaginationV id admin guest + owner } pageInfo { hasPreviousPage @@ -450,6 +452,7 @@ func (c *Client) Authorize(ctx context.Context) (ViewerPermissions, *http.Respon guest id admin + owner } }` b := map[string]interface{}{ diff --git a/pkg/linear/models.go b/pkg/linear/models.go index d1816503..0f37d0c5 100644 --- a/pkg/linear/models.go +++ b/pkg/linear/models.go @@ -57,6 +57,7 @@ type User struct { Teams struct { Nodes []Team `json:"nodes"` } `json:"teams"` + Owner bool `json:"owner"` } type Team struct { @@ -110,6 +111,7 @@ func (e *GraphQLError) Message() string { type ViewerPermissions struct { Guest bool `json:"guest"` Admin bool `json:"admin"` + Owner bool `json:"owner"` ID string `json:"id"` }