diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..003b9f3 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,20 @@ +# Use the jguer/yay-builder image as a parent image with archlinux +FROM docker.io/jguer/yay-builder + +# Install extra packages (pacman-contrib and fish) +RUN sudo pacman -Syu --noconfirm pacman-contrib fish git-delta openssh bat go github-cli + +# Set passwordless sudo for the docker user +RUN echo "docker ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/docker + +# Create a non-root user and switch to it +USER docker + +# Add /app/bin to the PATH +ENV PATH="/app/bin:/home/docker/go/bin:${PATH}" + +# Set the working directory +WORKDIR /workspaces/aur + +# Command to run when starting the container +CMD ["sleep", "infinity"] \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..c6ab8cb --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,16 @@ +{ + "name": "Existing Dockerfile", + "build": { + "context": "..", + "dockerfile": "../.devcontainer/Dockerfile" + }, + "remoteUser": "docker", + "workspaceFolder": "/workspaces/aur", + "customizations": { + "vscode": { + "extensions": [ + "golang.go" + ] + } + } +} diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6344934..690cb9a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -5,21 +5,21 @@ jobs: name: Lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v6 - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v9 with: version: latest test: name: Test strategy: matrix: - go: ["^1.19"] - os: [macos-latest, windows-latest, ubuntu-latest] + go: ["^1.25"] + os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/checkout@v6 + - uses: actions/setup-go@v6 with: go-version: ${{ matrix.go }} - name: Test diff --git a/.golangci.yml b/.golangci.yml index 5fbfafb..1ab9a1b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,69 +1,18 @@ -linters-settings: - dupl: - threshold: 100 - funlen: - lines: 100 - statements: 50 - goconst: - min-len: 3 - min-occurrences: 4 - gocritic: - enabled-tags: - - diagnostic - - experimental - - opinionated - - performance - - style - gocyclo: - min-complexity: 15 - goimports: - local-prefixes: github.com/Jguer/yay/v11 - gomnd: - checks: - - argument - - case - - condition - - return - ignored-numbers: - - '0' - - '1' - - '2' - - '3' - ignored-functions: - - strings.SplitN - govet: - check-shadowing: true - lll: - line-length: 140 - misspell: - locale: US - nolintlint: - allow-unused: false # report any unused nolint directives - require-explanation: false # don't require an explanation for nolint directives - require-specific: false # don't require nolint directives to be specific about which linter is being skipped - +version: "2" +run: + go: "1.18" linters: - # please, do not use `enable-all`: it's deprecated and will be removed soon. - # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint - disable-all: true + default: none enable: - bodyclose - depguard - dogsled - dupl - errcheck - - exportloopref - # - funlen # TOFIX - gochecknoinits - # - goconst # TOFIX - gocritic - # - gocyclo # TOFIX - - gofmt - - goimports - # - gomnd # TOFIX - goprintffuncname - gosec - - gosimple - govet - ineffassign - lll @@ -72,30 +21,87 @@ linters: - noctx - nolintlint - staticcheck - - stylecheck - - typecheck - unconvert - unparam - unused - whitespace - -run: - go: '1.18' - -issues: - exclude-rules: - - path: _test\.go - linters: - - lll - - revive - - wsl - - govet - - godot - - errcheck - - stylecheck - - dupl - - gocritic - - gochecknoinits - - exclude: - - G204 + settings: + depguard: + rules: + Main: + allow: + - $gostd + - github.com/Jguer/aur + - github.com/Jguer/aur/rpc + - github.com/stretchr/testify/assert + - github.com/stretchr/testify/require + - github.com/stretchr/testify/mock + - github.com/ohler55/ojg/oj + - github.com/itchyny/gojq + - github.com/mitchellh/mapstructure + - github.com/hashicorp/go-multierror + dupl: + threshold: 100 + funlen: + lines: 100 + statements: 50 + goconst: + min-len: 3 + min-occurrences: 4 + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + gocyclo: + min-complexity: 15 + lll: + line-length: 140 + misspell: + locale: US + nolintlint: + require-explanation: false + require-specific: false + allow-unused: false + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + rules: + - linters: + - dupl + - errcheck + - gochecknoinits + - gocritic + - godot + - govet + - lll + - revive + - staticcheck + - wsl + path: _test\.go + - path: (.+)\.go$ + text: G204 + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + settings: + goimports: + local-prefixes: + - github.com/Jguer/yay/v11 + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/go.mod b/go.mod index 449223e..e606963 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/Jguer/aur -go 1.19 +go 1.25 require ( github.com/itchyny/gojq v0.12.11 diff --git a/rpc/query.go b/rpc/query.go index 2a33697..2621b0d 100644 --- a/rpc/query.go +++ b/rpc/query.go @@ -46,14 +46,6 @@ func (c *Client) Info(ctx context.Context, pkgs []string) ([]aur.Pkg, error) { return c.get(ctx, v) } -func min(a, b int) int { - if a < b { - return a - } - - return b -} - func (c *Client) batchInfo(ctx context.Context, names []string) ([]aur.Pkg, error) { info := make([]aur.Pkg, 0, len(names)) var err error @@ -68,13 +60,13 @@ func (c *Client) batchInfo(ctx context.Context, names []string) ([]aur.Pkg, erro } for n := 0; n < len(missing); n += c.batchSize { - max := min(len(missing), n+c.batchSize) + maxIdx := min(len(missing), n+c.batchSize) if c.logFn != nil { - c.logFn("packages to query", missing[n:max]) + c.logFn("packages to query", missing[n:maxIdx]) } - tempInfo, requestErr := c.Info(ctx, missing[n:max]) + tempInfo, requestErr := c.Info(ctx, missing[n:maxIdx]) if requestErr != nil { err = multierror.Append(err, requestErr) continue diff --git a/rpc/req.go b/rpc/req.go index 23fd59c..8fc086a 100644 --- a/rpc/req.go +++ b/rpc/req.go @@ -42,7 +42,7 @@ func parseRPCResponse(resp *http.Response) ([]aur.Pkg, error) { return nil, fmt.Errorf("response decoding failed: %w", err) } - if len(result.Error) > 0 { + if result.Error != "" { return nil, &aur.PayloadError{ StatusCode: resp.StatusCode, ErrorField: result.Error,