Skip to content

Commit

Permalink
Set URL & token in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nquinquenel committed Jun 14, 2024
1 parent f970cb6 commit 75ffdde
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
sonarlint-core = "10.2.0.78280"
sonarlint-core = "10.2.0.78285"

sonar-java = "7.34.0.35958"
sonar-javascript = "10.14.0.26080"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class SonarLintGlobalOptionsPanel implements ConfigurationPanel<SonarLint
private JPanel rootPane;
private JBCheckBox autoTrigger;
private JBTextField nodeJsPath;
private JBTextField gripUrl;
private JBTextField gripAuthToken;
private JBLabel nodeJsVersion;

@Override
Expand Down Expand Up @@ -83,14 +85,31 @@ private JPanel createTopPanel() {
optionsPanel.add(nodeJsVersion, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0,
WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));

var gripLabel = new JLabel("GRIP Service URL: ");
optionsPanel.add(gripLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));

gripUrl = new JBTextField();
optionsPanel.add(gripUrl, new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0,
WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));

var gripTokenLabel = new JLabel("GRIP Auth Token: ");
optionsPanel.add(gripTokenLabel, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));

gripAuthToken = new JBTextField();
optionsPanel.add(gripAuthToken, new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0,
WEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0));

return optionsPanel;
}

@Override
public boolean isModified(SonarLintGlobalSettings model) {
getComponent();
return model.isAutoTrigger() != autoTrigger.isSelected()
|| !Objects.equals(model.getNodejsPath(), nodeJsPath.getText());
|| !Objects.equals(model.getNodejsPath(), nodeJsPath.getText()) || !Objects.equals(model.getGripUrl(), gripUrl.getText())
|| !Objects.equals(model.getGripAuthToken(), gripAuthToken.getText());
}

@Override
Expand All @@ -99,6 +118,8 @@ public void load(SonarLintGlobalSettings model) {
autoTrigger.setSelected(model.isAutoTrigger());
nodeJsPath.setText(model.getNodejsPath());
loadNodeJsSettings();
this.gripUrl.setText(model.getGripUrl());
this.gripAuthToken.setText(model.getGripAuthToken());
}

private void loadNodeJsSettings() {
Expand All @@ -118,6 +139,7 @@ public void save(SonarLintGlobalSettings settings) {
getComponent();
settings.setAutoTrigger(autoTrigger.isSelected());
settings.setNodejsPath(nodeJsPath.getText());
settings.setGripUrl(gripUrl.getText());
settings.setGripAuthToken(gripAuthToken.getText());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public final class SonarLintGlobalSettings {

private boolean autoTrigger = true;
private String nodejsPath = "";
private String gripUrl = "https://beta.sonar-grip-dev.io/";
private String gripAuthToken = "";

private List<ServerConnection> servers = new LinkedList<>();
private List<String> fileExclusions = new LinkedList<>();
Expand Down Expand Up @@ -184,6 +186,22 @@ public void setNodejsPath(String nodejsPath) {
this.nodejsPath = nodejsPath;
}

public String getGripUrl() {
return gripUrl;
}

public void setGripUrl(String gripUrl) {
this.gripUrl = gripUrl;
}

public String getGripAuthToken() {
return gripAuthToken;
}

public void setGripAuthToken(String gripAuthToken) {
this.gripAuthToken = gripAuthToken;
}

// Don't change annotation, used for backward compatibility
@OptionTag("sonarQubeServers")
public List<ServerConnection> getServerConnections() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/sonarlint/intellij/core/BackendService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ class BackendService : Disposable {
}

fun suggestFix(
serviceUri: URI,
authenticationToken: String,
module: Module,
fileUri: URI,
Expand All @@ -1127,6 +1128,7 @@ class BackendService : Disposable {
return requestFromBackend {
it.gripService.suggestFix(
SuggestFixParams(
serviceUri,
authenticationToken,
configScopeId,
fileUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiManager
import java.net.URI
import java.util.UUID
import org.sonarlint.intellij.actions.AbstractSonarAction
import org.sonarlint.intellij.actions.SonarLintToolWindow
import org.sonarlint.intellij.common.ui.ReadActionUtils
import org.sonarlint.intellij.common.ui.SonarLintConsole
import org.sonarlint.intellij.common.util.SonarLintUtils.getService
import org.sonarlint.intellij.config.Settings.getGlobalSettings
import org.sonarlint.intellij.core.BackendService
import org.sonarlint.intellij.finding.TextRangeMatcher
import org.sonarlint.intellij.ui.UiUtils.Companion.runOnUiThread
Expand Down Expand Up @@ -82,10 +84,17 @@ class SuggestAiFixAction(
file: VirtualFile,
issueId: UUID,
) {
val serviceUri = URI(getGlobalSettings().gripUrl)
val serviceAuthToken = getGlobalSettings().gripAuthToken
if (serviceAuthToken.isNullOrEmpty()) {
SonarLintConsole.get(project).error("No GRIP auth token configured")
return
}
ProgressManager.getInstance().run(object : Task.Backgroundable(project, "Suggesting a fix", false) {
override fun run(indicator: ProgressIndicator) {
val task = getService(project, BackendService::class.java).suggestFix(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJvbGl2aWVyLnNjaG1pdHQiLCJpc3MiOiJxdWlja2ZpeCIsImlhdCI6MTcxODAwMDQxNiwib3JnIjoic29uYXJzb3VyY2UiLCJleHAiOjE3MjA1OTI0MTZ9._6Egw3WprwnLvbKWYi8ZrsPLd1AIuyT4_rXtCN6jmIk",
serviceUri,
serviceAuthToken,
module,
VirtualFileUtils.toURI(file)!!,
issueMessage,
Expand Down

0 comments on commit 75ffdde

Please sign in to comment.