Skip to content

Commit

Permalink
feat: add explicit scan option
Browse files Browse the repository at this point in the history
- Add option to only scan when explicitly running the scan (turn of file
  listeners)
- Fix the auth check
  • Loading branch information
owenrumney committed Jul 10, 2024
1 parent 8712a3c commit 3c86e1c
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

## [Unreleased]

## [1.2.1] - 2024-07-10

### Fixed

- Check auth on download

### Added

- Skip scanning on file save as an option

## [1.2.0] - 2024-07-09

### Changed
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pluginGroup=io.infracost.plugins
pluginName=Infracost
pluginRepositoryUrl=https://github.com/infracost/jetbrains-infracost
pluginVersion=1.2.0
pluginVersion=1.2.1
pluginSinceBuild=232
pluginUntilBuild=242.*
platformType=IC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ internal class InfracostDownloadBinaryTask(private val project: Project, val ini
if (downloadBinary(project, binaryRelease, targetFile, initial)) {
InfracostSettingState.instance.infracostPath = targetFile.absolutePath
InfracostBinary.binaryFile = targetFile.absolutePath
if (initial) {
SwingUtilities.invokeLater {
CheckAuthAction.checkAuth(project)
}

SwingUtilities.invokeLater {
CheckAuthAction.checkAuth(project)
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intellij.openapi.project.ProjectLocator
import com.intellij.openapi.vfs.newvfs.BulkFileListener
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
import io.infracost.plugins.infracost.actions.RunInfracostAction
import io.infracost.plugins.infracost.settings.InfracostSettingState

val INFRACOST_FILE_EXTENSIONS = setOf("tf", "hcl", "tfvars")
val INFRACOST_FILES = setOf("infracost.yml", "infracost.yml.tmpl", "infracost-usage.yml")
Expand All @@ -14,6 +15,8 @@ class InfracostFileListener : BulkFileListener {
// at the moment it will be all files in the workspace that have been updated
// going forward we might want to check if the file is a terraform file explicitly
override fun after(events: MutableList<out VFileEvent>) {
if (InfracostSettingState.instance.onlyExplicitRun) return

for (event in events) {
if (event.isFromSave) {
if (event.file?.extension?.lowercase() in INFRACOST_FILE_EXTENSIONS ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil
)
class InfracostSettingState : PersistentStateComponent<InfracostSettingState?> {
var infracostPath: String = ""
var onlyExplicitRun: Boolean = false

override fun getState(): InfracostSettingState {
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.infracost.plugins.infracost.settings
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.ui.TextFieldWithBrowseButton
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.components.JBLabel
import com.intellij.util.ui.FormBuilder
import io.infracost.plugins.infracost.actions.DownloadInfracostAction
Expand All @@ -18,6 +19,8 @@ import javax.swing.SwingUtilities
class InfracostSettingsComponent {
val panel: JPanel
private val infracostPath = TextFieldWithBrowseButton()
private val updateButton = JButton("Update Bundled Infracost")
private val explicitInfracost = JBCheckBox("Don't run Infracost on save")

init {
infracostPath.addBrowseFolderListener(
Expand All @@ -27,8 +30,8 @@ class InfracostSettingsComponent {
FileChooserDescriptorFactory.createSingleFileDescriptor()
)

val button = JButton("Update Infracost")
button.addMouseListener(object : MouseAdapter() {
updateButton.toolTipText = "Update the bundled version of Infracost. This won't update any additional install you might have."
updateButton.addMouseListener(object : MouseAdapter() {
override fun mouseClicked(e: MouseEvent) {
SwingUtilities.invokeLater {
DownloadInfracostAction.runDownload(ProjectManager.getInstance().defaultProject, false)
Expand All @@ -40,7 +43,9 @@ class InfracostSettingsComponent {
FormBuilder.createFormBuilder()
.addLabeledComponent(JBLabel("Specific infracost path: "), infracostPath, 1, true)
.addVerticalGap(5)
.addComponent(button)
.addComponent(explicitInfracost, 1)
.addVerticalGap(5)
.addComponent(updateButton)
.addComponentFillVertically(JPanel(), 0)
.panel
}
Expand All @@ -56,4 +61,12 @@ class InfracostSettingsComponent {
infracostPath.text = newText
InfracostBinary.binaryFile = newText
}

fun getExplicitInfracost(): Boolean {
return explicitInfracost.isSelected
}

fun setExplicitInfracost(newVal: Boolean) {
explicitInfracost.isSelected = newVal
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ class InfracostSettingsConfigurable : Configurable {
override fun isModified(): Boolean {
val settings = InfracostSettingState.instance
val modified = infracostSettingsComponent!!.getInfracostPath() != settings.infracostPath
|| infracostSettingsComponent!!.getExplicitInfracost() != settings.onlyExplicitRun
return modified
}

override fun apply() {
val settings = InfracostSettingState.instance
settings.infracostPath = infracostSettingsComponent!!.getInfracostPath()
settings.onlyExplicitRun = infracostSettingsComponent!!.getExplicitInfracost()
}

override fun reset() {
val settings = InfracostSettingState.instance
infracostSettingsComponent!!.setInfracostPath(settings.infracostPath)
infracostSettingsComponent!!.setExplicitInfracost(settings.onlyExplicitRun)
}

override fun disposeUIResources() {
Expand Down

0 comments on commit 3c86e1c

Please sign in to comment.