Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add explicit scan option #13

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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