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

No token could be found with access #103

Closed
hnrkdmsk opened this issue Feb 25, 2020 · 15 comments
Closed

No token could be found with access #103

hnrkdmsk opened this issue Feb 25, 2020 · 15 comments
Labels
bug Something isn't working

Comments

@hnrkdmsk
Copy link

hnrkdmsk commented Feb 25, 2020

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

  • SonarQube Version: 7.9.1.27448
  • Plugin Version: 1.3.0

Additional context
Add any other context about the problem here.

@hnrkdmsk hnrkdmsk added the bug Something isn't working label Feb 25, 2020
@mc1arke
Copy link
Owner

mc1arke commented Feb 25, 2020

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

@hnrkdmsk
Copy link
Author

It's github.com.

@mc1arke
Copy link
Owner

mc1arke commented Feb 25, 2020

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
Copy link

ehats commented Feb 25, 2020

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
Copy link
Owner

mc1arke commented Feb 25, 2020

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
Copy link

ehats commented Feb 25, 2020

@mc1arke Sure thing!

@caarlos0
Copy link

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

mc1arke added a commit that referenced this issue Feb 26, 2020
When trying to find authentication tokens for accessing a repository, the list of repositories attached to a token are currently iterated over until one if found with a matching name, or the end of the retrieved list is reached. However, this search is not taking into account pagination in the response from Github, so any list of repositories that is greater than the default page size fails to find a matching authentication token if the repository is not present on the first page of the repository list. To resolve this, the response is checked for a `Link` header with a `rel="next"` element, with the link in this header being followed for each response until a matching repository is found, or the header is not present.
@mc1arke
Copy link
Owner

mc1arke commented Feb 26, 2020

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
Copy link
Author

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

@mirzacehajic
Copy link

👍 here.. works with latest fix

@mc1arke
Copy link
Owner

mc1arke commented Feb 27, 2020

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

@caarlos0
Copy link

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

@hnrkdmsk
Copy link
Author

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
Copy link

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

mc1arke added a commit that referenced this issue Apr 26, 2020
When trying to find authentication tokens for accessing a repository, the list of repositories attached to a token are currently iterated over until one if found with a matching name, or the end of the retrieved list is reached. However, this search is not taking into account pagination in the response from Github, so any list of repositories that is greater than the default page size fails to find a matching authentication token if the repository is not present on the first page of the repository list. To resolve this, the response is checked for a `Link` header with a `rel="next"` element, with the link in this header being followed for each response until a matching repository is found, or the header is not present.

Includes a drive-by-change to allow correct reporting of test coverage to SonarCloud.
mc1arke added a commit that referenced this issue Apr 26, 2020
When trying to find authentication tokens for accessing a repository, the list of repositories attached to a token are currently iterated over until one if found with a matching name, or the end of the retrieved list is reached. However, this search is not taking into account pagination in the response from Github, so any list of repositories that is greater than the default page size fails to find a matching authentication token if the repository is not present on the first page of the repository list. To resolve this, the response is checked for a `Link` header with a `rel="next"` element, with the link in this header being followed for each response until a matching repository is found, or the header is not present.

Includes a drive-by-change to allow correct reporting of test coverage to SonarCloud.
mc1arke added a commit that referenced this issue Apr 26, 2020
When trying to find authentication tokens for accessing a repository, the list of repositories attached to a token are currently iterated over until one if found with a matching name, or the end of the retrieved list is reached. However, this search is not taking into account pagination in the response from Github, so any list of repositories that is greater than the default page size fails to find a matching authentication token if the repository is not present on the first page of the repository list. To resolve this, the response is checked for a `Link` header with a `rel="next"` element, with the link in this header being followed for each response until a matching repository is found, or the header is not present.

Includes a drive-by-change to allow correct reporting of test coverage to SonarCloud.
mc1arke added a commit that referenced this issue Apr 26, 2020
When trying to find authentication tokens for accessing a repository, the list of repositories attached to a token are currently iterated over until one if found with a matching name, or the end of the retrieved list is reached. However, this search is not taking into account pagination in the response from Github, so any list of repositories that is greater than the default page size fails to find a matching authentication token if the repository is not present on the first page of the repository list. To resolve this, the response is checked for a `Link` header with a `rel="next"` element, with the link in this header being followed for each response until a matching repository is found, or the header is not present.

Includes a drive-by-change to allow correct reporting of test coverage to SonarCloud.
mc1arke added a commit that referenced this issue Apr 26, 2020
When trying to find authentication tokens for accessing a repository, the list of repositories attached to a token are currently iterated over until one is found with a matching name, or the end of the retrieved list is reached. However, this search is not taking into account pagination in the response from Github, so any list of repositories that is greater than the default page size fails to find a matching authentication token if the repository is not present on the first page of the repository list. To resolve this, the response is checked for a `Link` header with a `rel="next"` element, with the link in this header being followed for each response until a matching repository is found, or the header is not present.

Includes a drive-by-change to allow correct reporting of test coverage to SonarCloud.
mc1arke added a commit that referenced this issue Apr 26, 2020
When trying to find authentication tokens for accessing a repository, the list of repositories attached to a token are currently iterated over until one is found with a matching name, or the end of the retrieved list is reached. However, this search is not taking into account pagination in the response from Github, so any list of repositories that is greater than the default page size fails to find a matching authentication token if the repository is not present on the first page of the repository list. To resolve this, the response is checked for a `Link` header with a `rel="next"` element, with the link in this header being followed for each response until a matching repository is found, or the header is not present.

Includes a drive-by-change to allow correct reporting of test coverage to SonarCloud.
kennyko pushed a commit to kennyko/sonarqube-community-branch-plugin that referenced this issue Apr 29, 2020
@mc1arke
Copy link
Owner

mc1arke commented May 31, 2020

Released in version 1.3.1

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

5 participants