static bool IsFailedMergeTo(MergeToResponse mergeBranchResult)
 {
     return(mergeBranchResult.Status == MergeToResultStatus.AncestorNotFound ||
            mergeBranchResult.Status == MergeToResultStatus.Conflicts ||
            mergeBranchResult.Status == MergeToResultStatus.Error ||
            mergeBranchResult.ChangesetNumber == 0);
 }
Esempio n. 2
0
        internal static bool TryMergeToShelve(
            RestApi restApi,
            Branch branch,
            string destinationBranch,
            MergeReport mergeReport,
            string comment,
            string taskNumber,
            TrunkBotConfiguration botConfig,
            string codeReviewsStorageFile,
            out int shelveId)
        {
            shelveId = -1;

            MergeToResponse result = TrunkMergebotApi.MergeBranchTo(
                restApi, branch.Repository, branch.FullName, destinationBranch,
                comment, TrunkMergebotApi.MergeToOptions.CreateShelve);

            if (result.Status == MergeToResultStatus.MergeNotNeeded)
            {
                ChangeTaskStatus.SetTaskAsMerged(
                    restApi,
                    branch,
                    taskNumber,
                    string.Format(
                        "Branch {0} was already merged to {1} (MergeNotNeeded).",
                        branch.FullName,
                        botConfig.TrunkBranch),
                    botConfig,
                    codeReviewsStorageFile);
                return(false);
            }

            if (result.Status == MergeToResultStatus.AncestorNotFound ||
                result.Status == MergeToResultStatus.Conflicts ||
                result.Status == MergeToResultStatus.Error ||
                result.ChangesetNumber == 0)
            {
                BuildMergeReport.AddFailedMergeProperty(mergeReport, result.Status, result.Message);
                ChangeTaskStatus.SetTaskAsFailed(
                    restApi,
                    branch,
                    taskNumber,
                    string.Format(
                        "Can't merge branch {0}. Reason: {1}",
                        branch.FullName, result.Message),
                    botConfig,
                    codeReviewsStorageFile);
                return(false);
            }

            shelveId = result.ChangesetNumber;
            BuildMergeReport.AddSucceededMergeProperty(mergeReport, result.Status);

            return(true);
        }
        internal static ShelveResult TryMergeToShelves(
            IRestApi restApi,
            Branch branch,
            string[] destinationBranches,
            MergeReport mergeReport,
            string taskTitle,
            string botName)
        {
            ShelveResult result = new ShelveResult();

            foreach (string destinationBranch in destinationBranches)
            {
                MergeToResponse mergeToResult = MultilinerMergebotApi.MergeBranchTo(
                    restApi,
                    branch.Repository,
                    branch.FullName,
                    destinationBranch,
                    GetComment(branch.FullName, destinationBranch, taskTitle, botName),
                    MultilinerMergebotApi.MergeToOptions.CreateShelve);

                result.MergeStatusByTargetBranch[destinationBranch] = mergeToResult.Status;

                if (mergeToResult.Status == MergeToResultStatus.MergeNotNeeded)
                {
                    string warningMessage = string.Format(
                        "Branch [{0}] was already merged to [{1}] (No merge needed).",
                        branch.FullName,
                        destinationBranch);

                    result.MergesNotNeededMessages.Add(warningMessage);
                    continue;
                }

                if (IsFailedMergeTo(mergeToResult))
                {
                    string errorMsg = string.Format(
                        "Can't merge branch [{0}] to [{1}]. Reason: {2}.",
                        branch.FullName,
                        destinationBranch,
                        mergeToResult.Message);

                    result.ErrorMessages.Add(errorMsg);

                    BuildMergeReport.AddFailedMergeProperty(
                        mergeReport, mergeToResult.Status, mergeToResult.Message);

                    continue;
                }

                result.ShelvesByTargetBranch[destinationBranch] = mergeToResult.ChangesetNumber;
                BuildMergeReport.AddSucceededMergeProperty(mergeReport, mergeToResult.Status);
            }
            return(result);
        }
Esempio n. 4
0
        internal static bool TryApplyShelve(
            RestApi restApi,
            Branch branch,
            string destinationBranch,
            MergeReport mergeReport,
            string comment,
            string taskNumber,
            int shelveId,
            TrunkBotConfiguration botConfig,
            string codeReviewsStorageFile,
            out int csetId)
        {
            MergeToResponse mergeResult = TrunkMergebotApi.MergeShelveTo(
                restApi, branch.Repository, shelveId, destinationBranch,
                comment, TrunkMergebotApi.MergeToOptions.EnsureNoDstChanges);

            csetId = mergeResult.ChangesetNumber;
            BuildMergeReport.UpdateMergeProperty(mergeReport, mergeResult.Status, csetId);

            if (mergeResult.Status == MergeToResultStatus.OK)
            {
                return(true);
            }

            if (mergeResult.Status == MergeToResultStatus.DestinationChanges)
            {
                // it should checkin the shelve only on the exact parent shelve cset.
                // if there are new changes in the trunk branch enqueue againg the task
                return(false);
            }

            ChangeTaskStatus.SetTaskAsFailed(
                restApi,
                branch,
                taskNumber,
                string.Format(
                    "Can't merge branch {0}. Reason: {1}",
                    branch.FullName,
                    mergeResult.Message),
                botConfig,
                codeReviewsStorageFile);

            return(false);
        }
        internal static CheckinResult TryApplyShelves(
            IRestApi restApi,
            Branch branch,
            string[] destinationBranches,
            ShelveResult shelves,
            MergeReport mergeReport,
            string taskNumber,
            string taskTitle,
            string botName,
            MultilinerBotConfiguration botConfig,
            string codeReviewsStorageFile)
        {
            CheckinResult result = new CheckinResult();
            int           shelveId;

            foreach (string destinationBranch in destinationBranches)
            {
                if (!shelves.ShelvesByTargetBranch.ContainsKey(destinationBranch))
                {
                    continue;
                }

                shelveId = shelves.ShelvesByTargetBranch[destinationBranch];

                mLog.InfoFormat(
                    "Checking-in shelveset [{0}] from branch [{1}] to [{2}]",
                    shelveId, branch.FullName, destinationBranch);

                MergeToResponse mergeResult = MultilinerMergebotApi.MergeShelveTo(
                    restApi,
                    branch.Repository,
                    shelveId,
                    destinationBranch,
                    GetComment(branch.FullName, destinationBranch, taskTitle, botName),
                    MultilinerMergebotApi.MergeToOptions.EnsureNoDstChanges);

                result.MergeStatusByTargetBranch[destinationBranch] = mergeResult.Status;

                BuildMergeReport.UpdateMergeProperty(mergeReport, mergeResult.Status, mergeResult.ChangesetNumber);

                if (mergeResult.Status == MergeToResultStatus.OK)
                {
                    result.ChangesetsByTargetBranch[destinationBranch] = mergeResult.ChangesetNumber;

                    mLog.InfoFormat(
                        "Checkin: Created changeset [{0}] in branch [{1}]",
                        mergeResult.ChangesetNumber, destinationBranch);

                    continue;
                }

                if (mergeResult.Status == MergeToResultStatus.DestinationChanges)
                {
                    string dstWarnMessage = string.Format(
                        "Can't checkin shelve [{0}], the resulting shelve from merging branch " +
                        "[{1}] to [{2}]. Reason: new changesets appeared in destination branch " +
                        "while mergebot {3} was processing the merge from [{1}] to [{2}].{4}{5}",
                        shelveId,
                        branch.FullName,
                        destinationBranch,
                        botName,
                        Environment.NewLine,
                        mergeResult.Message);

                    // it should checkin the shelve only on the exact parent shelve cset.
                    // if there are new changes in the destination branch enqueue again the task
                    result.DestinationNewChangesWarnings.Add(dstWarnMessage);
                    continue;
                }

                string errorMsg = string.Format(
                    "Can't checkin shelve [{0}], the resulting shelve from merging branch " +
                    "[{1}] to [{2}]. Reason: {3}",
                    shelveId,
                    branch.FullName,
                    destinationBranch,
                    mergeResult.Message);

                result.ErrorMessages.Add(errorMsg);
            }

            return(result);
        }