[github] load PR changes via paginated API instead of in a single patch file

#IDEA-346666 Fixed

GitOrigin-RevId: 4435f7fee833aaed430e40c46a7ba90efb1d97bc
This commit is contained in:
Ivan Semenov
2024-02-21 18:03:24 +01:00
committed by intellij-monorepo-bot
parent b2cd9f7f00
commit 8601a30a18
4 changed files with 15 additions and 17 deletions

View File

@@ -13,6 +13,7 @@ import org.jetbrains.plugins.github.api.data.request.*
import org.jetbrains.plugins.github.api.util.GithubApiPagesLoader
import org.jetbrains.plugins.github.api.util.GithubApiSearchQueryBuilder
import org.jetbrains.plugins.github.api.util.GithubApiUrlQueryBuilder
import org.jetbrains.plugins.github.pullrequest.data.GHPRIdentifier
import org.jetbrains.plugins.github.pullrequest.data.GHPRSearchQuery
import java.awt.image.BufferedImage
@@ -415,15 +416,12 @@ object GithubApiRequests {
}.withOperationName("get pull request list ETag")
@JvmStatic
fun getDiff(repository: GHRepositoryCoordinates, number: Long) =
object : Get<String>(getUrl(repository, urlSuffix, "/$number"),
GithubApiContentHelper.V3_DIFF_JSON_MIME_TYPE) {
override fun extractResult(response: GithubApiResponse): String {
return response.handleBody(ThrowableConvertor {
it.reader().use { it.readText() }
})
}
}.withOperationName("get diff of a PR")
fun getDiffFiles(repository: GHRepositoryCoordinates, id: GHPRIdentifier): GithubApiRequest<GithubResponsePage<GHCommitFile>> =
getDiffFiles(getUrl(repository, urlSuffix, "/${id.number}", "/files"))
@JvmStatic
fun getDiffFiles(url: String): GithubApiRequest<GithubResponsePage<GHCommitFile>> =
Get.jsonPage<GHCommitFile>(url).withOperationName("get files for pull request")
object Reviewers : Entity("/requested_reviewers") {
@JvmStatic

View File

@@ -73,7 +73,7 @@ class GHPRChangesDataProviderImpl(parentCs: CoroutineScope,
changesService.loadMergeBaseOid(indicator, it.baseRefOid, it.headRefOid).thenCombine(commitsRequest) { mergeBaseRef, commits ->
mergeBaseRef to commits
}.thenCompose { (mergeBaseRef, commits) ->
changesService.createChangesProvider(indicator, it.baseRefOid, mergeBaseRef, it.headRefOid, commits)
changesService.createChangesProvider(indicator, pullRequestId, it.baseRefOid, mergeBaseRef, it.headRefOid, commits)
}
}
}

View File

@@ -34,6 +34,7 @@ interface GHPRChangesService: Disposable {
@CalledInAny
fun createChangesProvider(progressIndicator: ProgressIndicator,
id: GHPRIdentifier,
baseRef: String,
mergeBaseRef: String,
headRef: String,

View File

@@ -31,6 +31,7 @@ import org.jetbrains.plugins.github.api.GHGQLRequests
import org.jetbrains.plugins.github.api.GHRepositoryCoordinates
import org.jetbrains.plugins.github.api.GithubApiRequestExecutor
import org.jetbrains.plugins.github.api.GithubApiRequests.Repos.Commits
import org.jetbrains.plugins.github.api.GithubApiRequests.Repos.PullRequests
import org.jetbrains.plugins.github.api.data.GHCommit
import org.jetbrains.plugins.github.api.data.GHCommitHash
import org.jetbrains.plugins.github.api.data.commit.GHCommitFile
@@ -104,14 +105,12 @@ class GHPRChangesServiceImpl(private val progressManager: ProgressManager,
patchesCache.get(ref1 to ref2)
override fun createChangesProvider(progressIndicator: ProgressIndicator,
id: GHPRIdentifier,
baseRef: String,
mergeBaseRef: String,
headRef: String,
commits: Pair<GHCommit, Graph<GHCommit>>): CompletableFuture<GitBranchComparisonResult> {
return progressManager.submitIOTask(ProgressWrapper.wrap(progressIndicator)) {
val prPatchesRequest = patchesCache.get(baseRef to headRef)
commits: Pair<GHCommit, Graph<GHCommit>>): CompletableFuture<GitBranchComparisonResult> =
progressManager.submitIOTask(ProgressWrapper.wrap(progressIndicator)) {
val (lastCommit, graph) = commits
val commitsPatchesRequests = LinkedHashMap<GHCommit, CompletableFuture<List<FilePatch>>>()
for (commit in Traverser.forGraph(graph).depthFirstPostOrder(lastCommit)) {
@@ -122,12 +121,12 @@ class GHPRChangesServiceImpl(private val progressManager: ProgressManager,
val patches = request.joinCancellable()
GitCommitShaWithPatches(commit.oid, commit.parents.map { it.oid }, patches)
}
val prPatches = prPatchesRequest.joinCancellable()
val request = GithubApiPagesLoader.Request(PullRequests.getDiffFiles(ghRepository, id), PullRequests::getDiffFiles)
val prPatches = GithubApiPagesLoader.loadAll(requestExecutor, it, request).mapNotNull(::toPatch)
it.checkCanceled()
GitBranchComparisonResult.create(project, gitRemote.repository.root, baseRef, mergeBaseRef, commitsList, prPatches)
}.logError(LOG, "Error occurred while building changes from commits")
}
companion object {
private val LOG = logger<GHPRChangesService>()