{"record":{"id":"efa385f671df9cf8","repo":"SonarSource/sonarqube","slug":"failed-to-get-repository-s-on-s-this-might","errorCode":null,"errorMessage":"Failed to get repository '%s' on '%s' (this might be related to the GitHub App installation scope)","messagePattern":"Failed to get repository '(.+?)' on '(.+?)' \\(this might be related to the GitHub App installation scope\\)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationClientImpl.java","lineNumber":367,"sourceCode":"\n      return repositories;\n    } catch (Exception e) {\n      throw new IllegalStateException(format(\"Failed to list all repositories of '%s' accessible by user access token on '%s' using query '%s'\", organization, appUrl, searchQuery),\n        e);\n    }\n  }\n\n  @Override\n  public Optional<Repository> getRepository(String appUrl, AccessToken accessToken, String organizationAndRepository) {\n    try {\n      GetResponse response = githubApplicationHttpClient.get(appUrl, accessToken, String.format(\"/repos/%s\", organizationAndRepository));\n      return Optional.of(response)\n        .filter(r -> r.getCode() == HTTP_OK)\n        .flatMap(ApplicationHttpClient.Response::getContent)\n        .map(content -> GSON.fromJson(content, GsonGithubRepository.class))\n        .map(GsonGithubRepository::toRepository);\n    } catch (Exception e) {\n      throw new IllegalStateException(format(\"Failed to get repository '%s' on '%s' (this might be related to the GitHub App installation scope)\",\n        organizationAndRepository, appUrl), e);\n    }\n  }\n\n  @Override\n  public UserAccessToken createUserAccessToken(String appUrl, String clientId, String clientSecret, String code) {\n    try {\n      String endpoint = \"/login/oauth/access_token?client_id=\" + clientId + \"&client_secret=\" + clientSecret + \"&code=\" + code;\n\n      String baseAppUrl = convertApiUrlToBaseUrl(appUrl);\n\n      ApplicationHttpClient.Response response = githubApplicationHttpClient.post(baseAppUrl, null, endpoint);\n\n      if (response.getCode() != HTTP_OK) {\n        if (LOG.isDebugEnabled()) {\n          LOG.debug(\"Failed to create GitHub's user access token, response body: {}\", response.getContent().orElse(\"\"));\n        }\n        throw new IllegalStateException(\"Failed to create GitHub's user access token. GitHub returned code \" + response.getCode() + \".\");","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationClientImpl.java#L349-L385","documentation":"getRepository fetches a single repository by 'org/repo' identifier. Any exception during the call is wrapped in this IllegalStateException, which explicitly hints that the GitHub App installation scope may not include the repository. It commonly appears when the App is installed but not granted access to the requested repo.","triggerScenarios":"Calling getRepository(appUrl, accessToken, organizationAndRepository) when the HTTP call or JSON parsing throws — or when the App installation restricts repository access so the repo endpoint behaves unexpectedly.","commonSituations":"GitHub App installed with 'Only select repositories' excluding the target repo; repository renamed/deleted; wrong org/repo path; token lacking repo scope.","solutions":["In GitHub App settings, change Repository access to 'All repositories' or add the target repository to the selection.","Verify the organizationAndRepository string matches the current 'org/repo' path (repo not renamed).","Check the token/app permissions include repository metadata (read).","Confirm the repository still exists and is not archived/private to a different org."],"exampleFix":"// GitHub App settings: Repository access\n// before: Only select repositories -> [other-repo]\n// after: All repositories (or add 'my-org/my-repo' to the selection)","handlingStrategy":"validation","validationCode":"// check repo path shape before calling\nif (organizationAndRepository == null || !organizationAndRepository.matches(\"[\\w.-]+/[\\w.-]+\")) throw new IllegalArgumentException(\"Expected 'org/repo', got: \" + organizationAndRepository);","typeGuard":null,"tryCatchPattern":"try { return client.getRepository(url, token, orgRepo); } catch (IllegalStateException e) { log.warn(\"Repo {} not accessible; check GitHub App installation scope\", orgRepo); return Optional.empty(); }","preventionTips":["Install the GitHub App with 'All repositories' when auto-provisioning","Re-check installation scope after repos are added","Detect repo renames via webhooks and update bindings","Verify the org/repo path exists before linking a project"],"tags":["github","http","permissions","alm-binding"],"backgroundTag":"resource-not-found","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}