Example #1
0
        protected override bool Execute(IIntegrationResult result)
        {
            string repository      = result.GetSourceData("$TqGitCI_repository");
            string gitDirectory    = result.GetSourceData("$TqGitCI_gitDirectory");
            string branch          = result.GetSourceData("$TqGitCI_branch");
            string startBranch     = result.GetSourceData("$TqGitCI_startBranch");
            string projectName     = result.GetSourceData("$TqGitCI_projectName");
            string gitUserId       = result.GetParameters("$TqGitCI_gitUserId");
            string gitUserPassword = result.GetParameters("$TqGitCI_gitUserPassword");

            git = new GitUtil(projectName, gitDirectory, repository, gitUserId, gitUserPassword);

            // Branch
            git.Checkout(result, branch);
            var diffBranchAndStartBranch = git.GetDiffList(result, startBranch);

            if (diffBranchAndStartBranch.Count > 0)
            {
                var mergeResult = git.Merge(result, startBranch);
                result.SetSourceData("$TqGitCI_mergeResult", mergeResult.Status.ToString());
                result.SetParameters("$TqGitCI_mergeResult", mergeResult.Status.ToString());
                if (mergeResult.Status == MergeStatus.Conflicts)
                {
                    var conflictsList = git.GetConflictsList(result);
                    result.SetSourceData("$TqGitCI_mergeExceptionMessage", $"{projectName} Conflicts({conflictsList.Count}) {branch} <- {startBranch}");
                    result.SetParameters("$TqGitCI_mergeExceptionMessage", $"{projectName} Conflicts({conflictsList.Count}) {branch} <- {startBranch}");
                    return(false);
                }
            }
            return(true);
        }
        private string GetMessage(IIntegrationResult result)
        {
            StringBuilder msg = new StringBuilder(Message);

            msg.AppendLine();

            switch (MessageTemplate)
            {
            case "TqGitCI":
                if (result.Succeeded)
                {
                    msg.AppendLine($"CI Success");
                    return(string.Empty);
                }
                else
                {
                    msg.AppendLine($"CI Failure");

                    var errMsg = result.GetParameters("$TqGitCI_mergeResult") ?? string.Empty;
                    if (!string.IsNullOrEmpty(errMsg))
                    {
                        msg.AppendLine(errMsg);
                    }
                    errMsg = result.GetParameters("$TqGitCI_mergeExceptionMessage") ?? string.Empty;
                    if (!string.IsNullOrEmpty(errMsg))
                    {
                        msg.AppendLine(errMsg);
                    }
                    msg.Append(GetFailureTaskMessage(result));
                    return(msg.ToString());
                }

            case "TqBuild":
                if (result.Succeeded)
                {
                    msg.AppendLine($"Build And Deploy Success");
                    return(msg.ToString());
                }
                else
                {
                    msg.AppendLine($"Build And Deploy Failure");
                    msg.Append(GetFailureTaskMessage(result));
                    return(string.Empty);
                }

            default:
                msg.Append(GetFailureTaskMessage(result));
                return(msg.ToString());
            }
        }