mc1arke / sonarqube-community-branch-plugin

A plugin that allows branch analysis and pull request decoration in the Community version of Sonarqube
GNU Lesser General Public License v3.0
2.22k stars 521 forks source link

No token could be found with access #103

Closed hnrkdmsk closed 4 years ago

hnrkdmsk commented 4 years ago

Describe the bug I got the following exception if I have configured my app to have access to all my repositories and also new created ones. If I configure it to have access only to specific ones, no error occurs.

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: java.lang.IllegalStateException: No token could be found with access to the requested repository with the given application ID and key
    at com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.v3.RestApplicationAuthenticationProvider.getInstallationToken(RestApplicationAuthenticationProvider.java:130)
    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

My organization has 60+ repositories.

To Reproduce Configure your GitHub Application to have access to all repositories and new created ones.

Expected behavior That the error not occurs.

Screenshots

Software Versions

Additional context Add any other context about the problem here.

mc1arke commented 4 years ago

Can you confirm if this is github.com, or Github server and - if it's server - what the version number is please?

hnrkdmsk commented 4 years ago

It's github.com.

mc1arke commented 4 years ago

I suspect https://developer.github.com/v3/#pagination is causing issues. All my tests cases have been against organisations/users with a low number of repositories which is why I wouldn't have seen this. The code isn't checking for the rel link for retrieving paginated data, so will be treating the first page as the full list of repositories and therefore ignoring any repository listed on subsequent pages.

The only work-around I can see for now is specifying a small list of repositories that the application is allowed to access as per your current approach.

ehats commented 4 years ago

This is also an issue for our case, where we have ~600 repos in our org, and we'd like to scan all of them :)

mc1arke commented 4 years ago

Are either of you able to install a snapshot build to test with if I manage to create an appropriate fix? I could try and create lots of repositories just for testing, but a real-world test would be preferable.

ehats commented 4 years ago

@mc1arke Sure thing!

caarlos0 commented 4 years ago

I'm having the same issue I think, happy to help testing as well.

mc1arke commented 4 years ago

I've pushed a proposed fix to issue/103. Could one of you build and install from that branch and see if it allow for your repository to be found when allowing access to all your repositories in the application configuration?

hnrkdmsk commented 4 years ago

I have tested it and now it works fine in my case!

mirzacehajic commented 4 years ago

:+1: here.. works with latest fix

mc1arke commented 4 years ago

Thanks for testing. I'll get an MR containing that change raised and merged later today if possible.

caarlos0 commented 4 years ago

Hey, sorry to bother... but... any news on this? Anything I can do to help?

hnrkdmsk commented 4 years ago

Hey, sorry to bother... but... any news on this? Anything I can do to help?

You can checkout the https://github.com/mc1arke/sonarqube-community-branch-plugin/tree/issue/103 and build it locally. With this fix it works fine!

caarlos0 commented 4 years ago

If anyone else needs it, built: https://jars.caarlos0.dev/sonarqube-community-branch-plugin-1.3.1-SNAPSHOT.jar

mc1arke commented 4 years ago

Released in version 1.3.1