Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit f279aed

Browse files
StanleyGoldmanshana
authored andcommitted
Adding additional IsGitHubDotCom method
1 parent 88adbf1 commit f279aed

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public async Task<bool> ContinueLoginAsync(LoginResult loginResult, Func<LoginRe
205205
// it'll throw if it's private or an enterprise instance requiring authentication
206206
catch (ApiException apiex)
207207
{
208-
if (!HostAddress.IsGitHubDotComUri(OriginalUrl.ToRepositoryUri()))
208+
if (!HostAddress.IsGitHubDotCom(OriginalUrl.ToRepositoryUri()))
209209
isEnterprise = apiex.IsGitHubApiException();
210210
}
211211
catch {}

src/GitHub.Api/Authentication/LoginManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ bool EnterpriseWorkaround(UriString hostAddress, Exception e)
257257
// the failure, using basic authentication (with username and password) instead of trying
258258
// to get an authorization token.
259259
var apiException = e as ApiException;
260-
return !HostAddress.IsGitHubDotComUri(hostAddress.ToUri()) &&
260+
return !HostAddress.IsGitHubDotCom(hostAddress) &&
261261
(e is NotFoundException ||
262262
e is ForbiddenException ||
263263
apiException?.StatusCode == (HttpStatusCode)422);

src/GitHub.Api/Primitives/HostAddress.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class HostAddress
1616
/// <returns></returns>
1717
public static HostAddress Create(Uri hostUri)
1818
{
19-
return IsGitHubDotComUri(hostUri)
19+
return IsGitHubDotCom(hostUri)
2020
? GitHubDotComHostAddress
2121
: new HostAddress(hostUri);
2222
}
@@ -68,16 +68,26 @@ public HostAddress()
6868
// since that's the same cache key for all the other github.com operations.
6969
public string CredentialCacheKeyHost { get; private set; }
7070

71-
public static bool IsGitHubDotComUri(Uri hostUri)
71+
public static bool IsGitHubDotCom(Uri hostUri)
7272
{
7373
return hostUri.IsSameHost(GitHubDotComHostAddress.WebUri)
7474
|| hostUri.IsSameHost(GitHubDotComHostAddress.ApiUri)
7575
|| hostUri.IsSameHost(gistUri);
7676
}
7777

78+
public static bool IsGitHubDotCom(string url)
79+
{
80+
if (String.IsNullOrEmpty(url))
81+
return false;
82+
Uri uri = null;
83+
if (!Uri.TryCreate(url, UriKind.Absolute, out uri))
84+
return false;
85+
return IsGitHubDotCom(uri);
86+
}
87+
7888
public bool IsGitHubDotCom()
7989
{
80-
return IsGitHubDotComUri(ApiUri);
90+
return IsGitHubDotCom(ApiUri);
8191
}
8292

8393
public string Title

0 commit comments

Comments
 (0)