Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1476 from github/fixes/1473-enterprise-instance-n…
Browse files Browse the repository at this point in the history
…ot-detected

Fix SimpleApiClient.IsEnterprise().
  • Loading branch information
shana committed Feb 8, 2018
2 parents b568332 + 3be40a0 commit 78ad9f4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
11 changes: 8 additions & 3 deletions src/GitHub.Api/SimpleApiClient.cs
Expand Up @@ -72,7 +72,7 @@ async Task<Repository> GetRepositoryInternal()
if (repo != null)
{
hasWiki = await HasWikiInternal(repo);
isEnterprise = await IsEnterpriseInternal();
isEnterprise = isEnterprise ?? await IsEnterpriseInternal();
repositoryCache = repo;
}
owner = ownerLogin;
Expand All @@ -99,9 +99,14 @@ public bool HasWiki()
return hasWiki.HasValue && hasWiki.Value;
}

public bool IsEnterprise()
public async Task<bool> IsEnterprise()
{
return isEnterprise.HasValue && isEnterprise.Value;
if (!isEnterprise.HasValue)
{
isEnterprise = await IsEnterpriseInternal();
}

return isEnterprise ?? false;
}

async Task<bool> HasWikiInternal(Repository repo)
Expand Down
Expand Up @@ -366,7 +366,7 @@ async Task UpdateContent(ILocalRepositoryModel repository)
var repositoryUrl = repository.CloneUrl.ToRepositoryUrl();
var isDotCom = HostAddress.IsGitHubDotComUri(repositoryUrl);
var client = await apiClientFactory.Create(repository.CloneUrl);
var isEnterprise = isDotCom ? false : client.IsEnterprise();
var isEnterprise = isDotCom ? false : await client.IsEnterprise();

if ((isDotCom || isEnterprise) && await IsValidRepository(client))
{
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.Exports/Api/ISimpleApiClient.cs
Expand Up @@ -11,7 +11,7 @@ public interface ISimpleApiClient
UriString OriginalUrl { get; }
Task<Repository> GetRepository();
bool HasWiki();
bool IsEnterprise();
Task<bool> IsEnterprise();
bool IsAuthenticated();
}
}
2 changes: 1 addition & 1 deletion src/GitHub.VisualStudio.UI/Base/TeamExplorerItemBase.cs
Expand Up @@ -126,7 +126,7 @@ protected async Task<RepositoryOrigin> GetRepositoryOrigin()
{
var repo = await SimpleApiClient.GetRepository();

if ((repo.FullName == ActiveRepoName || repo.Id == 0) && SimpleApiClient.IsEnterprise())
if ((repo.FullName == ActiveRepoName || repo.Id == 0) && await SimpleApiClient.IsEnterprise())
{
return RepositoryOrigin.Enterprise;
}
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.VisualStudio/Menus/MenuBase.cs
Expand Up @@ -123,7 +123,7 @@ protected async Task<bool> IsGitHubRepo()
{
var repo = await SimpleApiClient.GetRepository();
var activeRepoFullName = ActiveRepo.Owner + '/' + ActiveRepo.Name;
return (repo.FullName == activeRepoFullName || repo.Id == 0) && SimpleApiClient.IsEnterprise();
return (repo.FullName == activeRepoFullName || repo.Id == 0) && await SimpleApiClient.IsEnterprise();
}
return isdotcom;
}
Expand Down
6 changes: 3 additions & 3 deletions test/UnitTests/GitHub.Api/SimpleApiClientTests.cs
Expand Up @@ -132,10 +132,10 @@ public async Task ReturnsTrueWhenEnterpriseProbeReturnsOk(EnterpriseProbeResult
new Lazy<IWikiProbe>(() => wikiProbe));
await client.GetRepository();

var result = client.IsEnterprise();
var result = await client.IsEnterprise();

Assert.That(expected, Is.EqualTo(result));
Assert.That(expected, Is.EqualTo(client.IsEnterprise()));
Assert.That(expected, Is.EqualTo(await client.IsEnterprise()));
}

[Test]
Expand All @@ -151,7 +151,7 @@ public void ReturnsFalseWhenWeHaveNotRequestedRepository()
new Lazy<IEnterpriseProbe>(() => enterpriseProbe),
new Lazy<IWikiProbe>(() => wikiProbe));

var result = client.IsEnterprise();
var result = client.IsEnterprise().Result;

Assert.False(result);
}
Expand Down

0 comments on commit 78ad9f4

Please sign in to comment.