generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(git-provider): implement lookupGitData and ShireVcsCommit updates …
…#41 - Add implementation for retrieving git commit data in GitQLDataProvider. - Update ShireVcsCommit data class to include hash, authorDate, and committerDate fields. - Utilize IntelliJ's progress API to fetch commit history asynchronously.
- Loading branch information
Showing
2 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 79 additions & 1 deletion
80
toolsets/git/src/main/kotlin/com/phodal/shirelang/git/provider/GitQLDataProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,89 @@ | ||
package com.phodal.shirelang.git.provider | ||
|
||
import com.intellij.ide.DataManager | ||
import com.intellij.openapi.progress.ProgressIndicator | ||
import com.intellij.openapi.progress.ProgressManager | ||
import com.intellij.openapi.progress.Task | ||
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator | ||
import com.intellij.openapi.progress.runBlockingCancellable | ||
import com.intellij.openapi.project.Project | ||
import com.phodal.shirecore.ShireCoreBundle | ||
import com.phodal.shirecore.provider.shire.ShireQLDataProvider | ||
import com.phodal.shirecore.provider.shire.ShireQLDataType | ||
import com.phodal.shirecore.vcs.ShireVcsCommit | ||
import git4idea.GitCommit | ||
import git4idea.history.GitHistoryUtils | ||
import git4idea.repo.GitRepositoryManager | ||
import kotlinx.coroutines.future.await | ||
import java.util.concurrent.CompletableFuture | ||
|
||
class GitQLDataProvider : ShireQLDataProvider { | ||
override fun lookupGitData(myProject: Project, dataTypes: List<ShireQLDataType>): Map<ShireQLDataType, Any?> { | ||
TODO("Not yet implemented") | ||
val result = mutableMapOf<ShireQLDataType, Any?>() | ||
val dataContext = DataManager.getInstance().getDataContextFromFocus().result | ||
Check notice on line 23 in toolsets/git/src/main/kotlin/com/phodal/shirelang/git/provider/GitQLDataProvider.kt
|
||
|
||
dataTypes.forEach { | ||
when (it) { | ||
ShireQLDataType.GIT_COMMIT -> { | ||
val commits = buildCommits(myProject) | ||
result[it] = commits | ||
} | ||
ShireQLDataType.GIT_BRANCH -> TODO() | ||
ShireQLDataType.GIT_FILE_COMMIT -> TODO() | ||
ShireQLDataType.GIT_FILE_BRANCH -> TODO() | ||
else -> { | ||
result[it] = null | ||
} | ||
} | ||
} | ||
|
||
return result | ||
} | ||
|
||
private fun buildCommits(myProject: Project): List<ShireVcsCommit> { | ||
val repository = GitRepositoryManager.getInstance(myProject).repositories.firstOrNull() ?: return emptyList() | ||
val branchName = repository.currentBranchName | ||
|
||
/** | ||
* Refs to [com.intellij.execution.process.OSProcessHandler.checkEdtAndReadAction], we should handle in this | ||
* way, another example can see in [git4idea.GitPushUtil.findOrPushRemoteBranch] | ||
*/ | ||
val future = CompletableFuture<List<GitCommit>>() | ||
val task = object : Task.Backgroundable(myProject, ShireCoreBundle.message("shire.ref.loading"), false) { | ||
override fun run(indicator: ProgressIndicator) { | ||
val commits: List<GitCommit> = try { | ||
// in some case, maybe not repo or branch, so we should handle it | ||
GitHistoryUtils.history(project, repository.root, branchName) | ||
} catch (e: Exception) { | ||
emptyList() | ||
} | ||
|
||
future.complete(commits) | ||
} | ||
} | ||
|
||
ProgressManager.getInstance() | ||
.runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task)) | ||
|
||
val results: MutableList<ShireVcsCommit> = mutableListOf() | ||
runBlockingCancellable { | ||
Check warning on line 69 in toolsets/git/src/main/kotlin/com/phodal/shirelang/git/provider/GitQLDataProvider.kt
|
||
future.await().forEach { | ||
val commit = ShireVcsCommit( | ||
it.id.asString(), | ||
it.author.name, | ||
it.author.email, | ||
it.authorTime, | ||
it.committer.name, | ||
it.committer.email, | ||
it.commitTime, | ||
it.fullMessage, | ||
it.fullMessage, | ||
) | ||
|
||
results.add(commit) | ||
} | ||
} | ||
|
||
return results.toList() | ||
} | ||
} |