From 8601a30a18eb3761d7c56ca6e24df89f853c46fb Mon Sep 17 00:00:00 2001 From: Ivan Semenov Date: Wed, 21 Feb 2024 18:03:24 +0100 Subject: [PATCH] [github] load PR changes via paginated API instead of in a single patch file #IDEA-346666 Fixed GitOrigin-RevId: 4435f7fee833aaed430e40c46a7ba90efb1d97bc --- .../plugins/github/api/GithubApiRequests.kt | 16 +++++++--------- .../data/provider/GHPRChangesDataProviderImpl.kt | 2 +- .../data/service/GHPRChangesService.kt | 1 + .../data/service/GHPRChangesServiceImpl.kt | 13 ++++++------- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiRequests.kt b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiRequests.kt index f1bbc5aa0d7f..a82e4c379caf 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiRequests.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/api/GithubApiRequests.kt @@ -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(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> = + getDiffFiles(getUrl(repository, urlSuffix, "/${id.number}", "/files")) + + @JvmStatic + fun getDiffFiles(url: String): GithubApiRequest> = + Get.jsonPage(url).withOperationName("get files for pull request") object Reviewers : Entity("/requested_reviewers") { @JvmStatic diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/provider/GHPRChangesDataProviderImpl.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/provider/GHPRChangesDataProviderImpl.kt index bfcbb829b1ec..729f31f3e35f 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/provider/GHPRChangesDataProviderImpl.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/provider/GHPRChangesDataProviderImpl.kt @@ -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) } } } diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/service/GHPRChangesService.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/service/GHPRChangesService.kt index 946d4a483d51..2892884057e7 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/service/GHPRChangesService.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/service/GHPRChangesService.kt @@ -34,6 +34,7 @@ interface GHPRChangesService: Disposable { @CalledInAny fun createChangesProvider(progressIndicator: ProgressIndicator, + id: GHPRIdentifier, baseRef: String, mergeBaseRef: String, headRef: String, diff --git a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/service/GHPRChangesServiceImpl.kt b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/service/GHPRChangesServiceImpl.kt index 4c59d0f7c738..0d103c51f122 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/service/GHPRChangesServiceImpl.kt +++ b/plugins/github/src/org/jetbrains/plugins/github/pullrequest/data/service/GHPRChangesServiceImpl.kt @@ -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>): CompletableFuture { - - return progressManager.submitIOTask(ProgressWrapper.wrap(progressIndicator)) { - val prPatchesRequest = patchesCache.get(baseRef to headRef) - + commits: Pair>): CompletableFuture = + progressManager.submitIOTask(ProgressWrapper.wrap(progressIndicator)) { val (lastCommit, graph) = commits val commitsPatchesRequests = LinkedHashMap>>() 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()