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
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
1 participant