public void Update()
 {
     PullRequests.Clear();
     foreach (var pullRequest in Model.Values.OrderBy(pr => pr.Id))
     {
         PullRequests.Add(new PullRequestViewModel(pullRequest));
     }
 }
Пример #2
0
        /// <summary>
        /// Reads the pull requests from the persistent file
        /// </summary>
        public void GetCurrentSaved()
        {
            Debug.Assert(this != null);
            try
            {
                if (!Directory.Exists(CacheDirectory))
                {
                    return;
                }
                if (!File.Exists(CachedLocalPullRequestListPath))
                {
                    return;
                }
                var json = File.ReadAllText(CachedLocalPullRequestListPath);
                var list = JsonConvert.DeserializeObject <IEnumerable <PullRequest> >(json);
                PullRequests.Clear();
                foreach (var p in list)
                {
                    //Restore Self-Referential Loops
                    p.ParentRepo = this;
                    foreach (var r in p.ValidFiles)
                    {
                        r.ParentPullRequst = p;
                    }

                    if (VerifyPullRequestCache(p))
                    {
                        PullRequests.Add(p);
                        foreach (var r in p.ValidFiles)
                        {
                            r.LoadFromCache();
                        }
                    }
                    else
                    {
                        if (Directory.Exists(p.CacheDirectory))
                        {
                            Directory.Delete(p.CacheDirectory, true);
                        }
                    }
                }

                UpdateLocalSavedList(); //In case some were deleted, write the file back
            }
            catch (Exception ex)
            {
                Logger.Error($"{ex.GetType().Name}: Couldn't load {CachedLocalPullRequestListPath} because {ex.Message}");
            }
        }
Пример #3
0
        /// <summary>
        /// Gets each page of the pull request list from GitHub. Once the list is complete, get all
        /// the pull request files for each pull request.
        /// </summary>
        /// <returns>List of pull request information.</returns>
        public async Task <IList <PullRequest> > GetPullRequestsAsync()
        {
            var url     = $"/repos/{Owner}/{RepoName}/pulls";
            var etag    = Ref.Create(EtagNoChanges);
            var updated = await GetPaginatedListAsync <PullRequest>(url, etag);

            var outdated = PullRequests;

            EtagNoChanges = etag.Value;
            if (updated == null)
            {
                return(null);
            }
            if (outdated != null)
            {
                var prToRemove = outdated.Where(old => updated.All(newpr => newpr.Number != old.Number));
                foreach (var pr in updated)
                {
                    pr.ParentRepo = this;
                    var old = outdated.FirstOrDefault(o => o.Number == pr.Number);
                    if (old != null)
                    {
                        pr.LastWrite = old.LastWrite;
                    }
                }
                DeletePRsFromDisk(prToRemove);
            }
            await Task.WhenAll(updated.Select(async pr =>
            {
                var files = await GetPaginatedListAsync <RepoFile>($"/repos/{Owner}/{RepoName}/pulls/{pr.Number}/files");
                foreach (var f in files)
                {
                    f.ParentPullRequst = pr;
                }
                pr.Files = PullRequest.FilterFiles(files).ToList();
                return(pr);
            }));

            PullRequests.Clear();
            PullRequests.AddRange(updated);
            UpdateLocalSavedList();
            return(updated);
        }