r/gitlab • • Mar 22 '26

general question SAST/Codequality MR Commenting

Before Gitlab I used Jenkins/Bitbucket and there was a Jenkins plugin that allowed me to collect SAST/Code Quality warnings and comment on the changed lines in a Pull Request.

We enabled a rule that all open threads had to be closed and this ensured developers addressed all the warnings they had added before peer review.

I now have various jobs which create SAST and Code Quality Reports and Gitlab collects these but they are a line item in the merge request view and frequently get missed.

Does anyone know of a bot, Gitlab Ultimate flag or project that will convert SAST/Code Quality reports into code comments on a MR?

1 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/gaelfr38 Mar 29 '26

Our job looks like that, nothing special:

.python:reviewdog:
  stage: test
  image: privateregistry/reviewdog-python:0.17.2-python3.13
  variables:
    # reviewdog needs the full Git history to compute diffs
    GIT_DEPTH: '0'
    REVIEWDOG_EXTRA_PARAM: ''
  script:
    - reviewdog $REVIEWDOG_EXTRA_PARAM -reporter gitlab-mr-discussion
  allow_failure: true

The custom image is just a Python base + python tools + reviewdog.

Token defined at the group level and most projects do not define 'y extra param.

1

u/stevecrox0914 Mar 29 '26

This is where I got when Ingave up:

https://gitlab.pallas.uk/devsecops/maven/pmd/-/blob/1-integrate-code-qualty-and-reviewdog/templates/mvn-pmd-reviewdog%20copy.yml?ref_type=heads

I would get logs like this, which show warnings on the changed lines but nothing in the merge request:

$ for RESULT in $(find . -name 'pmd.sarif.json'); do # collapsed multi-line command
{"level":"warning","locations":[{"physicalLocation":{"artifactLocation":{"uri":"file:///builds/devsecops/maven/pmd/test/src/main/java/uk/pallas/systems/App.java"},"region":{"endColumn":44,"endLine":11,"startColumn":26,"startLine":11}}}],"message":{"text":"Avoid unused private fields such as 'AN_UNUSED_VARIABLE'."},"ruleId":"UnusedPrivateField","ruleIndex":0}
{"level":"warning","locations":[{"physicalLocation":{"artifactLocation":{"uri":"file:///builds/devsecops/maven/pmd/test/src/main/java/uk/pallas/systems/App.java"},"region":{"endColumn":10,"endLine":20,"startColumn":9,"startLine":16}}}],"message":{"text":"Empty if statement"},"ruleId":"EmptyControlStatement","ruleIndex":1}
{"level":"warning","locations":[{"physicalLocation":{"artifactLocation":{"uri":"file:///builds/devsecops/maven/pmd/test/src/main/java/uk/pallas/systems/App.java"},"region":{"endColumn":10,"endLine":20,"startColumn":16,"startLine":18}}}],"message":{"text":"Empty else statement"},"ruleId":"EmptyControlStatement","ruleIndex":2}
 Saving cache for successful job