public void Extract_WhenPercent_ExpectMatchingColor(JsonData jsonData, ShieldsColors expectedValue)
        {
            var stats  = (SonarQubeStats)jsonData.Data;
            var result = _extractor.Extract(stats.Component.Measures.First(), stats.Metrics.First());

            Assert.Equal(expectedValue, result);
        }
        public Task <string> GetSvgBadgeAsync(string label, string value, ShieldsColors color)
        {
            var valueEncoded = System.Net.WebUtility.UrlEncode(value);
            var labelEncoded = System.Net.WebUtility.UrlEncode(label);

            // This could potentially become more generic (configuration file). Only issue are the colors.
            return(_shieldIoClient.GetStringAsync($"label-{valueEncoded}-{color.ToString().ToLowerInvariant()}.svg?longCache=true&style=popout&label={labelEncoded}"));
        }
        public void Extract_WhenInt_ExpectMatchingColor(JsonData jsonData, ShieldsColors expectedValue)
        {
            // LowerIsBetter is tested, normally we don't have the other way around with integer.
            var stats  = (SonarQubeStats)jsonData.Data;
            var result = _extractor.Extract(stats.Component.Measures.First(), stats.Metrics.First());

            Assert.Equal(expectedValue, result);
        }
        public async Task <ActionResult <System.IO.Stream> > Get(
            [FromQuery] string key,
            [FromQuery] Metric metric,
            [FromQuery] string branch = null,
            [FromQuery] string label  = null)
        {
            string        value;
            ShieldsColors color         = ShieldsColors.YellowGreen;
            string        officialLabel = null;

            if (metric == Metric.QualityGate)
            {
                label  = "Quality Gate";
                metric = Metric.QualityGateDetails;
            }

            var res = await _sonarQubeSvc.FetchStatsAsync(key, branch, metric);

            var currentMeasure = res.Component.Measures.FirstOrDefault();

            if (currentMeasure == null)
            {
                value = "---";
                color = ShieldsColors.Yellow;
            }
            else
            {
                var currentMetric = res.Metrics.FirstOrDefault(f => f.Key == metric.ToSnakeCase());
                officialLabel = label ?? currentMetric.Name;

                color = _sonarQubeColorCORP.Extract(currentMeasure, currentMetric);
                value = _sonarQubeValueExtractor.Extract(currentMeasure, currentMetric);
            }

            if (string.IsNullOrEmpty(officialLabel))
            {
                officialLabel = label ?? metric.ToSnakeCase().Replace('_', ' ');
            }

            var svgContent = await _shieldIoSvc.GetSvgBadgeAsync(officialLabel, value, color);

            return(Content(svgContent, "image/svg+xml; charset=utf-8"));
        }
Exemplo n.º 5
0
 public ColorStep(ShieldsColors color)
 {
     _color = color;
 }