Skip to content
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

Add new endpoint /api/project_pull_requests/gitlab_report for GitLab #974

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kakawait
Copy link

@kakawait kakawait commented Oct 7, 2024

Fixes #296

The plugin sonar-gitlab-plugin is relying on /api/issues/search with query-parameter pullRequest to retrieve information and generate json.

Unfortunately the pullRequest parameter isn't available for CE edition.

Thus I've created a new endpoint called /api/project_pull_requests/gitlab_report with 2 mands parameters

  1. project
  2. pullRequest

This endpoint will transform all OPEN issue to GitLab codeclimate json format.

Thus simply add following inside your .gitlab-ci.yml after the analysis to get report (adapt your variables name, only CI_MERGE_REQUEST_IID is predefined)

    - |
      curl -o gl-code-quality-report.json --header "Authorization: Bearer ${SONAR_TOKEN}" "${SONAR_HOST_URL}/api/project_pull_requests/gitlab_report?project=${SONAR_PROJECT_KEY}&pullRequest=${CI_MERGE_REQUEST_IID}"
  artifacts:
    reports:
      codequality: gl-code-quality-report.json

And tada is working


The main advantage of this approach is that the current plugin workflow/way-to-do stay untouched. Only new end point is added and GitLab user has to download report by their own

…codeclimate

The plugin [sonar-gitlab-plugin](https://github.com/javamachr/sonar-gitlab-plugin) is relying on `/api/issues/search` with _query-parameter_ `pullRequest` to retrieve information and generate json.

Unfortunately the `pullRequest` parameter isn't available for CE edition.

Thus I've created a new endpoint called `/api/project_pull_requests/gitlab_report` with 2 mands parameters

1. `project`
2. `pullRequest`

This endpoint will transform all `OPEN` issue to `GitLab codeclimate` json format.

Thus simply add following inside your `.gitlab-ci.yml` after the analysis to get report (adapt your variables name, only `CI_MERGE_REQUEST_IID` is predefined)

```
    - |
      curl -o gl-code-quality-report.json --header "Authorization: Bearer ${SONAR_TOKEN}" "${SONAR_HOST_URL}/api/project_pull_requests/gitlab_report?project=${SONAR_PROJECT_KEY}&pullRequest=${CI_MERGE_REQUEST_IID}"
  artifacts:
    reports:
      codequality: gl-code-quality-report.json
```

And tada is working
@mc1arke
Copy link
Owner

mc1arke commented Nov 11, 2024

I don't understand the statement:

The plugin sonar-gitlab-plugin is relying on /api/issues/search with query-parameter pullRequest to retrieve information and generate json.

Unfortunately the pullRequest parameter isn't available for CE edition.

The pullRequest parameter works if you specify the componentKeys as the project key when the sonarqube-community-branch -plugin is installed, e.g. for a project with key webgoat and a pull request with ID 2, then the request URL would be /api/issues/search?pullRequest=2&componentKeys=webgoat&resolved=false which is what I believe is what https://github.com/javamachr/sonar-gitlab-plugin/blob/e3f46c4ec22c0055f77e80adf48bdcadacad6432/src/main/java/com/talanlabs/sonar/plugins/gitlab/SonarFacade.java#L239 is doing.

Are you able to provide more information about the issue you're encountering?

@kakawait
Copy link
Author

Sorry for delay.

Last time I've checked on my own instance, the official api always returned me empty !

Thus i'll double check because now I've doubt

In addition, this new endpoint has advantage to directly return CodeClimate compatible JSON, preventing doing it CI side. But as you may see, transforming isn't the big deal

@fastfend
Copy link

Any update on this PR?
Would love to see that merged

@mc1arke
Copy link
Owner

mc1arke commented Dec 24, 2024

Based on my last comment, I need a response on why the existing endpoints don't provide the required functionality.

@fastfend
Copy link

Great, gonna checkout what proposed endpoint can provide after christmas then

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.

[Gitlab] Generate codeclimate.json for Gitlab Code Quality MR Widget
3 participants