コード例 #1
0
        /// <summary>
        /// Gets the modifications.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to)
        {
            // fetch latest changes from the remote repository
            RepositoryAction result = CreateUpateLocalRepository(to);

            Dictionary <string, string> revisionData = NameValuePair.ToDictionary(from.SourceControlData);
            ProcessResult logResult;
            string        lastCommit;

            if (revisionData.TryGetValue(COMMIT_KEY, out lastCommit))
            {
                logResult = GitLogHistory(GetBranchNameOrRevision(Branch, Revision), lastCommit, to);
            }
            else
            {
                Log.Debug(string.Concat("[Git] last integrated commit not found, using all ancestors of ",
                                        GetBranchNameOrRevision(Branch, Revision), " as the set of modifications."));
                logResult = GitLogHistory(GetBranchNameOrRevision(Branch, Revision), to);
            }

            // Get the hash of the origin head, and store it against the integration result.
            string originHeadHash = GitLogOriginHash(GetBranchNameOrRevision(Branch, Revision), to);

            revisionData[COMMIT_KEY] = originHeadHash;
            to.SourceControlData.Clear();
            NameValuePair.Copy(revisionData, to.SourceControlData);

            return(ParseModifications(logResult, lastCommit));
        }
コード例 #2
0
        private void AssertIntegrationResultTaggedWithCommit(IIntegrationResult result, string commit)
        {
            Dictionary <string, string> data = NameValuePair.ToDictionary(result.SourceControlData);

            Assert.That(data.ContainsKey(GIT_COMMIT_KEY), "IntegrationResult.SourceControlData did not contain commit info.");
            Assert.That(data[GIT_COMMIT_KEY], Is.EqualTo(commit));
        }
コード例 #3
0
        private void WriteIntegrationProperties(IIntegrationResult result)
        {
            writer.WriteStartElement(Elements.IntegrationProps);

            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetArtifactDirectory],
                                     IntegrationPropertyNames.CCNetArtifactDirectory);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetBuildCondition],
                                     IntegrationPropertyNames.CCNetBuildCondition);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetBuildDate],
                                     IntegrationPropertyNames.CCNetBuildDate);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetBuildTime],
                                     IntegrationPropertyNames.CCNetBuildTime);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetFailureUsers],
                                     IntegrationPropertyNames.CCNetFailureUsers);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetFailureTasks],
                                     IntegrationPropertyNames.CCNetFailureTasks, "task");
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetIntegrationStatus],
                                     IntegrationPropertyNames.CCNetIntegrationStatus);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetLabel],
                                     IntegrationPropertyNames.CCNetLabel);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetLastIntegrationStatus],
                                     IntegrationPropertyNames.CCNetLastIntegrationStatus);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetListenerFile],
                                     IntegrationPropertyNames.CCNetListenerFile);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetModifyingUsers],
                                     IntegrationPropertyNames.CCNetModifyingUsers);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetNumericLabel],
                                     IntegrationPropertyNames.CCNetNumericLabel);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetProject],
                                     IntegrationPropertyNames.CCNetProject);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetProjectUrl],
                                     IntegrationPropertyNames.CCNetProjectUrl);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetRequestSource],
                                     IntegrationPropertyNames.CCNetRequestSource);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetWorkingDirectory],
                                     IntegrationPropertyNames.CCNetWorkingDirectory);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetUser],
                                     IntegrationPropertyNames.CCNetUser);
            WriteIntegrationProperty(result.IntegrationProperties[IntegrationPropertyNames.CCNetBuildId],
                                     IntegrationPropertyNames.CCNetBuildId);
            WriteIntegrationProperty(result.LastChangeNumber, "LastChangeNumber");
            WriteIntegrationProperty(result.LastIntegrationStatus, "LastIntegrationStatus");
            WriteIntegrationProperty(result.LastSuccessfulIntegrationLabel, "LastSuccessfulIntegrationLabel");
            WriteIntegrationProperty(result.LastModificationDate, "LastModificationDate");

            var buildParameters = NameValuePair.ToDictionary(result.Parameters);

            if (buildParameters.ContainsKey("CCNetForceBuildReason"))
            {
                WriteIntegrationProperty(buildParameters["CCNetForceBuildReason"], "CCNetForceBuildReason");
            }

            writer.WriteEndElement();
        }
コード例 #4
0
        public void ToDictionaryConvertsValues()
        {
            List <NameValuePair> pairs = new List <NameValuePair>();

            pairs.Add(new NameValuePair("name", "value"));
            Dictionary <string, string> dictionary = NameValuePair.ToDictionary(pairs);

            Assert.AreEqual(1, dictionary.Count);
            Assert.IsTrue(dictionary.ContainsKey("name"));
            Assert.AreEqual("value", dictionary["name"]);
        }
コード例 #5
0
        /// <summary>
        /// Checks if the trigger needs to actually fire.
        /// </summary>
        /// <returns></returns>
        public IntegrationRequest Fire()
        {
            var request = this.InnerTrigger.Fire();

            if (request != null)
            {
                var values = new List <NameValuePair>(this.Parameters ?? new NameValuePair[0]);
                request.BuildValues = NameValuePair.ToDictionary(values);
            }

            return(request);
        }
コード例 #6
0
ファイル: Svn.cs プロジェクト: xiaoyongaz/CruiseControl.NET
        /// <summary>
        /// Gets the modifications.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public override Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to)
        {
            var revisionData = NameValuePair.ToDictionary(from.SourceControlData);

            if (to.LastIntegrationStatus == IntegrationStatus.Unknown)
            {
                ((SvnHistoryParser)historyParser).IntegrationStatusUnknown = true;
            }

            string wd = Path.GetFullPath(to.BaseFromWorkingDirectory(WorkingDirectory));

            if (WorkingFolderIsKnownAsSvnWorkingFolder(wd))
            {
                if (CleanUp)
                {
                    Execute(CleanupWorkingCopy(to));
                }

                if (Revert)
                {
                    Execute(RevertWorkingCopy(to));
                }

                if (this.DeleteObstructions)
                {
                    this.DeleteObstructionsFromWorking(to);
                }
            }
            else
            {
                Util.Log.Warning(string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} is not a svn working folder", wd));
            }

            List <Modification> modifications  = new List <Modification>();
            List <string>       repositoryUrls = new List <string>();

            repositoryUrls.Add(TrunkUrl);

            if (CheckExternals)
            {
                ProcessResult resultOfSvnPropget = Execute(PropGetProcessInfo(to));
                List <string> externals          = ParseExternalsDirectories(resultOfSvnPropget);
                foreach (string external in externals)
                {
                    if (!repositoryUrls.Contains(external))
                    {
                        repositoryUrls.Add(external);
                    }
                }
            }

            foreach (string repositoryUrl in repositoryUrls)
            {
                var            lastRepositoryRevisionName = "SVN:LastRevision:" + repositoryUrl;
                Modification[] modsInRepository;
                string         lastRepositoryRevision = null;
                if (UseRevsionNumbers)
                {
                    // Since we are using the last revision number, see if there is any number stored to use
                    lastRepositoryRevision = revisionData.ContainsKey(lastRepositoryRevisionName)
                        ? revisionData[lastRepositoryRevisionName]
                        : null;
                    ProcessResult result = Execute(NewHistoryProcessInfoFromRevision(lastRepositoryRevision, to, repositoryUrl));
                    modsInRepository = ParseModifications(result, lastRepositoryRevision);
                }
                else
                {
                    // Use use the date range
                    ProcessResult result = Execute(NewHistoryProcessInfo(from, to, repositoryUrl));
                    modsInRepository = ParseModifications(result, from.StartTime, to.StartTime);
                }

                // If there are modifications, get the number and add them to the output
                if (modsInRepository != null)
                {
                    lastRepositoryRevision = Modification.GetLastChangeNumber(modsInRepository)
                                             ?? lastRepositoryRevision;
                    modifications.AddRange(modsInRepository);
                    revisionData[lastRepositoryRevisionName] = lastRepositoryRevision;
                }

                // Set the latest revision - this always need to be done just in case an external has triggered a build
                if (repositoryUrl == TrunkUrl)
                {
                    latestRevision = int.Parse(lastRepositoryRevision ?? "0", CultureInfo.CurrentCulture);
                    revisionData[lastRepositoryRevisionName] = lastRepositoryRevision;
                }
            }

            mods = modifications.ToArray();
            if (UrlBuilder != null)
            {
                UrlBuilder.SetupModification(mods);
            }
            FillIssueUrl(mods);

            // Store the latest revision number
            to.SourceControlData.Clear();
            NameValuePair.Copy(revisionData, to.SourceControlData);

            return(mods);
        }
コード例 #7
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());
        }
コード例 #8
0
        public void ToDictionaryHandlesNull()
        {
            Dictionary <string, string> dictionary = NameValuePair.ToDictionary(null);

            Assert.AreEqual(0, dictionary.Count);
        }