-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from microsoft/staging
Release - 4/23/24
- Loading branch information
Showing
116 changed files
with
999 additions
and
2,274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,17 @@ | |
|
||
using GitHubExtension.DataModel; | ||
using Octokit; | ||
using Serilog; | ||
|
||
namespace GitHubExtension.Client; | ||
|
||
// Validation layer to help parsing GitHub URL. | ||
public static class Validation | ||
{ | ||
private static readonly Lazy<ILogger> _log = new(() => Serilog.Log.ForContext("SourceContext", nameof(Validation))); | ||
|
||
private static readonly ILogger Log = _log.Value; | ||
|
||
private static bool IsValidHttpUri(string uriString, out Uri? uri) | ||
{ | ||
return Uri.TryCreate(uriString, UriKind.Absolute, out uri) && | ||
|
@@ -17,15 +22,15 @@ private static bool IsValidHttpUri(string uriString, out Uri? uri) | |
|
||
public static bool IsValidGitHubURL(Uri uri) | ||
{ | ||
return IsValidGitHubComURL(uri) || IsValidGitHubEnterpriseServerURL(uri); | ||
return IsValidGitHubComURL(uri) || (IsValidGitHubEnterpriseServerURL(uri) && IsReachableGitHubEnterpriseServerURL(uri).Result); | ||
} | ||
|
||
public static bool IsValidGitHubComURL(Uri uri) | ||
{ | ||
// Valid GitHub URL has three segments. The first is '/'. | ||
if (uri.Segments.Length < 3 || (!uri.Host.Equals("github.com", StringComparison.OrdinalIgnoreCase) && !uri.Host.Equals("www.github.com", StringComparison.OrdinalIgnoreCase))) | ||
{ | ||
Log.Logger()?.ReportDebug($"{uri.OriginalString} is not a valid GitHub uri"); | ||
Log.Debug($"{uri.OriginalString} is not a valid GitHub uri"); | ||
return false; | ||
} | ||
|
||
|
@@ -39,7 +44,7 @@ public static bool IsValidGitHubEnterpriseServerURL(Uri server) | |
// https://docs.github.com/en/[email protected]/admin/configuration/configuring-network-settings/configuring-the-hostname-for-your-instance | ||
if (server.Segments.Length < 3) | ||
{ | ||
Log.Logger()?.ReportDebug($"{server.OriginalString} is not a valid GHES repo uri"); | ||
Log.Debug($"{server.OriginalString} is not a valid GHES repo uri"); | ||
return false; | ||
} | ||
|
||
|
@@ -56,7 +61,7 @@ public static bool IsValidGitHubURL(string url) | |
// Above link shows a work around. | ||
if (!IsValidHttpUri(url, out parsedUri) || url == null || parsedUri == null) | ||
{ | ||
Log.Logger()?.ReportDebug($"{url} is not a valid http uri"); | ||
Log.Debug($"{url} is not a valid http uri"); | ||
return false; | ||
} | ||
|
||
|
@@ -227,13 +232,13 @@ public static async Task<bool> IsReachableGitHubEnterpriseServerURL(Uri server) | |
var probeResult = await new EnterpriseProbe(new ProductHeaderValue(Constants.DEV_HOME_APPLICATION_NAME)).Probe(server); | ||
if (probeResult != EnterpriseProbeResult.Ok) | ||
{ | ||
Log.Logger()?.ReportError($"EnterpriseServer {server.AbsoluteUri} is not reachable"); | ||
Log.Error($"EnterpriseServer {server.AbsoluteUri} is not reachable"); | ||
return false; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Logger()?.ReportError($"EnterpriseServer {server.AbsoluteUri} could not be probed.", ex); | ||
Log.Error(ex, $"EnterpriseServer {server.AbsoluteUri} could not be probed."); | ||
return false; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.