-
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
Add GetConnectionIdFromUri Method to ConnectionIdHelper #5231
Add GetConnectionIdFromUri Method to ConnectionIdHelper #5231
Conversation
@@ -33,6 +35,22 @@ internal class ConnectionIdHelper : IConnectionIdHelper | |||
private const string SonarQubePrefix = "sq|"; | |||
private static readonly Uri SonarCloudUri = new Uri("https://sonarcloud.io"); | |||
|
|||
public string GetConnectionIdFromUri(string uriString, string organisation) |
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.
BoundSonarQubeProject has Uri
property, why do you use string
here? The other method of this class also returns Uri and not string
@@ -33,6 +35,22 @@ internal class ConnectionIdHelper : IConnectionIdHelper | |||
private const string SonarQubePrefix = "sq|"; | |||
private static readonly Uri SonarCloudUri = new Uri("https://sonarcloud.io"); | |||
|
|||
public string GetConnectionIdFromUri(Uri uri, string organisation) | |||
{ | |||
if (uri is not 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.
invert if to reduce nesting
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 don't think it will be that useful because then we'll need to have more return points (since this way it returns null when organisation is missing)
{ | ||
if (uri == SonarCloudUri) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(organisation)) { return SonarCloudPrefix + organisation; } |
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.
newlines missing in if body
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's to reduce clutter I think the expression is simple enough to read easily.
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 you're treating a symptom here. This method is hard to read, I completely missed the branch where organization is null (is that even a possibility?)
var actualConnectionId = testSubject.GetConnectionIdFromUri(null, "something"); | ||
|
||
actualConnectionId.Should().BeNull(); | ||
} |
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.
add test that uri == GetUriFromConnectionId(GetConnectionIdFromUri(uri))
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.
a couple of small suggestions, otherwise LGTM
Quality Gate passedIssues Measures |
5d81b54
into
feature/sloop-rule-meta-data
if (!string.IsNullOrWhiteSpace(organisation)) | ||
{ | ||
return SonarCloudPrefix + organisation; | ||
} |
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.
Maybe for a refactoring change in the next PR:
This would be easier to understand like this:
return string.IsNullOrWhiteSpace(organization)
? null
: SonarCloudPrefix + organization;
and then removing the least return null
@@ -33,6 +35,28 @@ internal class ConnectionIdHelper : IConnectionIdHelper | |||
private const string SonarQubePrefix = "sq|"; | |||
private static readonly Uri SonarCloudUri = new Uri("https://sonarcloud.io"); |
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.
C#9 target-typed null can be useful here (it's not useful ultimately everywhere, this is a place where it is)
private static readonly Uri SonarCloudUri = new("https://sonarcloud.io");
Fixes #5230