Categorygithub.com/exepirit/gitea-golangci-lint
modulepackage
0.3.0
Repository: https://github.com/exepirit/gitea-golangci-lint.git
Documentation: pkg.go.dev

# README

gitea-golangci-lint

Docker Image Size (latest by date)

This tool can send golangci-lint issues to Gitea as pull request reviews. You can visit https://golangci-lint.run/ to find the golangci-lint configurations.

Docker Image

To check the docker image, visit https://hub.docker.com/r/exepir1t/gitea-golangci-lint

docker pull exepir1t/gitea-golangci-lint

Build

CGO_ENABLED=0 go build -o gitea-golangci-lint

Configuration

There are 6 environment variables to be configured when you want to run this tool.

VariableDescriptionExample
GITEA_URLGitea server urlhttps://try.gitea.io
GITEA_USERGitea usernamegolanglinter
GITEA_TOKENGitea access tokenyour_gitea_user_accesstoken
GITEA_REPORepository name, which is inspectedoctocat/hello_world
PULL_REQUESTPull request ID123
HTTP_TIMEOUTHTTP requests timeout in seconds30
LINT_FORMATThe input format from os.Stdin, default to be emptyempty or checkstyle
STATUS_CONTEXTThe gitea's commit status context, empty will not sendSTATUS_CONTEXT

How to use?

Run it in the shell

golangci-lint run | gitea-golangci-lint

# Support checkstyle input format
golangci-lint run --out-format=checkstyle | gitea-golangci-lint --format=checkstyle

# Send commit check status to gitea
golangci-lint run --out-format=checkstyle | gitea-golangci-lint --format=checkstyle --status=golangci-lint

# for php lint tools
# try below command in your composer project, you should install php-cs-fixer and phpstan first
./vendor/bin/php-cs-fixer fix --config=./.php-cs-fixer.dist.php --dry-run --using-cache=no --format=checkstyle | gitea-golangci-lint --format=checkstyle
./vendor/bin/phpstan --error-format=checkstyle | gitea-golangci-lint --format=checkstyle

Run with Drone docker pipeline

Below is a drone task configuration, it may help you to config your drone task.

---
kind: pipeline
type: docker
name: default

volumes:
  - name: deps
    temp: { }

steps:
  - name: linter
    image: golangci/golangci-lint:latest-alpine
    pull: if-not-exists
    volumes:
      - name: deps
        path: /go
    commands:
      - golangci-lint run | tee .golangci-lint.log
      - |
        [[ -z "$${DRONE_PULL_REQUEST}" ]] && [[ -s .golangci-lint.log ]] && exit 1
      - exit 0
  - name: push linter review
    image: exepir1t/gitea-golangci-lint:latest
    pull: if-not-exists
    environment:
      GITEA_URL:
        from_secret: GITEA_URL
      GITEA_USER:
        from_secret: GITEA_CI_USER
      GITEA_TOKEN:
        from_secret: GITEA_CI_TOKEN
    commands:
      - cat .golangci-lint.log | /bin/gitea-golangci-lint
    when:
      event:
        - pull_request

Make the pipeline in the .drone.yml to be run correctly,you should add secrets as below:

  1. GITEA_URL: origin of Gitea server,Like: https://git.example.com;
  2. GITEA_CI_USER: user of Gitea server,Like: gitea, which has read authorization to the repo;
  3. GITEA_CI_TOKEN: token of Gitea user, which has read authorization to the repo;

# Packages

No description provided by the author

# Functions

No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author