public void ShouldConvertToModification()
		{
			var hgMod = new MercurialModification
			{
				ChangeNumber = 100,
				Comment = Guid.NewGuid().ToString(),
				EmailAddress = Guid.NewGuid().ToString(),
				FileName = Guid.NewGuid().ToString(),
				FolderName = Guid.NewGuid().ToString(),
				ModifiedTime = DateTime.UtcNow,
				UserName = Guid.NewGuid().ToString(),
				Version = Guid.NewGuid().ToString()
			};

			var ccnetMod = (Modification) hgMod;

			Assert.That(ccnetMod.ChangeNumber, Is.EqualTo(hgMod.ChangeNumber.ToString()));
			Assert.That(ccnetMod.Comment, Is.EqualTo(hgMod.Comment));
			Assert.That(ccnetMod.EmailAddress, Is.EqualTo(hgMod.EmailAddress));
			Assert.That(ccnetMod.FileName, Is.EqualTo(hgMod.FileName));
			Assert.That(ccnetMod.FolderName, Is.EqualTo(hgMod.FolderName));
			Assert.That(ccnetMod.ModifiedTime, Is.EqualTo(hgMod.ModifiedTime));
			Assert.That(ccnetMod.UserName, Is.EqualTo(hgMod.UserName));
			Assert.That(ccnetMod.Version, Is.EqualTo(hgMod.Version));
		}
		public Modification[] Parse(TextReader history, DateTime from, DateTime to)
		{
			var mods = new List<Modification>();

			var doc = new XmlDocument();
			try
			{
				doc.LoadXml(history.ReadToEnd());
			}
			catch( Exception ex )
			{
				throw new CruiseControlException("Unable to parse Mercurial history. Expected to get XML from the `hg log --style xml -v` command.", ex);
			}

			var logEntries = doc.SelectNodes("/log/logentry");
			if( logEntries == null )
			{
				return mods.ToArray();
			}

			foreach (XmlElement logEntry in logEntries)
			{
				var revision = 0;
				var revisionAttr = logEntry.Attributes["revision"];
				if( revisionAttr != null )
				{
					Int32.TryParse(revisionAttr.Value, out revision);
				}

				var nodeAttr = logEntry.Attributes["node"];
				var node = "";
				if( nodeAttr != null )
				{
					node = nodeAttr.Value;
				}

				var authorNode = logEntry["author"];
				string email = "", username = "";
				if (authorNode != null)
				{
					email = authorNode.Attributes["email"].Value;
					if (!string.IsNullOrEmpty(authorNode.InnerText))
					{
						username = authorNode.InnerText;
					}
					else
					{
						username = (email.Contains("@"))
							? email.Substring(0, email.IndexOf('@'))
							: email;
					}
				}

				var dateNode = logEntry["date"];
				DateTime modifiedAt = DateTime.MinValue;
				if (dateNode != null)
				{
					DateTime.TryParse(dateNode.InnerText, out modifiedAt);
				}

				var commentNode = logEntry["msg"];
				var comment = "";
				if( commentNode != null )
				{
					comment = commentNode.InnerText;
				}

				var pathsNode = logEntry["paths"];
				if (pathsNode == null || pathsNode.ChildNodes.Count == 0)
				{
					continue;
				}

				foreach (XmlElement fileNode in pathsNode.ChildNodes)
				{
					var path = fileNode.InnerText;

					var mod = new MercurialModification
					{
						ChangeNumber = revision,
						Comment = comment,
						EmailAddress = email,
						FileName = Path.GetFileName(path),
						FolderName = Path.GetDirectoryName(path),
						ModifiedTime = modifiedAt,
						UserName = username,
						Version = node
					};
					mods.Add(mod);
				}
			}
			return mods.ToArray();
		}
Ejemplo n.º 3
0
        public Modification[] Parse(TextReader history, DateTime from, DateTime to)
        {
            var mods = new List <Modification>();

            var doc = new XmlDocument();

            try
            {
                doc.LoadXml(history.ReadToEnd());
            }
            catch (Exception ex)
            {
                throw new CruiseControlException("Unable to parse Mercurial history. Expected to get XML from the `hg log --style xml -v` command.", ex);
            }

            var logEntries = doc.SelectNodes("/log/logentry");

            if (logEntries == null)
            {
                return(mods.ToArray());
            }

            foreach (XmlElement logEntry in logEntries)
            {
                var revision     = 0;
                var revisionAttr = logEntry.Attributes["revision"];
                if (revisionAttr != null)
                {
                    Int32.TryParse(revisionAttr.Value, out revision);
                }

                var nodeAttr = logEntry.Attributes["node"];
                var node     = "";
                if (nodeAttr != null)
                {
                    node = nodeAttr.Value;
                }

                var    authorNode = logEntry["author"];
                string email = "", username = "";
                if (authorNode != null)
                {
                    email = authorNode.Attributes["email"].Value;
                    if (!string.IsNullOrEmpty(authorNode.InnerText))
                    {
                        username = authorNode.InnerText;
                    }
                    else
                    {
                        username = (email.Contains("@"))
                                                        ? email.Substring(0, email.IndexOf('@'))
                                                        : email;
                    }
                }

                var      dateNode   = logEntry["date"];
                DateTime modifiedAt = DateTime.MinValue;
                if (dateNode != null)
                {
                    DateTime.TryParse(dateNode.InnerText, out modifiedAt);
                }

                var commentNode = logEntry["msg"];
                var comment     = "";
                if (commentNode != null)
                {
                    comment = commentNode.InnerText;
                }

                var pathsNode = logEntry["paths"];
                if (pathsNode == null || pathsNode.ChildNodes.Count == 0)
                {
                    continue;
                }

                foreach (XmlElement fileNode in pathsNode.ChildNodes)
                {
                    var path = fileNode.InnerText;

                    var mod = new MercurialModification
                    {
                        ChangeNumber = revision,
                        Comment      = comment,
                        EmailAddress = email,
                        FileName     = Path.GetFileName(path),
                        FolderName   = Path.GetDirectoryName(path),
                        ModifiedTime = modifiedAt,
                        UserName     = username,
                        Version      = node
                    };
                    mods.Add(mod);
                }
            }
            return(mods.ToArray());
        }