-
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ namespace SonarLint.VisualStudio.SLCore.Common.Helpers | |
internal interface IConnectionIdHelper | ||
{ | ||
Uri GetUriFromConnectionId(string connectionId); | ||
|
||
string GetConnectionIdFromUri(Uri uri, string organisation); | ||
} | ||
|
||
internal class ConnectionIdHelper : IConnectionIdHelper | ||
|
@@ -33,6 +35,22 @@ 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 commentThe 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)
|
||
|
||
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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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?) |
||
} | ||
else | ||
{ | ||
return SonarQubePrefix + uri.ToString(); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public Uri GetUriFromConnectionId(string connectionId) | ||
{ | ||
if (connectionId == null) | ||
|
@@ -43,8 +61,8 @@ public Uri GetUriFromConnectionId(string connectionId) | |
if (connectionId.StartsWith(SonarCloudPrefix)) | ||
{ | ||
var uriString = connectionId.Substring(SonarCloudPrefix.Length); | ||
return !string.IsNullOrWhiteSpace(uriString) ? SonarCloudUri : null; | ||
|
||
return !string.IsNullOrWhiteSpace(uriString) ? SonarCloudUri : null; | ||
} | ||
|
||
if (connectionId.StartsWith(SonarQubePrefix)) | ||
|
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))