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

[Gitlab] Merge Request Decoration doesn't support MR from fork project to main project #181

Closed
donkeylin opened this issue Jun 2, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@donkeylin
Copy link

Hi there,

First I want to thank you for the good work on the plugin!
but It seems the latest plugin 1.3.0 still not support Gitlab MR decoration for MR from forked project to main project.
I have a main project main/master and a fork project own/master, when I create a MR and trigger the CI pipeline, sonarqube showing the correct MR analysis, but there's no decoration comment on gitlab side.

From the log I can see

2020.06.02 18:51:23 INFO  ce[AXJ2X61Zm35d9lpDnh-C][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] Status url is: https://localhost//api/v4/projects/2489/statuses/f75f87d4e49dbf5fac735149e3f8426a2daa7eac
2020.06.02 18:51:23 INFO  ce[AXJ2X61Zm35d9lpDnh-C][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] PR commits url is: https://localhost//api/v4/projects/2489/merge_requests/6/commits
2020.06.02 18:51:23 INFO  ce[AXJ2X61Zm35d9lpDnh-C][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] MR discussion url is: https://localhost//api/v4/projects/2489/merge_requests/6/discussions
2020.06.02 18:51:23 INFO  ce[AXJ2X61Zm35d9lpDnh-C][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] User url is: https://localhost//api/v4/user
...
2020.06.01 17:48:55 ERROR ce[AXJxAB6mm35d9lpDnh94][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] {"message":"404 References for commit Not Found"}
2020.06.01 17:48:55 ERROR ce[AXJxAB6mm35d9lpDnh94][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Execution of task class com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask failed
java.lang.IllegalStateException: An error was returned in the response from the Gitlab API. See the previous log messages for details
        at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.gitlab.GitlabServerPullRequestDecorator.validateGitlabResponse(GitlabServerPullRequestDecorator.java:324)
        at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.gitlab.GitlabServerPullRequestDecorator.postStatus(GitlabServerPullRequestDecorator.java:315)
        at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.gitlab.GitlabServerPullRequestDecorator.decorateQualityGateStatus(GitlabServerPullRequestDecorator.java:159)
        at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask.finished(PullRequestPostAnalysisTask.java:132)
        at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.executeTask(PostProjectAnalysisTasksExecutor.java:113)
        at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.finished(PostProjectAnalysisTasksExecutor.java:107)
        at org.sonar.ce.task.step.ComputationStepExecutor.executeListener(ComputationStepExecutor.java:91)

it's reporting the post statuses failed.
The statuses URL is
https://localhost//api/v4/projects/2489/statuses/f75f87d4e49dbf5fac735149e3f8426a2daa7ea
dfc

note the project id in URL is 2489, my main project id is 2489 and the forked project id is 2490, if I understand correctly, the postStatus is trying to update the commit's status, however this commit belongs to forked project, so using main project id 2489 is not gonna find any valid commit.

I think GitlabServerPullRequestDecorator needs to adjust to support this case.

My environment:
Sonarqube: 7.9.3 community
Branch plugin: 1.3.0
Gitlab: 12.4.0

The gradle script for generating analysis is
gradle sonarqube -Dsonar.qualitygate.wait=true -Dsonar.pullrequest.key=$CI_MERGE_REQUEST_IID -Dsonar.pullrequest.branch=$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME -Dsonar.pullrequest.base=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME -Dsonar.pullrequest.gitlab.repositorySlug=$CI_MERGE_REQUEST_PROJECT_ID

@mc1arke
Copy link
Owner

mc1arke commented Jun 2, 2020

I believe this is related to the fix that @arch1tect0r has proposed as part of #179

@donkeylin
Copy link
Author

Yup, you're right. It's duplicated.

@mc1arke mc1arke added the bug Something isn't working label Oct 26, 2020
mc1arke pushed a commit that referenced this issue Mar 6, 2021
…ed project

When submitting the status of a merge request to Gitlab, the plugin was attempting to submit to a commit on the MR's target project, but was getting a `404 Not Found` response from the Gitlab API where the source project was not the same as the target project, such as the source project being a fork. This change retrieves the MR details from the Gitlab API and retrieves the source project ID for use during subsequent decoration calls, so the commit will be searched for in the correct project.
@mc1arke
Copy link
Owner

mc1arke commented Apr 1, 2021

Fixed in 1.7.0 of the plugin

@mc1arke mc1arke closed this as completed Apr 1, 2021
@chickenw1
Copy link

chickenw1 commented Aug 15, 2021

Hi, @mc1arke
My environment:
Sonarqube: 8.9 community
Branch plugin: 1.8.0
Gitlab: 13.12.9
2021.08.15 05:07:56 INFO ce[AXtINYF6yzuuarLrdq8S][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] Status url is: http://192.168.2.246:82/api/v4/projects/789/statuses/e2703dc1170792c1839015bd33407c18cd01ef71 2021.08.15 05:07:56 INFO ce[AXtINYF6yzuuarLrdq8S][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] PR commits url is: http://192.168.2.246:82/api/v4/projects/789/merge_requests/17/commits 2021.08.15 05:07:56 INFO ce[AXtINYF6yzuuarLrdq8S][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] MR discussion url is: http://192.168.2.246:82/api/v4/projects/789/merge_requests/17/discussions 2021.08.15 05:07:56 INFO ce[AXtINYF6yzuuarLrdq8S][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] User url is: http://192.168.2.246:82/api/v4/user 2021.08.15 05:07:56 INFO ce[AXtINYF6yzuuarLrdq8S][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] class com.github.mc1arke.sonarqube.plugin.ce.pullrequest.gitlab.response.User received 2021.08.15 05:07:56 INFO ce[AXtINYF6yzuuarLrdq8S][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] Using user: wangyouji 2021.08.15 05:07:56 INFO ce[AXtINYF6yzuuarLrdq8S][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] MR discussions received 2021.08.15 05:07:56 INFO ce[AXtINYF6yzuuarLrdq8S][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] MR discussions received 2021.08.15 05:07:56 INFO ce[AXtINYF6yzuuarLrdq8S][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] Discussions in MR: 911e5a42be12a9f216b79d63045a49e0d3ffeca9 2021.08.15 05:07:56 ERROR ce[AXtINYF6yzuuarLrdq8S][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] HttpResponseProxy{HTTP/1.1 404 Not Found [Server: nginx, Date: Sun, 15 Aug 2021 05:07:58 GMT, Content-Type: application/json, Content-Length: 34, Connection: keep-alive, Cache-Control: no-cache, Vary: Origin, X-Content-Type-Options: nosniff, X-Frame-Options: SAMEORIGIN, X-Gitlab-Feature-Category: continuous_integration, X-Request-Id: 01FD43B764EM2KQ1DZ3AGH9D6G, X-Runtime: 0.038094] ResponseEntityProxy{[Content-Type: application/json,Content-Length: 34,Chunked: false]}} 2021.08.15 05:07:56 ERROR ce[AXtINYF6yzuuarLrdq8S][c.g.m.s.p.c.p.g.GitlabServerPullRequestDecorator] {"message":"404 Commit Not Found"} 2021.08.15 05:07:56 ERROR ce[AXtINYF6yzuuarLrdq8S][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Execution of task class com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask failed java.lang.IllegalStateException: An error was returned in the response from the Gitlab API. See the previous log messages for details at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.gitlab.GitlabServerPullRequestDecorator.validateGitlabResponse(GitlabServerPullRequestDecorator.java:388) at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.gitlab.GitlabServerPullRequestDecorator.postStatus(GitlabServerPullRequestDecorator.java:379) at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.gitlab.GitlabServerPullRequestDecorator.decorateQualityGateStatus(GitlabServerPullRequestDecorator.java:178) at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask.finished(PullRequestPostAnalysisTask.java:160) at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.executeTask(PostProjectAnalysisTasksExecutor.java:118) at org.sonar.ce.task.projectanalysis.api.posttask.PostProjectAnalysisTasksExecutor.finished(PostProjectAnalysisTasksExecutor.java:109) at org.sonar.ce.task.step.ComputationStepExecutor.executeListener(ComputationStepExecutor.java:91) at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:63) at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:81) at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.executeTask(CeWorkerImpl.java:212) at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:194) at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:160) at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:135) at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:87) at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:53) at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:125) at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:69) at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:78) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.base/java.util.concurrent.FutureTask.run(Unknown Source) at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) 2021.08.15 05:07:56 INFO ce[AXtINYF6yzuuarLrdq8S][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Pull Request Decoration | status=FAILED | time=331ms
i use a jenkins do the pipeline job, and the merge request generate a new commit id, but this id not found in gitlab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants