public void SetsIsEnterpriseCorrectly(string htmlUrl, bool expected) { var apiAccount = CreateOctokitUser(htmlUrl); var cachedAccount = new AccountCacheItem(apiAccount); Assert.Equal(expected, cachedAccount.IsEnterprise); }
IObservable<AuthenticationResult> LoginWithApiUser(UserAndScopes userAndScopes) { return GetAuthenticationResultForUser(userAndScopes) .SelectMany(result => { if (result.IsSuccess()) { var accountCacheItem = new AccountCacheItem(userAndScopes.User); usage.IncrementLoginCount().Forget(); return ModelService.InsertUser(accountCacheItem).Select(_ => result); } if (result == AuthenticationResult.VerificationFailure) { return loginCache.EraseLogin(Address).Select(_ => result); } return Observable.Return(result); }) .ObserveOn(RxApp.MainThreadScheduler) .Do(result => { if (result.IsSuccess()) { SupportsGist = userAndScopes.Scopes?.Contains("gist") ?? true; IsLoggedIn = true; } log.Info("Log in from cache for login '{0}' to host '{1}' {2}", userAndScopes?.User?.Login ?? "(null)", hostAddress.ApiUri, result.IsSuccess() ? "SUCCEEDED" : "FAILED"); }); }
IObservable<AuthenticationResult> LoginWithApiUser(AccountCacheItem user) { return GetAuthenticationResultForUser(user) .SelectMany(result => { if (result.IsSuccess()) { return ModelService.InsertUser(user).Select(_ => result); } if (result == AuthenticationResult.VerificationFailure) { return loginCache.EraseLogin(Address).Select(_ => result); } return Observable.Return(result); }) .ObserveOn(RxApp.MainThreadScheduler) .Do(result => { if (result.IsSuccess()) { IsLoggedIn = true; } log.Info("Log in from cache for login '{0}' to host '{1}' {2}", user != null ? user.Login : "******", hostAddress.ApiUri, result.IsSuccess() ? "SUCCEEDED" : "FAILED"); }); }
static IObservable<AuthenticationResult> GetAuthenticationResultForUser(AccountCacheItem account) { return Observable.Return(account == null ? AuthenticationResult.CredentialFailure : account == unverifiedUser ? AuthenticationResult.VerificationFailure : AuthenticationResult.Success); }
public PullRequestCacheItem(PullRequest pr, IReadOnlyList<PullRequestFile> files) { Title = pr.Title; Number = pr.Number; Base = new GitReferenceCacheItem { Label = pr.Base.Label, Ref = pr.Base.Ref, Sha = pr.Base.Sha, RepositoryCloneUrl = pr.Base.Repository.CloneUrl, }; Head = new GitReferenceCacheItem { Label = pr.Head.Label, Ref = pr.Head.Ref, Sha = pr.Head.Sha, RepositoryCloneUrl = pr.Head.Repository?.CloneUrl }; CommentCount = pr.Comments + pr.ReviewComments; CommitCount = pr.Commits; Author = new AccountCacheItem(pr.User); Assignee = pr.Assignee != null ? new AccountCacheItem(pr.Assignee) : null; CreatedAt = pr.CreatedAt; UpdatedAt = pr.UpdatedAt; Body = pr.Body; ChangedFiles = files.Select(x => new PullRequestFileCacheItem(x)).ToList(); State = GetState(pr); IsOpen = pr.State == ItemState.Open; Merged = pr.Merged; Key = Number.ToString(CultureInfo.InvariantCulture); Timestamp = UpdatedAt; }
public IObservable<Unit> InsertUser(AccountCacheItem user) { return hostCache.InsertObject("user", user); }
IAccount Create(AccountCacheItem accountCacheItem) { return new Models.Account( accountCacheItem.Login, accountCacheItem.IsUser, accountCacheItem.IsEnterprise, accountCacheItem.OwnedPrivateRepositoriesCount, accountCacheItem.PrivateRepositoriesInPlanCount, avatarProvider.GetAvatar(accountCacheItem)); }
public PullRequestCacheItem(PullRequest pr) { Title = pr.Title; Number = pr.Number; CommentCount = pr.Comments; Author = new AccountCacheItem(pr.User); CreatedAt = pr.CreatedAt; UpdatedAt = pr.UpdatedAt; Key = Number.ToString(CultureInfo.InvariantCulture); Timestamp = UpdatedAt; }