private static int RunOptions(GithubOptions opts)
        {
            var monitor = new PullRequestMonitor(opts.Token, opts.Folder);
            var cancellationTokenSource = new CancellationTokenSource();

            try
            {
                Console.WriteLine("Beginning of retrieval of PR status");
                monitor.RunAsync(opts.Builds).Wait(cancellationTokenSource.Token);
            }
            catch (OperationCanceledException)
            {
                // Ignore
            }
            finally
            {
                Console.WriteLine("End of deep monitoring");
            }
            return(0);
        }
Example #2
0
        public static IServiceCollection ConfigureGithubServices(this IServiceCollection services, IConfiguration configuration, string githubUrl = "https://api.github.com")
        {
            var pats = configuration.GetSection("PATS").AsEnumerable();

            foreach (var pat in pats)
            {
                if (pat.Value != null)
                {
                    lock (GithubOptions.PersonalAccessTokenUsage)
                    {
                        if (!GithubOptions.PersonalAccessTokenUsage.ContainsKey(pat.Value))
                        {
                            GithubOptions.PersonalAccessTokenUsage.Add(pat.Value, 0);
                        }
                    }
                }
            }

            services.Configure <RankPoints>(options => configuration.GetSection("RankPoints").Bind(options));
            services.Configure <RankDegree>(options => configuration.GetSection("RankDegree").Bind(options));
            services.AddMemoryCache();
            services.AddScoped <IGithubService, GithubService>();
            services.AddScoped <IGithubUserStore, GithubUserStore>();
            services.AddScoped <IRankService, RankService>();
            services.AddScoped <ISvgService, SvgService>();
            services.AddScoped <ICacheService, MemoryCacheService>();

            services.AddHttpClient("github", c =>
            {
                var pat       = GithubOptions.NextPat();
                c.BaseAddress = new Uri(githubUrl);
                // Github requires a user-agent
                c.DefaultRequestHeaders.Add("Authorization", $"bearer {pat}");

                // Github requires a user-agent
                c.DefaultRequestHeaders.Add("User-Agent", "Awesome-Github-Stats");
            });

            return(services);
        }
Example #3
0
 public KeyValueController(GithubOptions githubOptions)
 {
     _githubOptions = githubOptions;
 }