コード例 #1
0
        /// <summary>
        /// gets changesets for the specified merge environment
        /// </summary>
        /// <param name="workItem"></param>
        /// <param name="environment"></param>
        /// <returns></returns>
        public IEnumerable <Changeset> GetChangesets(IWorkItem workItem, MergeEnvironment environment)
        {
            var tfs         = TfsTeamDataAccess.GetTfsTeamProjectCollection();
            var tfsWorkItem = TfsTrackingDataAccess.GetTfsWorkItem(workItem.Id);

            return(GetTfsChangesetsBySource(tfs, tfsWorkItem, environment).ToList());
        }
コード例 #2
0
 public JsonMergeEnvironment(MergeEnvironment model)
 {
     name   = model.Name;
     source = new JsonEnvironment {
         value = model.Source
     };
     target = new JsonEnvironment {
         value = model.Target
     };
     states        = model.AllowedStates;
     relationships = model.Relationships != null?model.Relationships.Select(b => new JsonMergeRelationship(b)) : null;
 }
コード例 #3
0
        /// <summary>
        /// commits pending changes for a changeset that have been merged to the specified target and associates specified work items and comment
        /// </summary>
        /// <param name="changeset"></param>
        /// <param name="environment"></param>
        /// <param name="comment"></param>
        /// <returns></returns>
        public Changeset CommitChangeset(Changeset changeset, MergeEnvironment environment, string comment)
        {
            var tfs            = TfsTeamDataAccess.GetTfsTeamProjectCollection();
            var versionControl = tfs.GetService <VersionControlServer>();
            var workspace      = versionControl.GetWorkspace(Workstation.Current.Name, tfs.AuthorizedIdentity.UniqueName);
            var tfsChangeset   = versionControl.GetChangeset(changeset.Id);
            var changes        = (from change in tfsChangeset.Changes select change).ToList();
            var relationship   = GetMergeRelationship(changeset, environment);
            var pending        = workspace.GetPendingChanges(changes
                                                             .Select(m => new ItemSpec(m.Item.ServerItem.ToLower()
                                                                                       .Replace(string.Format("/{0}/", changeset.Branch.Name.ToLower()), string.Format("/{0}/", relationship.Target.Name)), RecursionType.None)).ToArray(), false, int.MaxValue, null, true).ToList();
            var pendingChangesetChanges = pending.ToArray();

            //.Where(p => p.IsMerge && p.MergeSources.Any(source => changes.Any(change => string.Compare(change.Item.ServerItem, source.ServerItem, StringComparison.OrdinalIgnoreCase) == 0))).ToArray();

            return(Commit(workspace, pendingChangesetChanges, comment, changeset.WorkItems));
        }
コード例 #4
0
        /// <summary>
        /// get merge candidates for a project and environment
        /// </summary>
        /// <param name="project"></param>
        /// <param name="environment"></param>
        /// <returns></returns>
        public IEnumerable <Changeset> GetMergeCandidates(Project project, MergeEnvironment environment)
        {
            var tfs            = TfsTeamDataAccess.GetTfsTeamProjectCollection();
            var projects       = TfsTeamDataAccess.GetTfsProjects().ToList();
            var versionControl = tfs.GetService <VersionControlServer>();

            var mergeCandidates = new List <Changeset>();

            projects.ForEach(tfsProject => environment.Relationships.ToList().ForEach(relationship =>
            {
                var projectName = !tfsProject.ServerItem.EndsWith("/") ? tfsProject.ServerItem + "/" : tfsProject.Name;
                var sourcePath  = string.Format("{0}{1}/", projectName, relationship.Source.Name);
                var targetPath  = string.Format("{0}{1}/", projectName, relationship.Target.Name);
                try
                {
                    var candidates = versionControl.GetMergeCandidates(sourcePath, targetPath, RecursionType.Full).ToList();
                    candidates.ForEach(candidate =>
                    {
                        var workItems =
                            candidate.Changeset.WorkItems.Where(
                                workItem =>
                                workItem.State != "Active" &&
                                workItem.State != "In Review" &&
                                workItem.Type != workItem.Project.WorkItemTypes["Task"] &&                                                         // ignore changesets associated with task. Will create another audit that checks for changesets ONLY associated to task.
                                string.Compare(project.Name, workItem.Project.Name, StringComparison.OrdinalIgnoreCase) == 0);
                        if (workItems.Any())
                        {
                            mergeCandidates.Add(MapChangeset(candidate.Changeset, relationship.Source));
                        }
                    });
                }
                catch (Exception e)
                {
                }
            }));

            return(mergeCandidates);
        }
コード例 #5
0
 /// <summary>
 /// get the list of changesets
 /// </summary>
 /// <param name="workItem"></param>
 /// <param name="environment"></param>
 public IEnumerable <Changeset> GetChangesets(IWorkItem workItem, MergeEnvironment environment)
 {
     return(_sourceDataAccess.GetChangesets(workItem, environment));
 }
コード例 #6
0
ファイル: Source.cs プロジェクト: Kidsisker/Push
        /// <summary>
        /// commit pending changes for a changeset that have been merged for the specified target using the provided data access instance
        /// </summary>
        /// <param name="dataAccess">the implementation of the data access to use when getting the data</param>
        /// <param name="environment"></param>
        /// <param name="comment"></param>
        /// <param name="changeset"></param>
        public static Changeset CommitChangeset(ISourceDataAccess dataAccess, Changeset changeset, MergeEnvironment environment, string comment)
        {
            var da = new Data.Source.SourceData(dataAccess);

            return(da.CommitChangeset(changeset, environment, comment));
        }
コード例 #7
0
ファイル: Source.cs プロジェクト: Kidsisker/Push
        /// <summary>
        /// merge changeset using provided data access instance
        /// </summary>
        /// <param name="dataAccess">the implementation of the data access to use when getting the data</param>
        /// <param name="changeset"></param>
        /// <param name="environment"></param>
        public static MergeStatus MergeChangeset(ISourceDataAccess dataAccess, Changeset changeset, MergeEnvironment environment)
        {
            var da = new Data.Source.SourceData(dataAccess);

            return(da.MergeChangeset(changeset, environment));
        }
コード例 #8
0
ファイル: Source.cs プロジェクト: Kidsisker/Push
        /// <summary>
        /// get merge candidates for a project and environment
        /// </summary>
        /// <param name="dataAccess"></param>
        /// <param name="project"></param>
        /// <param name="environment"></param>
        /// <returns></returns>
        public static IEnumerable <Changeset> GetMergeCandidates(ISourceDataAccess dataAccess, Project project, MergeEnvironment environment)
        {
            var da = new Data.Source.SourceData(dataAccess);

            return(da.GetMergeCandidates(project, environment));
        }
コード例 #9
0
 /// <summary>
 /// merge changeset
 /// </summary>
 /// <param name="changeset"></param>
 /// <param name="environment"></param>
 public MergeStatus MergeChangeset(Changeset changeset, MergeEnvironment environment)
 {
     return(_sourceDataAccess.MergeChangeset(changeset, environment));
 }
コード例 #10
0
        /// <summary>
        /// gets changesets for all work items of the specified state
        /// </summary>
        /// <param name="project"></param>
        /// <param name="state"></param>
        /// <param name="environment"></param>
        /// <returns></returns>
        public IEnumerable <Changeset> GetChangesetsByWorkItemState(Project project, string state, MergeEnvironment environment)
        {
            var tfs       = TfsTeamDataAccess.GetTfsTeamProjectCollection();
            var workItems = TfsTrackingDataAccess.GetTfsWorkItemsByState(tfs, project, state);

            return(workItems.SelectMany(w => GetTfsChangesetsBySource(tfs, w, environment)).ToList());
        }
コード例 #11
0
 /// <summary>
 /// gets changesets for a particular path (branch) and workitem
 /// </summary>
 /// <param name="tfs"></param>
 /// <param name="workItem"></param>
 /// <param name="environment"></param>
 private static IEnumerable <Changeset> GetTfsChangesetsBySource(TfsTeamProjectCollection tfs, TfsWorkItem workItem, MergeEnvironment environment)
 {
     return(environment.Relationships
            .SelectMany(relationship => GetTfsChangesetsByPathName(tfs, workItem, relationship.Source.Name)
                        .Select(c => MapChangeset(c, relationship.Source))).ToList());
 }
コード例 #12
0
 /// <summary>
 /// determines merge relationship for a changeset and target environment
 /// </summary>
 /// <param name="changeset"></param>
 /// <param name="environment"></param>
 /// <returns></returns>
 private static MergeRelationship GetMergeRelationship(Changeset changeset, MergeEnvironment environment)
 {
     return(GetMergeRelationship(changeset.Branch, environment));
 }
コード例 #13
0
 /// <summary>
 /// determines merge relationship for a branch and target environment
 /// </summary>
 /// <param name="branch"></param>
 /// <param name="environment"></param>
 /// <returns></returns>
 private static MergeRelationship GetMergeRelationship(Branch branch, MergeEnvironment environment)
 {
     return(environment.Relationships.ToList().Find(r => string.Compare(r.Source.Name, branch.Name, StringComparison.OrdinalIgnoreCase) == 0));
 }
コード例 #14
0
 /// <summary>
 /// get the list of changesets
 /// </summary>
 /// <param name="project"></param>
 /// <param name="state"></param>
 /// <param name="environment"></param>
 public IEnumerable <Changeset> GetChangesetsByWorkItemState(Project project, string state, MergeEnvironment environment)
 {
     return(_sourceDataAccess.GetChangesetsByWorkItemState(project, state, environment));
 }
コード例 #15
0
ファイル: Source.cs プロジェクト: Kidsisker/Push
        /// <summary>
        /// get changesets using provided data access instance
        /// </summary>
        /// <param name="dataAccess">the implementation of the data access to use when getting the data</param>
        /// <param name="workItem"></param>
        /// <param name="environment"></param>
        public static IEnumerable <Changeset> GetChangesets(ISourceDataAccess dataAccess, IWorkItem workItem, MergeEnvironment environment)
        {
            var da = new Data.Source.SourceData(dataAccess);

            return(da.GetChangesets(workItem, environment));
        }
コード例 #16
0
 /// <summary>
 /// get the list of merge candidates for a project and environment
 /// </summary>
 /// <param name="project"></param>
 /// <param name="environment"></param>
 /// <returns></returns>
 public IEnumerable <Changeset> GetMergeCandidates(Project project, MergeEnvironment environment)
 {
     return(_sourceDataAccess.GetMergeCandidates(project, environment));
 }
コード例 #17
0
ファイル: Source.cs プロジェクト: Kidsisker/Push
        /// <summary>
        /// get changesets using provided data access instance
        /// </summary>
        /// <param name="dataAccess">the implementation of the data access to use when getting the data</param>
        /// <param name="project"></param>
        /// <param name="state"></param>
        /// <param name="environment"></param>
        public static IEnumerable <Changeset> GetChangesetsByWorkItemState(ISourceDataAccess dataAccess, Project project, string state, MergeEnvironment environment)
        {
            var da = new Data.Source.SourceData(dataAccess);

            return(da.GetChangesetsByWorkItemState(project, state, environment));
        }
コード例 #18
0
 /// <summary>
 /// commit pending changes for a changeset that have been merged for the specified target
 /// </summary>
 /// <param name="changeset"></param>
 /// <param name="environment"></param>
 /// <param name="comment"></param>
 public Changeset CommitChangeset(Changeset changeset, MergeEnvironment environment, string comment)
 {
     return(_sourceDataAccess.CommitChangeset(changeset, environment, comment));
 }
コード例 #19
0
        /// <summary>
        /// merges a changeset for the specified environment
        /// </summary>
        /// <param name="changeset"></param>
        /// <param name="environment"></param>
        /// <returns></returns>
        public MergeStatus MergeChangeset(Changeset changeset, MergeEnvironment environment)
        {
            var tfs            = TfsTeamDataAccess.GetTfsTeamProjectCollection();
            var versionControl = tfs.GetService <VersionControlServer>();
            var workspace      = versionControl.GetWorkspace(Workstation.Current.Name, tfs.AuthorizedIdentity.UniqueName);
            var tfsChangeset   = versionControl.GetChangeset(changeset.Id);
            var statusList     = new List <MergeStatus>();

            tfsChangeset.Changes.ToList().ForEach(change =>
            {
                var sourcePath        = change.Item.ServerItem.Substring(0, change.Item.ServerItem.LastIndexOf("/", StringComparison.Ordinal));
                sourcePath            = !sourcePath.EndsWith("/") ? sourcePath + "/" : sourcePath;
                var mergeRelationship = GetMergeRelationship(changeset, environment);
                if (mergeRelationship == null)
                {
                    statusList.Add(new MergeStatus
                    {
                        NumFailures = 1,
                        Message     = string.Format("There are no merge relationships configured for {0}", changeset.Branch.Name)
                    });
                    return;
                }
                var targetPath = sourcePath.ToLower().Replace(string.Format("/{0}/", changeset.Branch.Name.ToLower()), string.Format("/{0}/", mergeRelationship.Target.Name));

                if (string.Compare(sourcePath, targetPath, StringComparison.OrdinalIgnoreCase) == 0)                         // this happens with feature branches. They will get picked up on next "changeset".
                {
                    return;
                }

                // Get Latest first
                string[] itemsSpec = { targetPath };
                workspace.Get(itemsSpec, VersionSpec.Latest, RecursionType.Full, GetOptions.Overwrite);

                // Get ready to Merge.
                MergeStatus status;
                var verSpec = new ChangesetVersionSpec(tfsChangeset.ChangesetId);
                try
                {
                    status = MapMergeStatus(workspace.Merge(sourcePath, targetPath, verSpec, verSpec, LockLevel.None, RecursionType.Full, MergeOptions.None));
                }
                catch (Exception e)
                {
                    status = new MergeStatus
                    {
                        NumFailures = 1,
                        Message     = e.Message
                    };
                }
                var conflicts = workspace.QueryConflicts(new[] { targetPath }, true);
                conflicts.ToList().ForEach(conflict =>
                {
                    workspace.MergeContent(conflict, false);
                    if (conflict.ContentMergeSummary.TotalConflicting > 0)
                    {
                        return;
                    }
                    // Conflict was resolved. Does not require a human!
                    conflict.Resolution = Resolution.AcceptMerge;
                    // If the conflict is successfully resolved, the IsResolved property is set to true.
                    // If resolving this conflict caused other conflicts to be deleted besides the current conflict, the list of other deleted conflicts appears in resolvedConflicts.
                    Conflict[] resolvedConflicts;
                    workspace.ResolveConflict(conflict, out resolvedConflicts);
                    if (!conflict.IsResolved)
                    {
                        return;
                    }

                    var totalResolved           = resolvedConflicts.Count();
                    status.NumResolvedConflicts = status.NumResolvedConflicts + 1 + totalResolved;
                    status.NumConflicts         = status.NumConflicts - 1 - totalResolved;
                });
                statusList.Add(status);
            });
            return(new MergeStatus             // create summary of all merges for this changeset
            {
                HaveResolvableWarnings = statusList.Any(s => s.HaveResolvableWarnings),
                NoActionNeeded = statusList.All(s => s.NoActionNeeded),
                NumBytes = statusList.Sum(s => s.NumBytes),
                NumConflicts = statusList.Sum(s => s.NumConflicts),
                NumFailures = statusList.Sum(s => s.NumFailures),
                NumFiles = statusList.Sum(s => s.NumFiles),
                NumOperations = statusList.Sum(s => s.NumOperations),
                NumResolvedConflicts = statusList.Sum(s => s.NumResolvedConflicts),
                NumUpdated = statusList.Sum(s => s.NumUpdated),
                NumWarnings = statusList.Sum(s => s.NumWarnings)
            });
        }