Skip to content

SLVS-1394 Load organizations #5629

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

Merged

Conversation

gabriela-trutan-sonarsource
Copy link
Contributor

@gabriela-trutan-sonarsource gabriela-trutan-sonarsource commented Aug 23, 2024

SLVS-1394

This PR updates the ISlCoreConnectionAdapter to load the organizations for SonarCloud when creating a new connection.
Showing it in the UI will be a different PR

@terraform-techuser terraform-techuser changed the title SLVS-1394 Load organizations SLVS-1394 Load organizations Aug 23, 2024
@@ -63,13 +68,39 @@ public async Task<ValidateConnectionResponse> ValidateConnectionAsync(Connection
return await ValidateConnectionAsync(validateConnectionParams);
}

public async Task<AdapterResponse<List<OrganizationDisplay>>> GetOrganizationsAsync(ICredentialsModel credentialsModel)
{
var failedResponse = new AdapterResponse<List<OrganizationDisplay>>(false, []);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be static readonly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What can be static readonly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable failedResponse, you mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
var failedResponse = new AdapterResponse<List<OrganizationDisplay>>(false, []);

return await threadHandling.RunOnBackgroundThread(async () =>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can return without async

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to be explicit.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, not really. You have the async lambda inside and you could add the Async suffix to the method name. Not a big deal in the end, but it would technically be more efficient to return just the task and not await it's result here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the async

@@ -85,6 +116,17 @@ private async Task<ValidateConnectionResponse> ValidateConnectionAsync(ValidateC
});
}

private IConnectionConfigurationSLCoreService TryGetConnectionConfigurationSlCoreService()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try pattern should return bool and have an out parameters


namespace SonarLint.VisualStudio.ConnectedMode.UI.OrganizationSelection;

[ExcludeFromCodeCoverage]
public partial class OrganizationSelectionDialog : Window
{
public OrganizationSelectionDialog(IReadOnlyList<OrganizationDisplay> organizations)
public OrganizationSelectionDialog(IConnectedModeServices connectedModeServices, ICredentialsModel credentialsModel)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was simpler when it was just accepting a static list of connections, but I also get the point of moving the responsibility here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler, maybe. But that means we would have to load the connections from the dialog, which would violate the MVVM pattern: the view should have no knowledge about the Model (slCore in our case)

@@ -52,7 +52,8 @@ private void EditConnection_Clicked(object sender, RoutedEventArgs e)

private void NewConnection_Clicked(object sender, RoutedEventArgs e)
{
if (GetTransientConnection() is {} transientConnection && CredentialsDialogSucceeded(transientConnection) && GetCompleteConnection(transientConnection) is {} completeConnection)
if (GetTransientConnection() is {} partialConnection && GetCredentialsDialog(partialConnection) is {} credentialsDialog &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. formatting is incorrect here. 1 part of boolean expression per line, line breaks before operators.
  2. GetCredentialsDialog can never return null, so the condition feels a bit hacky. At this point I would convert this if (a && b && c && d) into
if(!a) return;
var dialog = b();
if(!c) return;
if(connection.Type == SonarCloud && !d) return;
viewModel.add()

}

var credentialsDialog = GetCredentialsDialog(transientConnection);
if (!CredentialsDialogSucceeded(credentialsDialog) || GetCompleteConnection(transientConnection, credentialsDialog) is not { } completeConnection)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at this point I would extract the server type check from GetCompleteConnection and rename it to FinalizeSonarCloudConnection or smth like that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather leave it like this. I think it is more readable and less cognitive complexity. It is, in the end, related to the final connection.

Would you want me to rename the GetCompleteConnection to FinalizeConnection? I see that SlCore also has the Transient connection vs full connection. So for me seems fine to stay as it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the method

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. it hides the fact that this method is only really needed to be called for SC connections, which just makes it less clear why we call it for SQ
  2. both of these connections are transitive, as they need to be saved in the repository first and then synced with SLCore to be non-transitive

Copy link
Contributor Author

@gabriela-trutan-sonarsource gabriela-trutan-sonarsource Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the caller needs to know that is only needed for SC. It simply needs the final connection. Adding a (a || (b&&c) ) makes the if more complex, therefore I think the logic should be part of another method

Copy link

@gabriela-trutan-sonarsource gabriela-trutan-sonarsource merged commit f69a48e into feature/new-connected-mode Aug 26, 2024
5 checks passed
@gabriela-trutan-sonarsource gabriela-trutan-sonarsource deleted the gt/load-organizations branch August 26, 2024 08:37
vnaskos-sonar pushed a commit that referenced this pull request Sep 12, 2024
vnaskos-sonar pushed a commit that referenced this pull request Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants