Skip to content

Add gitlab code quality report format - #9076

Open
comkieffer wants to merge 3 commits into
cppcheck-opensource:mainfrom
comkieffer:add-gitlab-code-quality-report-format
Open

comkieffer wants to merge 3 commits into
cppcheck-opensource:mainfrom
comkieffer:add-gitlab-code-quality-report-format

Conversation

@comkieffer

Copy link
Copy Markdown

Add a Gitlab Code Quality result format.

Gitlab SARIF reports are reserved for Ultimate subscriptions (not just Premium). The option so far has been to generate an xml report, and use cppcheck-codequality to convert that xml in the JSON CodeClimate format used by the Gitlab Code Quality feature.

This pull-request adds a native Gitlab Code Quality format to cppcheck.

It adds a gitlab-codequality option to the --output-format CLI option, and follows the same logic as the SARIF report. The Code Quality report is a lot more limited than the SARIF repoort though, so the feature is quite a bit simpler.

The main logic deviation between the two is that Gitlab require repository-relative paths for files. We can't check for that in cppcheck, but we can at least check that there are no absolute paths in the report.

Test it with:

cppcheck \
    --enable=warning,style,performance \
    --output-format=gitlab-codequality \
    --relative-paths="$PWD" \
    --output-file=gl-code-quality-report.json \
    src

As a sanity check of the output, I compared the new JSON with the output of cppcheck-codequality and they are identical, except for the fingerprint field. This implementation uses the finding hash, where cppcheck-codequality computed it's own hash.

Add --output-format=gitlab-codequality, which writes findings as a
GitLab Code Quality JSON array. Findings without a source location are
skipped because GitLab requires a location. The existing warning hash is
used as the fingerprint, with a location-based fallback when no token
hash is available.
Track whether the GitLab Code Quality report contains an absolute
location. Warn on stdout so the JSON report on stderr stays valid, even
when --relative-paths was given but did not make the path relative.
Append the CWE ID to the finding description when available, matching
the output of cppcheck-codequality.
@dmcppcheck

Copy link
Copy Markdown
Contributor

There should probably be a trac ticket for this PR. Please create it, or ask us to create it. Then the PR title should be updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants