Esempio n. 1
0
        public static SettingsContainer ParseToSettings(RawConfiguration settings)
        {
            var modalSettings = ReadModalSettings(settings);

            if (modalSettings == null)
            {
                return(null);
            }

            var authSettings = new GithubAuthSettings(
                EnsureTrailingSlash(settings.GithubApiEndpoint),
                settings.GithubToken);

            var userPrefs = new UserSettings
            {
                AllowedChange = settings.AllowedChange,
                ForkMode      = settings.ForkMode,
                LogLevel      = settings.LogLevel,
                MaxPullRequestsPerRepository = settings.MaxPullRequestsPerRepository,
                NuGetSources    = ReadNuGetSources(settings),
                PackageIncludes = ParseRegex(settings.Include, nameof(settings.Include)),
                PackageExcludes = ParseRegex(settings.Exclude, nameof(settings.Exclude))
            };

            return(new SettingsContainer
            {
                ModalSettings = modalSettings,
                GithubAuthSettings = authSettings,
                UserSettings = userPrefs
            });
        }
Esempio n. 2
0
        private static NuGetSources ReadNuGetSources(RawConfiguration settings)
        {
            if (string.IsNullOrWhiteSpace(settings.NuGetSources))
            {
                return(null);
            }

            var items = ReadMultilineSetting(settings.NuGetSources);

            return(new NuGetSources(items));
        }
Esempio n. 3
0
        private static RepositorySettings ReadRepositorySettings(RawConfiguration settings)
        {
            // general pattern is https://github.com/owner/reponame.git
            // from this we extract owner and repo name
            var path      = settings.GithubRepositoryUri.AbsolutePath;
            var pathParts = path.Split('/')
                            .Where(s => !string.IsNullOrWhiteSpace(s))
                            .ToList();

            var repoOwner = pathParts[0];
            var repoName  = pathParts[1].Replace(".git", string.Empty);

            return(new RepositorySettings
            {
                GithubUri = settings.GithubRepositoryUri,
                RepositoryName = repoName,
                RepositoryOwner = repoOwner
            });
        }
Esempio n. 4
0
        public static SettingsContainer ParseToSettings(RawConfiguration settings)
        {
            var modalSettings = ReadModalSettings(settings);

            if (modalSettings == null)
            {
                return(null);
            }

            var authSettings = new GithubAuthSettings(
                EnsureTrailingSlash(settings.GithubApiEndpoint),
                settings.GithubToken);

            var minPackageAge = DurationParser.Parse(settings.MinPackageAge);

            if (!minPackageAge.HasValue)
            {
                minPackageAge = TimeSpan.Zero;
                Console.WriteLine($"Min package age '{settings.MinPackageAge}' could not be parsed");
            }

            var userPrefs = new UserSettings
            {
                AllowedChange = settings.AllowedChange,
                ForkMode      = settings.ForkMode,
                ReportMode    = settings.ReportMode,
                MaxPullRequestsPerRepository = settings.MaxPullRequestsPerRepository,
                MaxRepositoriesChanged       = settings.MaxRepositoriesChanged,
                NuGetSources      = ReadNuGetSources(settings),
                PackageIncludes   = ParseRegex(settings.Include, nameof(settings.Include)),
                PackageExcludes   = ParseRegex(settings.Exclude, nameof(settings.Exclude)),
                MinimumPackageAge = minPackageAge.Value,
                Directory         = settings.Dir
            };

            return(new SettingsContainer
            {
                ModalSettings = modalSettings,
                GithubAuthSettings = authSettings,
                UserSettings = userPrefs
            });
        }
Esempio n. 5
0
        private static ModalSettings ReadModalSettings(RawConfiguration settings)
        {
            var mode = ParseMode(settings.Mode);

            if (!mode.HasValue)
            {
                Console.WriteLine($"Mode '{settings.Mode}' not supported");
                return(null);
            }

            switch (mode.Value)
            {
            case GithubMode.Repository:
                if (settings.GithubRepositoryUri == null)
                {
                    Console.WriteLine("Missing required repository uri");
                    return(null);
                }
                return(new ModalSettings
                {
                    Mode = GithubMode.Repository,
                    Repository = ReadRepositorySettings(settings)
                });

            case GithubMode.Organisation:
                if (string.IsNullOrWhiteSpace(settings.GithubOrganisationName))
                {
                    Console.WriteLine("Missing required organisation name");
                    return(null);
                }
                return(new ModalSettings
                {
                    Mode = GithubMode.Organisation,
                    OrganisationName = settings.GithubOrganisationName
                });

            default:
                Console.WriteLine($"Mode parse went wrong: {settings.Mode}");
                return(null);
            }
        }
Esempio n. 6
0
        private static ModalSettings ReadModalSettings(RawConfiguration settings)
        {
            var mode = ParseMode(settings.Mode);

            if (!mode.HasValue)
            {
                Console.WriteLine($"Mode '{settings.Mode}' not supported");
                return(null);
            }

            switch (mode.Value)
            {
            case RunMode.Repository:
                if (settings.GithubToken == null)
                {
                    Console.WriteLine("Missing required github token");
                    return(null);
                }

                if (settings.GithubRepositoryUri == null)
                {
                    Console.WriteLine("Missing required repository uri");
                    return(null);
                }

                return(new ModalSettings
                {
                    Mode = RunMode.Repository,
                    Repository = ReadRepositorySettings(settings.GithubRepositoryUri),
                    Labels = ReadMultilineSetting(settings.Labels)
                });

            case RunMode.Organisation:
                if (settings.GithubToken == null)
                {
                    Console.WriteLine("Missing required github token");
                    return(null);
                }

                if (string.IsNullOrWhiteSpace(settings.GithubOrganisationName))
                {
                    Console.WriteLine("Missing required organisation name");
                    return(null);
                }
                return(new ModalSettings
                {
                    Mode = RunMode.Organisation,
                    OrganisationName = settings.GithubOrganisationName,
                    Labels = ReadMultilineSetting(settings.Labels)
                });

            case RunMode.Inspect:
            case RunMode.Update:
            {
                return(new ModalSettings
                    {
                        Mode = mode.Value
                    });
            }

            default:
                Console.WriteLine($"Mode parse went wrong: {settings.Mode}");
                return(null);
            }
        }
Esempio n. 7
0
 private static string[] ReadNuGetSources(RawConfiguration settings)
 {
     return(settings.NuGetSources.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries));
 }