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

SLVS-1455 Make Id of type URL #5698

Merged
merged 12 commits into from
Sep 25, 2024
Prev Previous commit
Next Next commit
Fix rebase issues
vnaskos-sonar committed Sep 24, 2024

Verified

This commit was signed with the committer’s verified signature.
jborean93 Jordan Borean
commit e0b7b61d59fa6594b67bd2daac4db8e67c26ae09
Original file line number Diff line number Diff line change
@@ -799,7 +799,7 @@ public async Task UseSharedBindingAsync_SharedBindingForExistSonarQubeConnection
var response = await testSubject.UseSharedBindingAsync();

response.Success.Should().BeTrue();
serverConnectionsRepositoryAdapter.Received(1).TryGetServerConnectionById(testSubject.SharedBindingConfigModel.Uri.ToString(), out _);
serverConnectionsRepositoryAdapter.Received(1).TryGet(new ConnectionInfo(testSubject.SharedBindingConfigModel.Uri.ToString(), ConnectionServerType.SonarQube), out _);
await bindingController.Received(1)
.BindAsync(Arg.Is<BoundServerProject>(proj => proj.ServerConnection == expectedServerConnection), Arg.Any<CancellationToken>());
}
@@ -815,7 +815,7 @@ public async Task UseSharedBindingAsync_SharedBindingForExistingSonarCloudConnec
var response = await testSubject.UseSharedBindingAsync();

response.Success.Should().BeTrue();
serverConnectionsRepositoryAdapter.Received(1).TryGetServerConnectionById(testSubject.SharedBindingConfigModel.Organization, out _);
serverConnectionsRepositoryAdapter.Received(1).TryGet(new ConnectionInfo(testSubject.SharedBindingConfigModel.Organization, ConnectionServerType.SonarCloud), out _);
await bindingController.Received(1)
.BindAsync(Arg.Is<BoundServerProject>(proj => proj.ServerConnection == expectedServerConnection), Arg.Any<CancellationToken>());
}
6 changes: 0 additions & 6 deletions src/ConnectedMode/ServerConnectionsRepositoryAdapter.cs
Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@ namespace SonarLint.VisualStudio.ConnectedMode;

public interface IServerConnectionsRepositoryAdapter
{
bool TryGetServerConnectionById(ConnectionInfo connectionInfo, out ServerConnection serverConnection);
bool TryGetAllConnections(out List<Connection> connections);
bool TryGetAllConnectionsInfo(out List<ConnectionInfo> connectionInfos);
bool TryRemoveConnection(ConnectionInfo connectionInfo);
@@ -41,11 +40,6 @@ public interface IServerConnectionsRepositoryAdapter
[method: ImportingConstructor]
internal class ServerConnectionsRepositoryAdapter(IServerConnectionsRepository serverConnectionsRepository) : IServerConnectionsRepositoryAdapter
{
public bool TryGetServerConnectionById(ConnectionInfo connectionInfo, out ServerConnection serverConnection)
{
return TryGet(connectionInfo, out serverConnection);
}

public bool TryGetAllConnections(out List<Connection> connections)
{
var succeeded = serverConnectionsRepository.TryGetAll(out var serverConnections);
13 changes: 5 additions & 8 deletions src/ConnectedMode/UI/ManageBinding/ManageBindingViewModel.cs
Original file line number Diff line number Diff line change
@@ -176,10 +176,12 @@ public async Task ExportBindingConfigurationAsync()

internal async Task<AdapterResponse> UseSharedBindingAsync()
{
var connectionId = GetConnectionIdFromSharedBindingConfig();
if (!connectedModeServices.ServerConnectionsRepositoryAdapter.TryGetServerConnectionById(connectionId, out var serverConnection))
var connection = SharedBindingConfigModel.IsSonarCloud()
? new ConnectionInfo(SharedBindingConfigModel.Organization, ConnectionServerType.SonarCloud)
: new ConnectionInfo(SharedBindingConfigModel.Uri.ToString(), ConnectionServerType.SonarQube);
if (!connectedModeServices.ServerConnectionsRepositoryAdapter.TryGet(connection, out var serverConnection))
{
connectedModeServices.Logger.WriteLine(ConnectedMode.Resources.UseSharedBinding_ConnectionNotFound, connectionId);
connectedModeServices.Logger.WriteLine(ConnectedMode.Resources.UseSharedBinding_ConnectionNotFound, connection.Id);
connectedModeServices.MessageBox.Show(UiResources.NotFoundConnectionForSharedBindingMessageBoxText, UiResources.NotFoundConnectionForSharedBindingMessageBoxCaption, MessageBoxButton.OK, MessageBoxImage.Warning);
return new AdapterResponse(false);
}
@@ -268,11 +270,6 @@ internal bool LoadConnections()
return await BindAsync(serverConnection, SelectedProject?.Key);
}

private string GetConnectionIdFromSharedBindingConfig()
{
return SharedBindingConfigModel.IsSonarCloud() ? new ServerConnection.SonarCloud(SharedBindingConfigModel.Organization).Id : new ServerConnection.SonarQube(SharedBindingConfigModel.Uri).Id;
}

private async Task<AdapterResponse> BindAsync(ServerConnection serverConnection, string serverProjectKey)
{
try