/// <summary>
        /// Calculate difference between two WorkflowDetails objects
        /// </summary>
        private TwoListDifference <MergeRequest> getMergeRequestDiff(string hostname,
                                                                     List <Project> enabledProjects, IWorkflowDetails oldDetails, IWorkflowDetails newDetails)
        {
            TwoListDifference <MergeRequest> diff = new TwoListDifference <MergeRequest>
            {
                FirstOnly  = new List <MergeRequest>(),
                SecondOnly = new List <MergeRequest>(),
                Common     = new List <MergeRequest>()
            };

            foreach (var project in enabledProjects)
            {
                ProjectKey key = new ProjectKey {
                    HostName = hostname, ProjectId = project.Id
                };
                List <MergeRequest> previouslyCachedMergeRequests = oldDetails.GetMergeRequests(key);
                List <MergeRequest> newCachedMergeRequests        = newDetails.GetMergeRequests(key);

                diff.FirstOnly.AddRange(previouslyCachedMergeRequests.Except(newCachedMergeRequests).ToList());
                diff.SecondOnly.AddRange(newCachedMergeRequests.Except(previouslyCachedMergeRequests).ToList());
                diff.Common.AddRange(previouslyCachedMergeRequests.Intersect(newCachedMergeRequests).ToList());
            }

            return(diff);
        }
Esempio n. 2
0
        /// <summary>
        /// Cache passed merge requests
        /// </summary>
        private void cacheMergeRequests(string hostname, Project project, List <MergeRequest> mergeRequests)
        {
            ProjectKey key = getProjectKey(hostname, project.Id);

            InternalDetails.SetProjectName(key, project.Path_With_Namespace);

            List <MergeRequest> previouslyCachedMergeRequests = InternalDetails.GetMergeRequests(key);

            InternalDetails.SetMergeRequests(key, mergeRequests);

            Trace.TraceInformation(String.Format(
                                       "[WorkflowDetailsCache] Number of cached merge requests for project {0} at {1} is {2} (was {3} before update)",
                                       project.Path_With_Namespace, hostname, mergeRequests.Count, previouslyCachedMergeRequests.Count));

            cleanupOldRecords(previouslyCachedMergeRequests, mergeRequests);
        }
Esempio n. 3
0
        /// <summary>
        /// Load merge requests from GitLab and cache them
        /// </summary>
        async private Task cacheMergeRequestsAsync(string hostname, Project project)
        {
            ProjectKey key = getProjectKey(hostname, project.Id);

            InternalDetails.SetProjectName(key, project.Path_With_Namespace);

            List <MergeRequest> mergeRequests;

            try
            {
                mergeRequests = await Operator.GetMergeRequestsAsync(hostname, InternalDetails.GetProjectName(key));
            }
            catch (OperatorException ex)
            {
                ExceptionHandlers.Handle(ex, String.Format("Cannot load merge requests for project Id {0}", project.Id));
                return; // silent return
            }

            cacheMergeRequests(hostname, project, mergeRequests);
        }
Esempio n. 4
0
        /// <summary>
        /// Convert a list of Project Id to list of Project names
        /// </summary>
        private List <ProjectUpdate> getProjectUpdates(List <MergeRequest> mergeRequests, string hostname,
                                                       IWorkflowDetails details)
        {
            List <ProjectUpdate> projectUpdates = new List <ProjectUpdate>();

            // Check all the updated merge request to figure out the latest change among them
            DateTime updateTimestamp = DateTime.MinValue;

            foreach (MergeRequest mergeRequest in mergeRequests)
            {
                ProjectKey key = new ProjectKey {
                    HostName = hostname, ProjectId = mergeRequest.Project_Id
                };
                string projectName = details.GetProjectName(key);

                // Excluding duplicates
                for (int iUpdate = projectUpdates.Count - 1; iUpdate >= 0; --iUpdate)
                {
                    if (projectUpdates[iUpdate].ProjectName == projectName)
                    {
                        projectUpdates.RemoveAt(iUpdate);
                    }
                }

                updateTimestamp = details.GetLatestChangeTimestamp(mergeRequest.Id) > updateTimestamp?
                                  details.GetLatestChangeTimestamp(mergeRequest.Id) : updateTimestamp;

                projectUpdates.Add(
                    new ProjectUpdate
                {
                    HostName    = hostname,
                    ProjectName = projectName,
                    Timestamp   = updateTimestamp
                });
            }

            return(projectUpdates);
        }
Esempio n. 5
0
 /// <summary>
 /// Sets a list of merge requests for the given project
 /// </summary>
 internal void SetMergeRequests(ProjectKey key, List <MergeRequest> mergeRequests)
 {
     MergeRequests[key] = mergeRequests;
 }
Esempio n. 6
0
 /// <summary>
 /// Return a list of merge requests by unique project id
 /// </summary>
 public List <MergeRequest> GetMergeRequests(ProjectKey key)
 {
     return(MergeRequests.ContainsKey(key) ? MergeRequests[key] : new List <MergeRequest>());
 }
Esempio n. 7
0
 /// <summary>
 /// Add a project name/id pair to the cache
 /// </summary>
 internal void SetProjectName(ProjectKey key, string name)
 {
     ProjectNames[key] = name;
 }
Esempio n. 8
0
 /// <summary>
 /// Return project name (Path_With_Namespace) by unique project Id
 /// </summary>
 public string GetProjectName(ProjectKey key)
 {
     Debug.Assert(ProjectNames.ContainsKey(key));
     return(ProjectNames.ContainsKey(key) ? ProjectNames[key] : String.Empty);
 }