Skip to content

feat: Add GitLab output format support to CLI. #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

raffaelecarelle
Copy link
Contributor

@raffaelecarelle raffaelecarelle commented Mar 31, 2025

Introduced the "gitlab" format for CLI output, alongside existing "text" and "json" formats. This includes a new GitlabPrinter implementation, updates to the PrinterFactory and output option handling, as well as corresponding unit and E2E tests. The change enhances integration options, particularly for GitLab CI.

gitlab code quality format must have particular json format

see gitlab docs: https://docs.gitlab.com/ci/testing/code_quality/#code-quality-report-format

this PR depends on #475

@raffaelecarelle raffaelecarelle changed the title Add GitLab output format support to CLI. feat: Add GitLab output format support to CLI. Mar 31, 2025
@fain182
Copy link
Collaborator

fain182 commented Apr 1, 2025

@raffaelecarelle Apart from backward compatibility, do we have a good reason to maintain both a JSON format and a GitLab format? Does the current JSON format offer any advantages?
Otherwise, maybe we could simply update the JSON format to be compatible with the GitLab format...

@raffaelecarelle
Copy link
Contributor Author

Well, the GitLab format is specific to GitLab (initially I was the one who confused things, I apologize). Meanwhile, the JSON format can be used either by GitLab for other types of reports or also by other platforms like GitHub or SonarQube. I would keep both for greater flexibility, and to cover more use cases, but if it's more difficult then we can remove one of the two.

Introduced the "gitlab" format for CLI output, alongside existing "text" and "json" formats. This includes a new `GitlabPrinter` implementation, updates to the `PrinterFactory` and output option handling, as well as corresponding unit and E2E tests. The change enhances integration options, particularly for GitLab CI.
Introduced support for the GitLab-specific output format in the Check command and its end-to-end test suite. Modified the condition in the Check command to handle the GitLab format and added a corresponding test case to verify functionality for outputs with no errors.
Unified violation instantiation and assertion logic in tests, replacing mock-based violations with direct object creation. Simplified JSON output comparisons using `assertSame` with string literals. Updated `GitlabPrinter` to use relative paths for better clarity in output.
Replaced the use of `Path::makeRelative` and `getPathFromFqcn` with the `getFilePath` method in the `Violation` class for path resolution. Removed unused `getPathFromFqcn` method and Symfony `Path` dependency. Updated test cases accordingly to reflect the changes.
Copy link
Member

@micheleorselli micheleorselli left a comment

Choose a reason for hiding this comment

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

last round of rieview, then I think we are good to go

Simplified the GitLabPrinter logic by removing unnecessary nesting and improving error handling structure. Updated related tests to match the refactored implementation, including hardcoding FQCN strings for mock violations. Cleaned up outdated test dependencies and adjusted JSON output formatting for consistency.
Copy link
Member

@micheleorselli micheleorselli left a comment

Choose a reason for hiding this comment

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

thanks @raffaelecarelle! 🙇

@micheleorselli micheleorselli merged commit 58d222a into phparkitect:main Apr 7, 2025
16 checks passed
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.

3 participants