-
Notifications
You must be signed in to change notification settings - Fork 77
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
Conversation
77da67c
to
2d08fca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -33,11 +33,12 @@ public record ConnectionInfo(string Id, ConnectionServerType ServerType) | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add documentation for what the Id is expected to be and that it is different than the ServerConnection
2d08fca
to
734aa31
Compare
@@ -91,7 +91,11 @@ public Task<AdapterResponseWithData<List<OrganizationDisplay>>> GetOrganizations | |||
|
|||
try | |||
{ | |||
var credentials = MapCredentials(credentialsModel?.ToICredentials()); | |||
if (credentialsModel == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this explicit check. If it is null, there will be a null reference exception that will be caught by the catch block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case the credentialsModel is null the ToICredentials will throw a generic null exception. In this case I believe it's better to be proactive and add back the .?
so the exception we get becomes specific to the lack of credentials.
@@ -37,7 +37,7 @@ public static ConnectionInfo From(ServerConnection serverConnection) | |||
{ | |||
ServerConnection.SonarQube sonarQubeConnection => new ConnectionInfo(sonarQubeConnection.Id, ConnectionServerType.SonarQube), | |||
ServerConnection.SonarCloud sonarCloudConnection => new ConnectionInfo(sonarCloudConnection.OrganizationKey, ConnectionServerType.SonarCloud), | |||
_ => null | |||
_ => throw new ArgumentException(Resources.UnexpectedConnectionType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unit test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not technically possible to add a unit test for this case. Technically, this branch is unreachable as the ServerConnection
constructor is private, so a ServerConnection can be either SonarQube or SonarCloud. It is also not possible to remove the default case without having a warning, as the C# compiler can't properly recognize exhaustive switch.
@@ -216,7 +216,7 @@ private static Either<TransientSonarQubeConnectionDto, TransientSonarCloudConnec | |||
new TransientSonarQubeConnectionDto(connectionInfo.Id, credentialsDto)), | |||
ConnectionServerType.SonarCloud => Either<TransientSonarQubeConnectionDto, TransientSonarCloudConnectionDto>.CreateRight( | |||
new TransientSonarCloudConnectionDto(connectionInfo.Id, credentialsDto)), | |||
_ => null | |||
_ => throw new ArgumentException(Resources.UnexpectedConnectionType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unit test
@@ -230,7 +230,7 @@ private static Either<TransientSonarQubeConnectionDto, TransientSonarCloudConnec | |||
new TransientSonarQubeConnectionDto(sonarQubeConnection.Id, credentials)), | |||
ServerConnection.SonarCloud sonarCloudConnection => Either<TransientSonarQubeConnectionDto, TransientSonarCloudConnectionDto>.CreateRight( | |||
new TransientSonarCloudConnectionDto(sonarCloudConnection.OrganizationKey, credentials)), | |||
_ => null | |||
_ => throw new ArgumentException(Resources.UnexpectedConnectionType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unit test
|
||
return connectionInfo.ServerType switch | ||
{ | ||
ConnectionServerType.SonarQube => Either<TransientSonarQubeConnectionDto, TransientSonarCloudConnectionDto>.CreateLeft( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider adding a comment here or in the caller method to point out that the organizationKey is expected to be null, when validating a transient connection (a connection that is not yet finished)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it would make it a bit more clear. However, I am not sure whether this is the correct place. This requirement comes from the SLCore API, which is already documented there, and on our end, we have unit tests to verify that this behavior is respected.
Quality Gate passedIssues Measures |
SLVS-1455
What
Store the
https://sonarcloud.io/organizations/OrganizationKey
instead of the sonarcloud organization as connection ID.Why
This is pre-work to remove the prefixes (
sc|
andsq|
) fromConnectionIdHelper
. Connections should be identifiable by theirId
.How
ConnectionInfo
is a UI model that is used to display information on the UI and act as a DTO.1.1. The
ConnectionInfo.Id
is either the sonarqube uri or the sonarcloud organization.ServerConnection
is a backend model and it should not be used directly on the UI.1.1. The
ServerConnection.Id
is always a uri...Adapter
should be able to convert UI models to backend models (eg.ConnectionInfo
toServerConnection
)...Repository
should only know/reference backend models and never UI models.Expected results
connections.json
: All connectionsId
should be URLshttp://localhost:9000
https://sonarcloud.io/organizations/OrganizationKey
binding.config
:ServerConnectionId
should be the same as inconnection.json