Add gitlab codequality format#741
Conversation
|
Can someone please review and accept this PR? |
|
Fixes #743 |
|
Please someone approve this. |
|
Please be patient. |
|
Is there any news on this? |
|
Stop harassing me. I'll look at it when I can. It can be in months. |
|
It's been months, I am back. |
|
Maybe even @koyuki7w ? |
|
It's not that big, please let's finish this: |
|
@Avihais12344 Believe me it's still not so long. Once upon time in one python project I've been waiting for several years, and eventually found the authors decided to rewrite the code from scratch dumping all the work done. So be patient man. Be patient. =) |
|
@freehck |
|
@Avihais12344 |
DimitriPapadopoulos
left a comment
There was a problem hiding this comment.
I would recommend using single quotes (in Python code) for consistency.
yamllint/cli.py
Outdated
| if ('GITHUB_ACTIONS' in os.environ and | ||
| 'GITHUB_WORKFLOW' in os.environ): | ||
| args_format = 'github' | ||
| elif ("GITLAB_CI" in os.environ): |
There was a problem hiding this comment.
👍 GITLAB_CI indeed appears to be the best way to detect jobs executed in GitLab CI/CD:
There was a problem hiding this comment.
Thank you so much.
So I can resolve this conversation right?
yamllint/cli.py
Outdated
| "begin": problem.line, | ||
| "end": problem.line, |
There was a problem hiding this comment.
From JSON linting best practices:
For numerical values, quotes are optional but it is a good idea to enclose them in double quotes.
Not sure about this one: quotes are optional, but would it be a "good idea" to add quotes as suggested?
I understand you'd have to cast with str() as is the case for the hash above.
There was a problem hiding this comment.
Done.
What do you think @DimitriPapadopoulos? Added a comment so people would understand why I have did it.
There was a problem hiding this comment.
Well, why not?
yamllint/cli.py
Outdated
| first = False | ||
| else: | ||
| print(",") | ||
| print(textwrap.indent(Format.gitlab(problem, file), " "), end='') |
There was a problem hiding this comment.
Why indent here and not in Format.gitlab? Both are possible of course. Is there a rational behind your choice?
There was a problem hiding this comment.
The JSON finalization is made here (print of "[", "]", "," between blocks), so I think he wanted to keep that final formatting here, and Format.gitlab to only return a JSON block ready to be inserted in the final output
There was a problem hiding this comment.
That's right @EzLucky, I can solve this conversation now @DimitriPapadopoulos ?
Co-authored-by: Dimitri Papadopoulos Orfanos <[email protected]>
Fixed. |
Thanks for your suggestion, I would take that into account. Although it's missing the |
|
@DimitriPapadopoulos @EzLucky I would like your review again please :) |
|
This PR looks in good shape. @adrienverge When you have time, I think it would be worth reviewing and eventually merging it. |
EzLucky
left a comment
There was a problem hiding this comment.
Please modify in docs/integration.rst line 53 :
You can use the following GitLab CI/CD stage to run yamllint and get the
results as a `Code quality (Code Climate)
<https://docs.gitlab.com/ee/ci/testing/code_quality.html>`_ report.to :
yamllint auto-detects when it's running inside of a GitLab CI/CD job
and automatically uses the suited output format to get the
results as a `Code quality (Code Climate)<https://docs.gitlab.com/ee/ci/testing/code_quality.html>`_ report.
You can also force GitLab Code quality output with ``yamllint --format gitlab``.
You can use the following GitLab CI/CD stage to otain a codequality report artifact:(I can use the suggestion feature on this part of the file)
docs/integration.rst
Outdated
| - mkdir reports | ||
| - > | ||
| yamllint -f parsable . | tee >(awk ' | ||
| BEGIN {FS = ":"; ORS="\n"; first=1} | ||
| { | ||
| gsub(/^[ \t]+|[ \t]+$|"/, "", $4); | ||
| match($4, /^\[(warning|error)\](.*)\((.*)\)$/, a); | ||
| sev = (a[1] == "error" ? "major" : "minor"); | ||
| if (first) { | ||
| first=0; | ||
| printf("["); | ||
| } else { | ||
| printf(","); | ||
| } | ||
| printf("{\"location\":{\"path\":\"%s\",\"lines\":{\"begin\":%s,"\ | ||
| "\"end\":%s}},\"severity\":\"%s\",\"check_name\":\"%s\","\ | ||
| "\"categories\":[\"Style\"],\"type\":\"issue\","\ | ||
| "\"description\":\"%s\"}", $1, $2, $3, sev, a[3], a[2]); | ||
| } | ||
| END { if (!first) printf("]\n"); }' > reports/codequality.json) | ||
| - yamllint -f gitlab . > codequality.json) | ||
| artifacts: | ||
| when: always | ||
| paths: | ||
| - reports | ||
| expire_in: 1 week | ||
| reports: | ||
| codequality: reports/codequality.json |
There was a problem hiding this comment.
Suggestions :
- simplification : the reports directory is not needed
- typo : there was an extra ')'
- use of
teecommand to display output on the terminal - renaming of the output json as you may have codequality reports from other tools in your pipeline artifacts
| - mkdir reports | |
| - > | |
| yamllint -f parsable . | tee >(awk ' | |
| BEGIN {FS = ":"; ORS="\n"; first=1} | |
| { | |
| gsub(/^[ \t]+|[ \t]+$|"/, "", $4); | |
| match($4, /^\[(warning|error)\](.*)\((.*)\)$/, a); | |
| sev = (a[1] == "error" ? "major" : "minor"); | |
| if (first) { | |
| first=0; | |
| printf("["); | |
| } else { | |
| printf(","); | |
| } | |
| printf("{\"location\":{\"path\":\"%s\",\"lines\":{\"begin\":%s,"\ | |
| "\"end\":%s}},\"severity\":\"%s\",\"check_name\":\"%s\","\ | |
| "\"categories\":[\"Style\"],\"type\":\"issue\","\ | |
| "\"description\":\"%s\"}", $1, $2, $3, sev, a[3], a[2]); | |
| } | |
| END { if (!first) printf("]\n"); }' > reports/codequality.json) | |
| - yamllint -f gitlab . > codequality.json) | |
| artifacts: | |
| when: always | |
| paths: | |
| - reports | |
| expire_in: 1 week | |
| reports: | |
| codequality: reports/codequality.json | |
| - yamllint -f gitlab . | tee yamllint-codequality.json | |
| artifacts: | |
| when: always | |
| expire_in: 1 week | |
| reports: | |
| codequality: yamllint-codequality.json |
Or even simpler: |
…ample and rephrased the documentation itself to actually expain the capabilities.
|
Thanks for your suggestions @DimitriPapadopoulos and @EzLucky, I have tried to merge your 2 excellent suggestions. |
|
@DimitriPapadopoulos I would like your approval as well. @adrienverge When you can, please merge. |
|
LGTM, and an addition worth the additional complexity as far as I'm concerned. But the this is up to the maintainer and I know he's quite busy. Please be patient. |
|
@adrienverge Just reminding. |
|
@adrienverge Just reminding, and happy new year :) |
Added codequality format as specified at the docs, with tests.
Please merge this for all the Gitlab users!