Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Not able to analyze a PR from fork to main repo #45

Closed
PeterOsudio opened this issue May 4, 2017 · 3 comments
Closed

Not able to analyze a PR from fork to main repo #45

PeterOsudio opened this issue May 4, 2017 · 3 comments

Comments

@PeterOsudio
Copy link
Contributor

Expected Behavior

We are experiencing issues with bitbucket cloud integration when analyzing Pull Requests from a forked repo into the main repo. Is there any way to configure the accountName for the source and target independently?

I tried to include only the relevant info in the log. Let me know if any other info is needed to provide a solution.

Actual Behavior

Assume we have a main repo called upstream and a fork called origin.

Running the sonar-runner with account name origin and PR 7375 results in the following error.
> sonar-runner -Dsonar.bitbucket.accountName=origin -Dsonar.bitbucket.pullRequestId=7375 -Dsonar.analysis.mode=issues...

18:53:50.746 DEBUG - Post-jobs : Sonar Plug-in for Bitbucket Cloud (wrapped)
18:53:50.746 INFO  - Executing post-job Sonar Plug-in for Bitbucket Cloud (wrapped)
18:53:50.899 INFO  - [sonar4bitbucket] Pull request with id '7375' not found. No analysis will be performed.

This makes sense since the PR is listed in the upsteam repo.

Running the sonar-runner with account name upstream and PR 7375 results in the following error.
> sonar-runner -Dsonar.bitbucket.accountName=upstream -Dsonar.bitbucket.pullRequestId=7375 -Dsonar.analysis.mode=issues ...

18:56:04.369 DEBUG - Post-jobs : Sonar Plug-in for Bitbucket Cloud (wrapped)
18:56:04.369 INFO  - Executing post-job Sonar Plug-in for Bitbucket Cloud (wrapped)
18:56:04.652 INFO  - [sonar4bitbucket] Plug-in is active and will analyze pull request with #7375...
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
Total time: 47.238s
Final Memory: 31M/1139M
INFO: ------------------------------------------------------------------------
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: POST https://bitbucket.org/api/2.0/repositories/upstream/****/commit/fabac8a20182/statuses/build returned a response status of 404 Not Found
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with the -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.

This also makes sense since the commit of the PR is not yet merged into upstream. Is there any way to configure the accountName for the source and target independently?

Plug-in version, SonarQube version, CI system, build type

Sonarqube 5.6
Bitbucket for Sonar 1.2.0

@PeterOsudio
Copy link
Contributor Author

PeterOsudio commented May 4, 2017

Looking at the code it calls bitbucket to get the pullrequest details. I see that the source branch is also returned, so instead of composing the commit url it could be retrieved from the PR response.

https://api.bitbucket.org/2.0/repositories/upstream/****/pullrequests/7375

...
  "source": {
    "commit": {
      "hash": "fabac8a20182",
      "links": {
        "self": {
          "href": "https://api.bitbucket.org/2.0/repositories/origin/****/commit/fabac8a20182"
        }
      }
    },
...

full-json-response.txt

@PeterOsudio
Copy link
Contributor Author

Untested potential fix. Please review: #46

@mrueegg
Copy link
Contributor

mrueegg commented Jun 18, 2017

Will close this now as the pull request got merged. Thanks again for your help!

@mrueegg mrueegg closed this as completed Jun 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants