Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Apr 17, 2024
1 parent 65ee781 commit 2d64ed2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/main/kotlin/com/dsoftware/ghmanager/psi/HighlightAnnotator.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.dsoftware.ghmanager.psi

import com.dsoftware.ghmanager.psi.GitHubWorkflowConfig.FIELD_USES
import com.dsoftware.ghmanager.psi.actions.UpdateActionVersionFix
import com.intellij.codeInspection.InspectionManager
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.Annotator
import com.intellij.lang.annotation.HighlightSeverity
Expand All @@ -26,16 +29,26 @@ class HighlightAnnotator : Annotator {
val currentVersion = yamlKeyValue.valueText.split("@").getOrNull(1)
val latestVersion = gitHubActionCache.getAction(actionName)?.latestVersion
if (VersionCompareTools.isActionOutdated(currentVersion, latestVersion)) {
holder.newAnnotation(
HighlightSeverity.WARNING,
"$currentVersion is outdated. Latest version is $latestVersion"
).range(
TextRange.create(
yamlKeyValue.textRange.startOffset
+ yamlKeyValue.text.indexOf("@") + 1,
yamlKeyValue.textRange.endOffset
val message = "$currentVersion is outdated. Latest version is $latestVersion"
val annotationBuilder = holder
.newAnnotation(HighlightSeverity.WARNING, message)
.range(
TextRange.create(
yamlKeyValue.textRange.startOffset
+ yamlKeyValue.text.indexOf("@") + 1,
yamlKeyValue.textRange.endOffset
)
)
).create()
val inspectionManager = yamlKeyValue.project.service<InspectionManager>()
val quickfix = UpdateActionVersionFix(actionName, latestVersion!!)
val problemDescriptor = inspectionManager.createProblemDescriptor(
yamlKeyValue, message, quickfix,
ProblemHighlightType.WEAK_WARNING, true
);
annotationBuilder
.newLocalQuickFix(quickfix, problemDescriptor)
.registerFix()
annotationBuilder.create()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.dsoftware.ghmanager.psi.actions

import com.dsoftware.ghmanager.i18n.MessagesBundle.message
import com.intellij.codeInspection.LocalQuickFix
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import org.jetbrains.yaml.YAMLElementGenerator
import org.jetbrains.yaml.psi.YAMLKeyValue

class UpdateActionVersionFix(
private val actionName: String, fullLatestVersion: String,
) : LocalQuickFix {
private val latestVersion = fullLatestVersion.split(".").first()

override fun getFamilyName(): String {
return message("ghmanager.update.action.version.fix.family.name", actionName, latestVersion)
}


override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
val yamlKeyValue = descriptor.psiElement as YAMLKeyValue
val actionName = yamlKeyValue.valueText.split("@").firstOrNull() ?: return
val yamlElementGenerator = yamlKeyValue.project.service<YAMLElementGenerator>()
val newYamlKeyValue =
yamlElementGenerator.createYamlKeyValue(yamlKeyValue.keyText, "$actionName@$latestVersion")
yamlKeyValue.setValue(newYamlKeyValue.value!!)
}

}
1 change: 1 addition & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ action.name.refresh-workflow-runs=Refresh Workflow Runs
action.name.show-settings=Open GHActions-Manager Settings
action.name.open-in-browser=Open GitHub Link in Browser
action-group.name.select-workflow=Select Workflow to Execute
ghmanager.update.action.version.fix.family.name=Update {0} action to version {1}

0 comments on commit 2d64ed2

Please sign in to comment.