internal void LoadBranchesToProcess() { List <Branch> branches = FindQueries.FindResolvedBranches( mRestApi, mBotConfig.Repository, mBotConfig.BranchPrefix ?? string.Empty, mBotConfig.PlasticStatusAttrConfig.Name, mBotConfig.PlasticStatusAttrConfig.ResolvedValue); List <Branch> alreadyTracked = new List <Branch>(); alreadyTracked.AddRange(mResolvedBranchesStorage.GetQueuedBranches()); alreadyTracked.AddRange(mReadyToMergeBranchesStorage.GetQueuedBranches()); FilterAlreadyTrackedBranches(branches, alreadyTracked); mResolvedBranchesStorage.Write(branches); }
internal void ProcessBranches(object state) { while (true) { Branch branch; lock (mSyncLock) { Monitor.Wait(mSyncLock, 5000); if (!mResolvedBranchesStorage.HasQueuedBranches()) { continue; } branch = mResolvedBranchesStorage.DequeueBranch(); branch.FullName = FindQueries.GetBranchName(mRestApi, branch.Repository, branch.Id); } mLog.InfoFormat( "Checking if branch {0} has merge conflicts with {1} branch...", branch.FullName, mBotConfig.TrunkBranch); string taskNumber = GetTaskNumber( Branch.GetShortName(branch.FullName), mBotConfig.BranchPrefix); if (string.IsNullOrEmpty(taskNumber)) { mLog.WarnFormat("Unable to calculate the task number of branch {0}. Tracked branch prefix:{1}", branch.FullName, mBotConfig.BranchPrefix); continue; } if (!HasToTriggerTryMerge( mRestApi, taskNumber, mBotConfig.IssueTrackerConfig)) { mLog.InfoFormat("Branch {0} is not ready to trigger a try-merge. It will be queued again.", branch.FullName); lock (mSyncLock) { mResolvedBranchesStorage.EnqueueBranch(branch); } continue; } BranchMerger.Result result = BranchMerger.Try( mRestApi, branch.Repository, branch.FullName, mBotConfig.TrunkBranch); if (result == null) //branch already merged! { continue; } MergeReporter.NotifyMerge( mRestApi, mBotName, branch.Repository, branch.FullName, result.HasManualConflicts, result.Message); string notifyMessage = string.Empty; if (!result.HasManualConflicts) { mLog.InfoFormat( "Branch {0} has no manual conflicts with {1} at this repository state.", branch.FullName, mBotConfig.TrunkBranch); notifyMessage = string.Format( "Branch {0} has no manual conflicts with branch {1} and is able to be merged so far.", branch.FullName, mBotConfig.TrunkBranch); Notifier.Notify(mRestApi, branch.Owner, notifyMessage, mBotConfig.NotifierConfig, true); lock (mSyncLock) { mReadyToMergeBranchesStorage.EnqueueBranch(branch); } continue; } mLog.InfoFormat( "Branch {0} has manual conflicts with branch {1}.", branch.FullName, mBotConfig.TrunkBranch); string extraIssueTrackerMessage = mBotConfig.IssueTrackerConfig == null ? string.Empty : string.Format( "and the {0} plug's issue tracker field of {1} {2} to {3}", mBotConfig.IssueTrackerConfig.PlugName, mBotConfig.IssueTrackerConfig.ProjectKey, taskNumber, mBotConfig.IssueTrackerConfig.StatusField.ResolvedValue); notifyMessage = string.Format( "Branch {0} has manual conflicts with branch {1} and cannot be merged. " + Environment.NewLine + Environment.NewLine + "Please run a merge from branch {1} to branch {0} in your plastic workspace " + "and resolve these manual conflicts. " + Environment.NewLine + "Then, enqueue the branch {0} again by setting the {2} attribute of the {0} branch to {3} {4}", branch.FullName, mBotConfig.TrunkBranch, mBotConfig.PlasticStatusAttrConfig.Name, mBotConfig.PlasticStatusAttrConfig.ResolvedValue, extraIssueTrackerMessage); Notifier.Notify(mRestApi, branch.Owner, notifyMessage, mBotConfig.NotifierConfig, false); StatusUpdater.UpdateBranchAttribute( mRestApi, branch.Repository, branch.FullName, mBotConfig.PlasticStatusAttrConfig.Name, mBotConfig.PlasticStatusAttrConfig.FailedValue); if (mBotConfig.IssueTrackerConfig != null) { StatusUpdater.UpdateIssueTrackerField( mRestApi, mBotConfig.IssueTrackerConfig.PlugName, mBotConfig.IssueTrackerConfig.ProjectKey, taskNumber, mBotConfig.IssueTrackerConfig.StatusField.Name, mBotConfig.IssueTrackerConfig.StatusField.FailedValue); } } }