Skip to main content

Parse linter output and convert it to GitLab Code Quality report

Project description

GitLab-CQ

Parse linter output and convert it to GitLab Code Quality report.

Supported Linters

Pull Requests for additional linter support are welcome.

Installation

$ python -m pip install -U gitlab-cq

Or use pipx:

$ pipx install gitlab-cq

Usage

There are two ways to use GitLab-CQ: run linter command via. GitLab-CQ or parse linter output from stdin.

Run linter command via. GitLab-CQ:

$ gitlab-cq [--output file_path] [--merge] [--echo] CMD [Arguments]

Parse linter output from stdin:

$ CMD [Arguments] | gitlab-cq [--output file_path] [--merge] [--echo] LINTER

Arguments:

  • CMD:
    • Command to run linter.
  • Arguments:
    • Arguments for linter command.
  • LINTER:
    • Linter name to parse: {ruff, pyright, mypy, gcc, clang-tidy, clang}

Options:

  • --output file_path:
    • Output to file_path.
  • --merge:
    • Merge output to existing JSON file (available if --output is specified).
  • --echo:
    • Echo linter output (available if --output is specified).

Required options for linters

The following options are required for linters when parsing from stdin.
(No need to add the following when the linter runs via. GitLab-CQ, since these options are automatically added.)

  • ruff:
    • --output-format json is required and do not pass --output option.
  • pyright:
    • --outputjson is required.
  • mypy:
    • --output=json is required.

Example

Integration to GitLab CI and save an GitLab CQ artifact:

code quality:
  stage: test
  script:
    # Run linters via. GitLab-CQ and merge output to gl-code-quality-report.json
    - pipx install gitlab-cq
    - gitlab-cq --output gl-code-quality-report.json         ruff check .
    - gitlab-cq --output gl-code-quality-report.json --merge pyright .
    - gitlab-cq --output gl-code-quality-report.json --merge mypy .
    # Parse linter/compiler output and merge to gl-code-quality-report.json
    - gcc -Wall -Wextra -o /dev/null -c main.c 2>&1     | gitlab-cq --output gl-code-quality-report.json --merge gcc
    - clang-tidy -format-style=file -p . --quiet main.c | gitlab-cq --output gl-code-quality-report.json --merge clang-tidy  
  artifacts:
    reports:
      codequality: gl-code-quality-report.json

Author

Yoshiki Matsuda (@yosh-matsuda)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitlab_cq-0.2.0.tar.gz (12.9 kB view hashes)

Uploaded Source

Built Distribution

gitlab_cq-0.2.0-py3-none-any.whl (11.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page