fun doRun()

in src/main/kotlin/org/jetbrains/teamcity/github/action/GetPullRequestDetailsAction.kt [24:47]


    fun doRun(info: GitHubRepositoryInfo, client: GitHubClientEx, context: ActionContext, number: Int): PullRequestEx {
        val service = PullRequestServiceEx(client)
        val repo = info.getRepositoryId()
        try {
            LOG.debug("Loading pull request #$number data for repository ${info.id}")
            return service.getPullRequestEx(repo, number)
        } catch (e: RequestException) {
            LOG.warnAndDebugDetails("Failed loading pull request #$number data for repository ${info.id}: ${e.status}", e)
            context.handleCommonErrors(e)
            when (e.status) {
                HTTP_NOT_FOUND, HTTP_FORBIDDEN -> {
                    // No access
                    // Probably token does not have permissions
                    val scopes = client.tokenOAuthScopes?.map { it.lowercase() } ?: throw GitHubAccessException(GitHubAccessException.Type.NoAccess) // Weird. No header?
                    when (TokensHelper.getHooksAccessType(scopes).first) {
                        TokensHelper.HookAccessType.NO_ACCESS -> throw GitHubAccessException(GitHubAccessException.Type.TokenScopeMismatch)
                        TokensHelper.HookAccessType.READ -> throw GitHubAccessException(GitHubAccessException.Type.TokenScopeMismatch)
                        TokensHelper.HookAccessType.WRITE, TokensHelper.HookAccessType.ADMIN -> throw GitHubAccessException(GitHubAccessException.Type.UserHaveNoAccess)
                    }
                }
            }
            throw e
        }
    }