コード例 #1
0
        public (string badge, string history) Process(
            IDictionary <object, object> config,
            IMarkdownReferences references,
            RocketBoosterBuild build
            )
        {
            var url = references.AddReference(
                "azurepipelines",
                $"https://{config["account"]}.visualstudio.com/{config["teamproject"]}/_build/latest?definitionId={config["builddefinition"]}&branchName=master"
                );
            var badge = references.AddReference(
                "azurepipelines-badge",
                $"https://img.shields.io/azure-devops/build/{config["account"]}/{config["teamproject"]}/{config["builddefinition"]}.svg?color=98C6FF&label=azure%20pipelines&logo=azuredevops&logoColor=98C6FF&style=flat",
                "Azure Pipelines Status"
                );
            var historyUrl = references.AddReference(
                "azurepipelines-history",
                $"https://{config["account"]}.visualstudio.com/{config["teamproject"]}/_build?definitionId={config["builddefinition"]}&branchName=master"
                );
            var historyBadge = references.AddReference(
                "azurepipelines-history-badge",
                $"https://buildstats.info/azurepipelines/chart/{config["account"]}/{config["teamproject"]}/{config["builddefinition"]}?includeBuildsFromPullRequest=false",
                "Azure Pipelines History"
                );

            return($"[!{badge}]{url}", $"[!{historyBadge}]{historyUrl}");
        }
コード例 #2
0
ファイル: Badges.cs プロジェクト: tristal/Nuke
        /// <inheritdoc />
        public string Process(
            IDictionary <string, object> config,
            IMarkdownReferences references,
            RocketBoosterBuild build
            )
        {
            var sb = new StringBuilder();

            foreach (var section in _sections)
            {
                var subConfig = string.IsNullOrEmpty(section.ConfigKey) ?
                                config.ToDictionary(x => (object)x.Key, x => x.Value) :
                                config.TryGetValue(section.ConfigKey, out var o) ? o as IDictionary <object, object> : null;
                // Assume if not configured, it will never be able to be rendered
                if (subConfig is null)
                {
                    continue;
                }

                var result = section.Process(subConfig, references, build);
                if (string.IsNullOrWhiteSpace(result))
                {
                    continue;
                }

                sb.AppendLine(result);
            }

            return(sb.ToString());
        }
コード例 #3
0
ファイル: AppVeyorHistory.cs プロジェクト: tristal/Nuke
        public (string badge, string history) Process(
            IDictionary <object, object> config,
            IMarkdownReferences references,
            RocketBoosterBuild build
            )
        {
            var url = references.AddReference(
                "appveyor",
                $"https://ci.appveyor.com/project/{config["account"]}/{config["build"]}"
                );
            var badge = references.AddReference(
                "appveyor-badge",
                $"https://img.shields.io/appveyor/ci/{config["account"]}/{config["build"]}.svg?color=00b3e0&label=appveyor&logo=appveyor&logoColor=00b3e0&style=flat",
                "AppVeyor Status"
                );
            var historyUrl = references.AddReference(
                "appveyor-history",
                $"https://ci.appveyor.com/project/{config["account"]}/{config["build"]}/history"
                );
            var historyBadge = references.AddReference(
                "appveyor-history-badge",
                $"https://buildstats.info/appveyor/chart/{config["account"]}/{config["build"]}?includeBuildsFromPullRequest=false",
                "AppVeyor History"
                );

            return($"[!{badge}]{url}", $"[!{historyBadge}]{historyUrl}");
        }
コード例 #4
0
ファイル: CodacySection.cs プロジェクト: tristal/Nuke
        public string Process(
            IDictionary <object, object> config,
            IMarkdownReferences references,
            RocketBoosterBuild build
            )
        {
            if (!(config.TryGetValue("github", out var githubObj) && config.TryGetValue("codacy", out var codacyObj)))
            {
                return(string.Empty);
            }

            var github = (IDictionary <object, object>)githubObj;
            var codacy = (IDictionary <object, object>)codacyObj;
            var url    = references.AddReference(
                "codacy",
                $"https://www.codacy.com/app/{github["owner"]}/{github["repository"]}"
                );
            var badge = references.AddReference(
                "codacy-badge",
                $"https://api.codacy.com/project/badge/Grade/{codacy["project"]}",
                "Codacy"
                );

            return($"[!{badge}]{url}");
        }
コード例 #5
0
ファイル: Histories.cs プロジェクト: tristal/Nuke
        /// <inheritdoc />
        public string Process(
            IDictionary <string, object> config,
            IMarkdownReferences references,
            RocketBoosterBuild build
            )
        {
            var results = new List <(string name, string badge, string history)>();

            foreach (var section in _sections)
            {
                var subConfig = string.IsNullOrEmpty(section.ConfigKey) ?
                                config.ToDictionary(x => (object)x.Key, x => x.Value) :
                                config.TryGetValue(section.ConfigKey, out var o) ? o as IDictionary <object, object> : null;
                // Assume if not configured, it will never be able to be rendered
                if (subConfig is null)
                {
                    continue;
                }

                var(badge, history) = section.Process(subConfig, references, build);
                results.Add((section.Name, badge, history));
            }

            var sb = new StringBuilder();

            sb.AppendLine($"| {string.Join(" | ", results.Select(z => z.name))} |");
            sb.AppendLine(
                $"| {string.Join(" | ", results.Select(z => string.Join("", Enumerable.Range(0, z.name.Length).Select(x => "-"))))} |"
                );
            sb.AppendLine($"| {string.Join(" | ", results.Select(z => z.badge))} |");
            sb.AppendLine($"| {string.Join(" | ", results.Select(z => z.history))} |");
            return(sb.ToString());
        }
コード例 #6
0
        /// <summary>
        /// <para>Updates the given markdown content with all the sections replaced.</para>
        /// <para>
        /// The "generated references" is special and will always be run through last, to make sure all sections can
        /// contribute references.
        /// </para>
        /// </summary>
        /// <param name="content"></param>
        /// <param name="build"></param>
        /// <returns></returns>
        public string Process(string content, RocketBoosterBuild build)
        {
            var nukeDataRegex = new Regex(
                "<!-- nuke-data(.*?)-->",
                RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase
                );
            var match = nukeDataRegex.Match(content);
            var yaml  = string.Join("\n", match.Groups.Cast <Group>().Skip(1).Select(x => x.Value));
            var d     = new DeserializerBuilder()
                        // .WithNamingConvention(new CamelCaseNamingConvention())
                        .Build();

            using var reader = new StringReader(yaml.Trim('\n'));
            var config = d.Deserialize <ExpandoObject>(reader);

            var sectionRegex = new Regex(
                "<!-- (.*?) -->",
                RegexOptions.Multiline | RegexOptions.Compiled | RegexOptions.IgnoreCase
                );

            var sections = sectionRegex.Matches(content);

            var ranges = new List <(int start, int length, string content)>();

            foreach (var sectionMatch in sections.OfType <Match>()
                     .GroupBy(x => x.Groups[1].Value)
                     .OrderByDescending(x => x.Key != "generated references")
                     )
            {
                var sectionName = sectionMatch.First().Groups[1].Value;
                if (!Sections.AllSections.TryGetValue(sectionName, out var section))
                {
                    throw new NotImplementedException("Section " + sectionName + " is not supported!");
                }

                var sectionStart      = sectionMatch.First().Captures[0];
                var sectionEnd        = sectionMatch.Last().Captures[0];
                var newSectionContent = section.Process(config, References, build);
                ranges.Add(
                    (sectionStart.Index + sectionStart.Length,
                     sectionEnd.Index - (sectionStart.Index + sectionStart.Length), newSectionContent)
                    );
            }

            foreach (var range in ranges.OrderByDescending(x => x.start))
            {
                content = content.Substring(0, range.start)
                          + "\n" + range.content + content.Substring(range.start + range.length);
            }

            return(content);
        }
コード例 #7
0
ファイル: References.cs プロジェクト: tristal/Nuke
        /// <inheritdoc />
        public string Process(
            IDictionary <string, object> config,
            IMarkdownReferences references,
            RocketBoosterBuild build
            )
        {
            var sb = new StringBuilder();

            foreach (var item in _references)
            {
                sb.AppendLine($"{item.Key}: {item.Value}");
            }

            return(sb.ToString());
        }
コード例 #8
0
ファイル: CodecovSection.cs プロジェクト: tristal/Nuke
        public string Process(
            IDictionary <object, object> config,
            IMarkdownReferences references,
            RocketBoosterBuild build
            )
        {
            var url = references.AddReference(
                "codecov",
                $"https://codecov.io/gh/{config["owner"]}/{config["repository"]}"
                );
            var badge = references.AddReference(
                "codecov-badge",
                $"https://img.shields.io/codecov/c/github/{config["owner"]}/{config["repository"]}.svg?color=E03997&label=codecov&logo=codecov&logoColor=E03997&style=flat",
                "Code Coverage"
                );

            return($"[!{badge}]{url}");
        }
コード例 #9
0
        public string Process(
            IDictionary <object, object> config,
            IMarkdownReferences references,
            RocketBoosterBuild build
            )
        {
            var url = references.AddReference(
                "github-release",
                $"https://github.com/{config["owner"]}/{config["repository"]}/releases/latest"
                );
            var badge = references.AddReference(
                "github-release-badge",
                $"https://img.shields.io/github/release/{config["owner"]}/{config["repository"]}.svg?logo=github&style=flat",
                "Latest Release"
                );

            return($"[!{badge}]{url}");
        }
コード例 #10
0
        public string Process(
            IDictionary <object, object> config,
            IMarkdownReferences references,
            RocketBoosterBuild build
            )
        {
            var url = references.AddReference(
                "github-license",
                $"https://github.com/{config["owner"]}/{config["repository"]}/blob/master/LICENSE"
                );
            var badge = references.AddReference(
                "github-license-badge",
                $"https://img.shields.io/github/license/{config["owner"]}/{config["repository"]}.svg?style=flat",
                "License"
                );

            return($"[!{badge}]{url}");
        }