Skip to content

Comments

Add gitlab codequality format#741

Open
Avihais12344 wants to merge 30 commits intoadrienverge:masterfrom
Avihais12344:feature/add-gitlab-codequality-format
Open

Add gitlab codequality format#741
Avihais12344 wants to merge 30 commits intoadrienverge:masterfrom
Avihais12344:feature/add-gitlab-codequality-format

Conversation

@Avihais12344
Copy link

Added codequality format as specified at the docs, with tests.

Please merge this for all the Gitlab users!

@coveralls
Copy link

coveralls commented Apr 18, 2025

Coverage Status

coverage: 99.817% (+0.002%) from 99.815%
when pulling df38c11 on Avihais12344:feature/add-gitlab-codequality-format
into e3d54cc on adrienverge:master.

@Avihais12344
Copy link
Author

Can someone please review and accept this PR?
@adrienverge

@Avihais12344
Copy link
Author

Fixes #743

@Avihais12344
Copy link
Author

Avihais12344 commented Apr 29, 2025

Please someone approve this.
@adrienverge

@adrienverge
Copy link
Owner

Please be patient.

@Avihais12344
Copy link
Author

Is there any news on this?
@adrienverge

@adrienverge
Copy link
Owner

Stop harassing me. I'll look at it when I can. It can be in months.

@Avihais12344
Copy link
Author

It's been months, I am back.
Any news @adrienverge ?

@Avihais12344
Copy link
Author

Maybe even @koyuki7w ?

@Avihais12344
Copy link
Author

It's not that big, please let's finish this:
@adrienverge @koyuki7w

@freehck
Copy link

freehck commented Jul 29, 2025

@Avihais12344
You already did all the work but gotta wait for eternity to have your stuff in upstream? Welcome to the FOSS! =)

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. =)

@Avihais12344
Copy link
Author

@freehck
I see, thanks for your advice.
But what would you do in this situation?

@freehck
Copy link

freehck commented Jul 30, 2025

@Avihais12344
I'd use the fork until PR's merged.
Somethig like this:
pip install git+https://github.com/freehck/yamllint.git@my-master

Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 GITLAB_CI indeed appears to be the best way to detect jobs executed in GitLab CI/CD:

Predefined variables

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much.
So I can resolve this conversation right?

yamllint/cli.py Outdated
Comment on lines 106 to 107
"begin": problem.line,
"end": problem.line,
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
What do you think @DimitriPapadopoulos? Added a comment so people would understand why I have did it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, why not?

yamllint/cli.py Outdated
first = False
else:
print(",")
print(textwrap.indent(Format.gitlab(problem, file), " "), end='')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why indent here and not in Format.gitlab? Both are possible of course. Is there a rational behind your choice?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right @EzLucky, I can solve this conversation now @DimitriPapadopoulos ?

@Avihais12344
Copy link
Author

I would recommend using single quotes (in Python code) for consistency.

Fixed.

@Avihais12344
Copy link
Author

Avihais12344 commented Sep 18, 2025

@Avihais12344 I'd use the fork until PR's merged. Somethig like this: pip install git+https://github.com/freehck/yamllint.git@my-master

Thanks for your suggestion, I would take that into account. Although it's missing the gitlab format...

@Avihais12344
Copy link
Author

@DimitriPapadopoulos @EzLucky I would like your review again please :)

@DimitriPapadopoulos
Copy link
Contributor

This PR looks in good shape. @adrienverge When you have time, I think it would be worth reviewing and eventually merging it.

Copy link

@EzLucky EzLucky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment on lines 64 to 70
- 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestions :

  • simplification : the reports directory is not needed
  • typo : there was an extra ')'
  • use of tee command to display output on the terminal
  • renaming of the output json as you may have codequality reports from other tools in your pipeline artifacts
Suggested change
- 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

@DimitriPapadopoulos
Copy link
Contributor

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``.

Or even simpler:

yamllint auto-detects when it's running inside of a GitLab CI/CD job and outputs the results as
a `Code Quality (CodeClimate)<https://docs.gitlab.com/ee/ci/testing/code_quality.html>`_ report.
You can also force GitLab Code Quality output with ``yamllint --format gitlab``.

…ample and rephrased the documentation itself to actually expain the capabilities.
@Avihais12344
Copy link
Author

Thanks for your suggestions @DimitriPapadopoulos and @EzLucky, I have tried to merge your 2 excellent suggestions.

@Avihais12344
Copy link
Author

@DimitriPapadopoulos I would like your approval as well.

@adrienverge When you can, please merge.

@DimitriPapadopoulos
Copy link
Contributor

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.

@Avihais12344
Copy link
Author

@adrienverge Just reminding.

@Avihais12344
Copy link
Author

@adrienverge Just reminding, and happy new year :)

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.

6 participants