Created
February 25, 2020 15:15
-
-
Save Mishkun/055e5b489b12b588f244bde04cf849a1 to your computer and use it in GitHub Desktop.
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
registerAction(id = "OptimizeImportsInBranchAction") { event: AnActionEvent -> | |
val project = project ?: run { | |
show("Project is null") | |
return@registerAction | |
} | |
val cmd = exec("git diff --name-only origin/dev .") | |
// val diffs = exec("git status") | |
if (cmd.first.isNotBlank()) { | |
show(cmd.first) | |
return@registerAction | |
} | |
val diffs = cmd.second.split('\n') | |
for (diff in diffs) { | |
val psiFiles = FilenameIndex.getFilesByName(project, diff, GlobalSearchScope.projectScope(project)) | |
for (psiFile in psiFiles) { | |
val optimizer = OptimizeImportsProcessor(project, psiFile) | |
optimizer.run() | |
} | |
} | |
show("Optimized imports in ${diffs.count()} files") | |
} | |
fun exec(command: String): Pair<String, String> = | |
Runtime.getRuntime().exec(command, null, File(project?.basePath)).run { | |
errorStream.bufferedReader().use { it.readText() }.trimEnd() to | |
inputStream.bufferedReader().use { it.readText() }.trimEnd() | |
} | |
if (!isIdeStartup) show("Loaded OptimizeImportsInBranchAction") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment