예제 #1
0
        private BuildDetails GetBuildDetails(Credentials credentials, string buildUrl, bool ignoreUntrustedCertificate)
        {
            if (buildUrl == null)
            {
                return(null);
            }

            var url = NetUtils.ConcatUrls(buildUrl, "/api/xml", JenkinsService.buildDetailsFilter);

            if (logger.IsDebugEnabled)
            {
                logger.Debug("Getting build details from " + url);
            }

            var xmlStr = DownloadString(credentials, url, true, ignoreUntrustedCertificate);

            if (logger.IsTraceEnabled)
            {
                logger.Trace("XML: " + xmlStr);
            }

            var xml = new XmlDocument();

            xml.LoadXml(xmlStr);

            var number            = xml.SelectSingleNode("/*/number").InnerText;
            var fullDisplayName   = xml.SelectSingleNode("/*/fullDisplayName").InnerText;
            var timestamp         = xml.SelectSingleNode("/*/timestamp").InnerText;
            var estimatedDuration = xml.SelectSingleNode("/*/estimatedDuration").InnerText;
            var duration          = xml.SelectSingleNode("/*/duration").InnerText;
            var xmlResult         = xml.SelectSingleNode("/*/result");
            var result            = xmlResult == null ? string.Empty : xmlResult.InnerText;
            var userNodes         = xml.SelectNodes("/*/culprit/fullName");

            var ts   = TimeSpan.FromSeconds(long.Parse(timestamp) / 1000);
            var date = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            date = date.Add(ts);
            var estimatedts = TimeSpan.FromSeconds(long.Parse(estimatedDuration) / 1000);
            var durationts  = TimeSpan.FromSeconds(long.Parse(estimatedDuration) / 1000);

            Spring.Collections.Generic.ISet <string> users = new HashedSet <string>();
            foreach (XmlNode userNode in userNodes)
            {
                var userName = StringUtils.ExtractUserName(userNode.InnerText);
                users.Add(userName);
            }

            var res = new BuildDetails();

            BuildCauses.FillInBuildCauses(res, xml);
            res.Number            = int.Parse(number);
            res.DisplayName       = fullDisplayName;
            res.Time              = date;
            res.EstimatedDuration = estimatedts;
            res.Duration          = durationts;
            res.Result            = BuildStatus.StringToBuildStatus(result);
            res.Users             = users;

            ClaimService.FillInBuildDetails(res, xml);

            if (logger.IsDebugEnabled)
            {
                logger.Debug("Done getting build details");
            }

            return(res);
        }