-
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 1 commit
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(string uriString, 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"); | ||
|
||
public string GetConnectionIdFromUri(string uriString, string 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. BoundSonarQubeProject has |
||
{ | ||
if (!string.IsNullOrWhiteSpace(uriString) && Uri.TryCreate(uriString, UriKind.Absolute, out var uri)) | ||
{ | ||
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 + uriString; | ||
} | ||
} | ||
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.
C#9 target-typed null can be useful here (it's not useful ultimately everywhere, this is a place where it is)