示例#1
0
 internal Task <ImmutableList <CommitStatus> > LoadBranchStatus(string commitSha)
 {
     logger.LogInformation("Load commit status of {0}", commitSha);
     return(loadContext.Factory.GetOrCreateLoader <string, ImmutableList <CommitStatus> >("GetUpstreamBranchGroups", async keys =>
     {
         logger.LogInformation("Loading {0} branch group upstream", keys.Distinct().Count());
         var result = await gitService.GetCommitStatuses(keys.Distinct().ToImmutableList());
         return keys.Distinct().ToDictionary(k => k, key => result.ContainsKey(key) ? result[key] : ImmutableList <CommitStatus> .Empty);
     }).LoadAsync(commitSha));
 }
        private async Task <IEnumerable <BranchGroupCompleteData> > GroupBranches(ImmutableList <BranchGroupCompleteData> settings, ImmutableList <GitRef> actualBranches, Func <string, Task <BranchGroupCompleteData> > factory)
        {
            var nonconfiguredBranches = new HashSet <GitRef>();
            var configuredBranches    = settings.ToDictionary(b => b.GroupName);
            var statuses = await gitApi.GetCommitStatuses(actualBranches.Select(b => b.Commit).ToImmutableList());

            foreach (var actualBranch in actualBranches)
            {
                var configured = false;
                foreach (var configuredBranch in configuredBranches.Values)
                {
                    if (branchIteration.IsBranchIteration(configuredBranch.GroupName, actualBranch.Name))
                    {
                        configuredBranch.Branches = configuredBranch.Branches?.Add(actualBranch) ?? Enumerable.Repeat(actualBranch, 1).ToImmutableList();
                        configuredBranch.Statuses = statuses[actualBranch.Commit];
                        configured = true;
                        break;
                    }
                }
                if (!configured)
                {
                    nonconfiguredBranches.Add(actualBranch);
                }
            }
            var nonconfiguredBranchesResult = await nonconfiguredBranches.ToObservable().SelectMany(async branch =>
            {
                var result      = await factory(branch.Name);
                result.Branches = result.Branches ?? Enumerable.Repeat(branch, 1).ToImmutableList();
                result.Statuses = ImmutableList <CommitStatus> .Empty;
                return(result);
            }).ToArray();

            return(configuredBranches.Values
                   .Select(group =>
            {
                group.Branches = group.Branches ?? ImmutableList <GitRef> .Empty;
                return group;
            })
                   .Concat(nonconfiguredBranchesResult));
        }