/// <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()); }
/// <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> /// commits changes for the local workspace and associates specified work items and comment /// </summary> /// <param name="workspace"></param> /// <param name="changes"></param> /// <param name="comment"></param> /// <param name="associatedWorkItems"></param> /// <returns></returns> private static Changeset Commit(Workspace workspace, PendingChange[] changes, string comment, IEnumerable <WorkItem> associatedWorkItems) { if (changes == null || !changes.Any()) { return(null); } var tfs = TfsTeamDataAccess.GetTfsTeamProjectCollection(); var versionControl = tfs.GetService <VersionControlServer>(); var associateTfsWorkItems = associatedWorkItems.Select(w => TfsTrackingDataAccess.GetTfsWorkItem(w.Id)) .GroupBy(g => g.Id) .Select(w => new WorkItemCheckinInfo(w.First(), WorkItemCheckinAction.Associate)).ToArray(); comment = string.Format("{0}: {1} {2}", string.Join(",", associateTfsWorkItems.OrderBy(o => o.WorkItem.Id).Select(a => a.WorkItem.Id.ToString(CultureInfo.InvariantCulture))), comment, ConfigurationManager.AppSettings["AutomationMessage"]); var changesetId = 0; try { changesetId = workspace.CheckIn(changes, comment, null, associateTfsWorkItems, null); } catch (GatedCheckinException gatedException) { // Gated check-in is required. Get the list of build definitions affected by the check-in var buildDefs = gatedException.AffectedBuildDefinitions; // Take first build def. I don't really have any better way to determine it. var buildEnum = buildDefs.GetEnumerator(); buildEnum.MoveNext(); var buildDef = buildEnum.Current; var gatedBuildDefUri = buildDef.Value; var shelvesetSpecName = gatedException.ShelvesetName; var shelvesetTokens = shelvesetSpecName.Split(new[] { ';' }); // Create a build request for the gated check-in build var buildServer = tfs.GetService <IBuildServer>(); var buildRequest = buildServer.CreateBuildRequest(gatedBuildDefUri); buildRequest.ShelvesetName = shelvesetTokens[0]; // Specify the name of the existing shelveset buildRequest.Reason = BuildReason.CheckInShelveset; // Check-in the shelveset if successful buildRequest.GatedCheckInTicket = gatedException.CheckInTicket; // Associate the check-in var build = TfsBuildDataAccess.QueueTfsBuild(buildRequest, null, true); if (build.Build != null) { var firstOrDefault = build.Build.Changesets.FirstOrDefault(); // shouldn't be null for gated check in, for pete's sake. if (firstOrDefault != null) { changesetId = firstOrDefault.Id; } if (build.Build.Status == BuildStatus.Succeeded) { workspace.Undo(changes); } } } var newTfsChangeset = versionControl.GetChangeset(changesetId); return(newTfsChangeset == null ? null : MapChangeset(newTfsChangeset)); }