Skip to content

Commit

Permalink
SLCORE-968 add client method to check if branches match
Browse files Browse the repository at this point in the history
  • Loading branch information
sophio-japharidze-sonarsource committed Oct 7, 2024
1 parent 074e1ae commit 756d3f1
Show file tree
Hide file tree
Showing 40 changed files with 163 additions and 48 deletions.
6 changes: 6 additions & 0 deletions API_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 10.7.1

## Breaking changes

* Add a new method to `org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcClient#matchProjectBranch` allowing the backend to check whether the locally checked-out branch matches a requesting server branch

# 10.7

## Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion backend/analysis-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-analysis-engine</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend/cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-backend-cli</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend/commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-commons</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ private String matchSonarProjectBranch(String configurationScopeId, SonarLintCan
return matchedSonarBranch;
}

@CheckForNull
public String getMatchedSonarProjectBranch(String configurationScopeId) {
return cachedMatchingBranchByConfigScope.get(configurationScopeId);
}

@CheckForNull
private String requestClientToMatchSonarProjectBranch(String configurationScopeId, String mainSonarBranchName, Set<String> allSonarBranchesNames,
SonarLintCancelMonitor cancelMonitor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.sonarsource.sonarlint.core.file.PathTranslationService;
import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcClient;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.InitializeParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.branch.MatchProjectBranchParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.connection.AssistCreatingConnectionParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.connection.SonarCloudConnectionParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.connection.SonarQubeConnectionParams;
Expand Down Expand Up @@ -112,10 +113,10 @@ public void handle(ClassicHttpRequest request, ClassicHttpResponse response, Htt
showFixSuggestionQuery.projectKey,
(connectionId, configScopeId, cancelMonitor) -> {
if (configScopeId != null) {
var matchingBranch = branchTrackingService.getMatchedSonarProjectBranch(configScopeId);
if (matchingBranch != null && !matchingBranch.equals(showFixSuggestionQuery.branch)) {
var localBranchMatchesRequesting = client.matchProjectBranch(new MatchProjectBranchParams(configScopeId, showFixSuggestionQuery.branch)).join().isBranchMatched();
if (!localBranchMatchesRequesting) {
client.showMessage(new ShowMessageParams(MessageType.ERROR, "Attempted to show a fix suggestion for a different branch than the one currently checked out." +
"\nPlease check out the correct branch and try again."));
"\nPlease make sure the correct branch is checked out and try again."));
return;
}
showFixSuggestionForScope(configScopeId, showFixSuggestionQuery.issueKey, showFixSuggestionQuery.fixSuggestion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
Expand All @@ -49,6 +50,7 @@
import org.sonarsource.sonarlint.core.rpc.protocol.SonarLintRpcClient;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.FeatureFlagsDto;
import org.sonarsource.sonarlint.core.rpc.protocol.backend.initialize.InitializeParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.branch.MatchProjectBranchResponse;
import org.sonarsource.sonarlint.core.rpc.protocol.client.message.MessageType;
import org.sonarsource.sonarlint.core.rpc.protocol.client.message.ShowMessageParams;
import org.sonarsource.sonarlint.core.telemetry.TelemetryService;
Expand Down Expand Up @@ -247,16 +249,16 @@ void should_cancel_flow_when_branch_does_not_match() throws HttpException, IOExc
when(connectionConfigurationRepository.findByOrganization(any())).thenReturn(List.of(
new SonarCloudConnectionConfiguration(PRODUCTION_URI, "name", "organizationKey", false)));
when(configurationRepository.getBoundScopesToConnectionAndSonarProject(any(), any())).thenReturn(List.of(new BoundScope("configScope", "connectionId", "projectKey")));
when(sonarProjectBranchTrackingService.getMatchedSonarProjectBranch(any())).thenReturn("branch");
when(sonarProjectBranchTrackingService.getMatchedSonarProjectBranch(any())).thenReturn("anotherBranch");
when(sonarLintRpcClient.matchProjectBranch(any())).thenReturn(CompletableFuture.completedFuture(new MatchProjectBranchResponse(false)));

showFixSuggestionRequestHandler.handle(request, response, context);
var showMessageArgumentCaptor = ArgumentCaptor.forClass(ShowMessageParams.class);

await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> verify(sonarLintRpcClient).showMessage(showMessageArgumentCaptor.capture()));
assertThat(showMessageArgumentCaptor.getValue().getType()).isEqualTo(MessageType.ERROR);
assertThat(showMessageArgumentCaptor.getValue().getText()).isEqualTo("Attempted to show a fix suggestion for a different branch than the one currently checked out." +
"\nPlease check out the correct branch and try again.");
assertThat(showMessageArgumentCaptor.getValue().getText()).isEqualTo("Attempted to show a fix suggestion for a different branch than the one currently checked out.\n" +
"Please make sure the correct branch is checked out and try again.");
verify(sonarLintRpcClient).matchProjectBranch(any());
verifyNoMoreInteractions(sonarLintRpcClient);
}

Expand Down
2 changes: 1 addition & 1 deletion backend/http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-http</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend/plugin-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-plugin-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend/plugin-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-plugin-commons</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend/rpc-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-rpc-impl</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend/rule-extractor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-rule-extractor</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend/server-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-server-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend/server-connection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-server-connection</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend/slf4j-sonar-log/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-slf4j-sonar-log</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion backend/telemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-telemetry</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/maven-shade-ext-bnd-transformer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>maven-shade-ext-bnd-transformer</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client/java-client-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-java-client-dependencies</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client/java-client-legacy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-java-client-legacy</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client/java-client-osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-java-client-osgi</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client/java-client-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-java-client-utils</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion client/rpc-java-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>sonarlint-rpc-java-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ default void showFixSuggestion(String configurationScopeId, String issueKey, Fix
String matchSonarProjectBranch(String configurationScopeId, String mainBranchName, Set<String> allBranchesNames,
SonarLintCancelChecker cancelChecker) throws ConfigScopeNotFoundException;

boolean matchProjectBranch(String configurationScopeId, String branchNameToMatch, SonarLintCancelChecker cancelChecker) throws ConfigScopeNotFoundException;

void didChangeMatchedSonarProjectBranch(String configScopeId, String newMatchedBranchName);

TelemetryClientLiveAttributesResponse getTelemetryLiveAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.DidChangeAnalysisReadinessParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.DidDetectSecretParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.DidRaiseIssueParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.GetInferredAnalysisPropertiesParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.GetInferredAnalysisPropertiesResponse;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.GetFileExclusionsParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.GetFileExclusionsResponse;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.GetInferredAnalysisPropertiesParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.analysis.GetInferredAnalysisPropertiesResponse;
import org.sonarsource.sonarlint.core.rpc.protocol.client.binding.AssistBindingParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.binding.AssistBindingResponse;
import org.sonarsource.sonarlint.core.rpc.protocol.client.binding.NoBindingSuggestionFoundParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.binding.SuggestBindingParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.branch.DidChangeMatchedSonarProjectBranchParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.branch.MatchProjectBranchParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.branch.MatchProjectBranchResponse;
import org.sonarsource.sonarlint.core.rpc.protocol.client.branch.MatchSonarProjectBranchParams;
import org.sonarsource.sonarlint.core.rpc.protocol.client.branch.MatchSonarProjectBranchResponse;
import org.sonarsource.sonarlint.core.rpc.protocol.client.connection.AssistCreatingConnectionParams;
Expand Down Expand Up @@ -311,6 +313,18 @@ public CompletableFuture<MatchSonarProjectBranchResponse> matchSonarProjectBranc
});
}

@Override
public CompletableFuture<MatchProjectBranchResponse> matchProjectBranch(MatchProjectBranchParams params) {
return requestAsync(cancelChecker -> {
try {
return new MatchProjectBranchResponse(
delegate.matchProjectBranch(params.getConfigurationScopeId(), params.getServerBranchToMatch(), new SonarLintCancelChecker(cancelChecker)));
} catch (ConfigScopeNotFoundException e) {
throw configScopeNotFoundError(params.getConfigurationScopeId());
}
});
}

@Override
public void didChangeMatchedSonarProjectBranch(DidChangeMatchedSonarProjectBranchParams params) {
notify(() -> delegate.didChangeMatchedSonarProjectBranch(params.getConfigScopeId(), params.getNewMatchedBranchName()));
Expand Down
4 changes: 2 additions & 2 deletions its/plugins/custom-sensor-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-its</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<groupId>org.sonarsource.plugins.example</groupId>
<artifactId>custom-sensor-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>

<name>Example Plugin for SonarQube</name>
<description>Example of plugin for SonarQube</description>
Expand Down
2 changes: 1 addition & 1 deletion its/plugins/global-extension-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-its</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion its/plugins/java-custom-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-its</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion its/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
</parent>
<artifactId>sonarlint-core-its</artifactId>
<name>SonarLint Core - ITs</name>
Expand Down
2 changes: 1 addition & 1 deletion its/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-its</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
</parent>
<artifactId>sonarlint-core-its-tests</artifactId>
<name>SonarLint Core - ITs - Tests</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ public String matchSonarProjectBranch(String configurationScopeId, String mainBr
return mainBranchName;
}

public boolean matchProjectBranch(String configurationScopeId, String branchNameToMatch, SonarLintCancelChecker cancelChecker) throws ConfigScopeNotFoundException {
return true;
}

@Override
public void didChangeMatchedSonarProjectBranch(String configScopeId, String newMatchedBranchName) {

Expand Down
2 changes: 1 addition & 1 deletion medium-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.sonarsource.sonarlint.core</groupId>
<artifactId>sonarlint-core-parent</artifactId>
<version>10.7-SNAPSHOT</version>
<version>10.7.1-SNAPSHOT</version>
</parent>
<artifactId>sonarlint-medium-tests</artifactId>
<name>SonarLint Core - Medium Tests</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,11 @@ public String matchSonarProjectBranch(String configurationScopeId, String mainBr
return mainBranchName;
}

@Override
public boolean matchProjectBranch(String configurationScopeId, String branchNameToMatch, SonarLintCancelChecker cancelChecker) throws ConfigScopeNotFoundException {
return true;
}

@Override
public void didChangeMatchedSonarProjectBranch(String configScopeId, String newMatchedBranchName) {

Expand Down
Loading

0 comments on commit 756d3f1

Please sign in to comment.