Exemple #1
0
        internal static void NotifyTaskStatus(
            RestApi restApi,
            string owner,
            string message,
            TrunkBotConfiguration.Notifier notificationsConfig)
        {
            if (notificationsConfig == null)
            {
                return;
            }

            try
            {
                List <string> recipients = GetNotificationRecipients(
                    restApi, owner, notificationsConfig);

                TrunkMergebotApi.Notify.Message(
                    restApi, notificationsConfig.Plug, message, recipients);
            }
            catch (Exception e)
            {
                mLog.ErrorFormat("Error notifying task status message '{0}'. Error: {1}",
                                 message, e.Message);
                mLog.DebugFormat("StackTrace:{0}{1}", Environment.NewLine, e.StackTrace);
            }
        }
Exemple #2
0
        static List <string> GetNotificationRecipients(
            RestApi restApi,
            string owner,
            TrunkBotConfiguration.Notifier notificationsConfig)
        {
            List <string> recipients = new List <string>();

            recipients.Add(owner);

            if (notificationsConfig.FixedRecipients != null)
            {
                recipients.AddRange(notificationsConfig.FixedRecipients);
            }

            return(ResolveUserProfile.ResolveFieldForUsers(
                       restApi, recipients, notificationsConfig.UserProfileField));
        }
Exemple #3
0
        internal static void NotifyException(
            RestApi restApi,
            Branch branch,
            string message,
            string taskStatus,
            Exception exception,
            TrunkBotConfiguration.Notifier notificationsConfig)
        {
            string exMessage = string.Format(
                "There was an error setting the branch '{0}' as '{1}'. " +
                "Error: {2}. Inner error: {3}",
                branch.FullName, taskStatus, exception.Message, message);

            NotifyTaskStatus(
                restApi, branch.Owner, exMessage,
                notificationsConfig);
        }
Exemple #4
0
        static bool CreateLabel(
            RestApi restApi,
            int csetId,
            string branchFullName,
            string trunkBranchName,
            string repository,
            bool isAutoLabelEnabled,
            string automaticLabelPattern,
            MergeReport mergeReport,
            string branchOwner,
            TrunkBotConfiguration.Notifier notificationsConfig,
            out string labelCreated)
        {
            labelCreated = string.Empty;

            if (!isAutoLabelEnabled)
            {
                return(true);
            }

            if (string.IsNullOrEmpty(automaticLabelPattern))
            {
                return(true);
            }

            AutomaticLabeler.Result result = null;
            try
            {
                result = AutomaticLabeler.CreateLabel(
                    restApi, csetId, repository, automaticLabelPattern, DateTime.Now);
            }
            catch (Exception e)
            {
                mLog.ErrorFormat(
                    "An error occurred labeling the merged branch {0} in changeset {1}@{2}: {3}",
                    branchFullName,
                    csetId,
                    repository,
                    e.Message);

                if (result == null)
                {
                    result = new AutomaticLabeler.Result(false, string.Empty, e.Message);
                }
            }

            labelCreated = result.Name;

            BuildMergeReport.AddLabelProperty(
                mergeReport, result.IsSuccessful, result.Name, result.ErrorMessage);

            string message = result.IsSuccessful ?
                             string.Format(
                "Label {0} created successfully in {1} branch, changeset cs:{2}@{3}",
                labelCreated, trunkBranchName, csetId, repository) :
                             string.Format(
                "Failed to create label after merging branch {0} " +
                "in {1} branch, changeset cs:{2}@{3}. Error: {4}",
                branchFullName, trunkBranchName, csetId, repository, result.ErrorMessage);

            Notifier.NotifyTaskStatus(restApi, branchOwner, message, notificationsConfig);
            return(result.IsSuccessful);
        }