/// <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()); }
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; }
/// <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)); }
/// <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); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <summary> /// merge changeset /// </summary> /// <param name="changeset"></param> /// <param name="environment"></param> public MergeStatus MergeChangeset(Changeset changeset, MergeEnvironment environment) { return(_sourceDataAccess.MergeChangeset(changeset, environment)); }
/// <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()); }
/// <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()); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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) }); }