Esempio n. 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);
        }
Esempio n. 2
0
        public override Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to)
        {
            Dictionary <string, string> dictionary = NameValuePair.ToDictionary(from.SourceControlData);
            IList <Modification>        changeList = new List <Modification>();

            InitProcessData(to);
            InitGitRepository(to);

            git.Reset(to, Branch);
            git.Reset(to, StartBranch);

            git.FetchOrigin(to);

            // StartBranch
            git.Checkout(to, StartBranch);
            var diffOriginStartBranch = git.GetDiffList(to, $"origin/{StartBranch}");
            var startBranchPullResult = git.Pull(to);

            foreach (var item in startBranchPullResult.Item2)
            {
                changeList.Add(item);
            }

            // Branch
            git.Checkout(to, Branch);
            var diffOriginBranch = git.GetDiffList(to, $"origin/{Branch}");
            var branchPullResult = git.Pull(to);

            foreach (var item in branchPullResult.Item2)
            {
                changeList.Add(item);
            }

            if (changeList.Count == 0 && from.LastBuildStatus != IntegrationStatus.Success)
            {
                foreach (var change in from.Modifications)
                {
                    changeList.Add(change);
                }
            }

            if (isFirstRun || from.LastBuildStatus != IntegrationStatus.Success)
            {
                if (changeList.Count == 0)
                {
                    changeList.Add(new Modification
                    {
                        ChangeNumber = "Initialize",
                        Comment      = "Initialize",
                        FileName     = "",
                        FolderName   = "",
                        ModifiedTime = DateTime.MinValue,
                        EmailAddress = "Initialize",
                        UserName     = "******",
                        Type         = "Unmodified"
                    });
                }
            }

            to.SourceControlData.Clear();
            NameValuePair.Copy(dictionary, to.SourceControlData);
            to.SetSourceData("$TqGitCI_repository", gitUrl);
            to.SetSourceData("$TqGitCI_gitDirectory", gitDirectory);
            to.SetSourceData("$TqGitCI_branch", Branch);
            to.SetSourceData("$TqGitCI_startBranch", StartBranch);
            to.SetSourceData("$TqGitCI_projectName", projectName);
            to.SetSourceData("$TqGitCI_hasDiffOrigin1", (diffOriginBranch.Count > 0).ToString());
            to.SetSourceData("$TqGitCI_pullResult1", branchPullResult.Item1.Status.ToString());
            to.SetSourceData("$TqGitCI_lastCommitter1", branchPullResult.Item2.LastOrDefault()?.UserName ?? string.Empty);
            to.SetSourceData("$TqGitCI_hasDiffOrigin2", (diffOriginStartBranch.Count > 0).ToString());
            to.SetSourceData("$TqGitCI_pullResult2", startBranchPullResult.Item1.Status.ToString());
            to.SetSourceData("$TqGitCI_lastCommitter2", startBranchPullResult.Item2.LastOrDefault()?.UserName ?? string.Empty);

            to.SetParameters("$TqGitCI_gitUserId", GitUserId);
            to.SetParameters("$TqGitCI_gitUserPassword", GitUserPassword);

            return(changeList.ToArray());
        }