예제 #1
0
 /// <summary>
 /// Construct a <see cref="Repository"/>
 /// </summary>
 /// <param name="gitHubConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the <see cref="GitHubConfiguration"/> to use for determining the <see cref="repositoryObject"/>'s path</param>
 /// <param name="_logger">The <see cref="ILogger"/> to use for setting up the <see cref="Repository"/></param>
 /// <param name="_ioManager">The value of <see cref="ioManager"/></param>
 public Repository(IOptions <GitHubConfiguration> gitHubConfigurationOptions, ILogger <Repository> _logger, IIOManager _ioManager)
 {
     logger = _logger ?? throw new ArgumentNullException(nameof(_logger));
     gitHubConfiguration = gitHubConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(gitHubConfigurationOptions));
     ioManager           = new ResolvingIOManager(_ioManager ?? throw new ArgumentNullException(nameof(_ioManager)), _ioManager.ConcatPath(Application.DataDirectory, RepositoriesDirectory));
     semaphore           = new SemaphoreSlim(1);
 }
예제 #2
0
 /// <summary>
 /// Construct a <see cref="PullRequestController"/>
 /// </summary>
 /// <param name="gitHubManager">The value of <see cref="gitHubManager"/></param>
 /// <param name="stringLocalizer">The value of <see cref="stringLocalizer"/></param>
 /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing value of <see cref="generalConfiguration"/></param>
 /// <param name="githubConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing value of <see cref="generalConfiguration"/></param>
 public PullRequestController(IGitHubManager gitHubManager, IStringLocalizer <PullRequestController> stringLocalizer, IOptions <GeneralConfiguration> generalConfigurationOptions, IOptions <GitHubConfiguration> githubConfigurationOptions)
 {
     this.gitHubManager   = gitHubManager ?? throw new ArgumentNullException(nameof(gitHubManager));
     this.stringLocalizer = stringLocalizer ?? throw new ArgumentNullException(nameof(stringLocalizer));
     generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
     gitHubConfiguration  = githubConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(githubConfigurationOptions));
 }
예제 #3
0
 /// <summary>
 /// Construct a <see cref="GitHubManager"/>
 /// </summary>
 /// <param name="gitHubConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="gitHubConfiguration"/></param>
 /// <param name="gitHubClientFactory">The value of <see cref="gitHubClientFactory"/></param>
 /// <param name="databaseContext">The value of <see cref="databaseContext"/></param>
 /// <param name="logger">The value of <see cref="logger"/></param>
 public GitHubManager(IOptions <GitHubConfiguration> gitHubConfigurationOptions, IGitHubClientFactory gitHubClientFactory, IDatabaseContext databaseContext, ILogger <GitHubManager> logger)
 {
     gitHubConfiguration      = gitHubConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(gitHubConfigurationOptions));
     this.gitHubClientFactory = gitHubClientFactory ?? throw new ArgumentNullException(nameof(gitHubClientFactory));
     this.databaseContext     = databaseContext ?? throw new ArgumentNullException(nameof(databaseContext));
     this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
예제 #4
0
        private static ServiceProvider BuildDependencyInjection(IConfiguration config)
        {
            return(new ServiceCollection()
                   .AddLogging(loggingBuilder =>
            {
                loggingBuilder.AddConfiguration(config.GetSection("Logging"));
                loggingBuilder.AddConsole();
            })
                   .AddValidationRules(config)
                   .AddTransient(services =>
            {
                var githubConfig = new GitHubConfiguration();
                config.GetSection("GitHub").Bind(githubConfig);

                ValidateConfig(githubConfig);
                return githubConfig;
            })
                   .AddTransient <IGitHubClient, GitHubClient>(services =>
            {
                return CreateClient(services.GetService <GitHubConfiguration>());
            })
                   .AddTransient <ValidationClient>()
                   .AddSingleton <IRepositoryValidator>(provider =>
            {
                return new RepositoryValidator(
                    provider.GetService <ILogger <RepositoryValidator> >(),
                    provider.GetService <IGitHubClient>(),
                    provider.GetServices <IValidationRule>().ToArray());
            })
                   .AddTransient <GitUtils>()
                   .AddTransient <DocumentationFileCreator>()
                   .BuildServiceProvider());
        }
예제 #5
0
 /// <summary>
 /// Construct a <see cref="PayloadsController"/>
 /// </summary>
 /// <param name="gitHubConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing value of <see cref="gitHubConfiguration"/></param>
 /// <param name="logger">The value of <see cref="logger"/></param>
 /// <param name="pullRequestProcessor">The value of <see cref="pullRequestProcessor"/></param>
 /// <param name="gitHubManager">The value of <see cref="gitHubManager"/></param>
 public PayloadsController(IOptions <GitHubConfiguration> gitHubConfigurationOptions, ILogger <PayloadsController> logger, IPayloadProcessor pullRequestProcessor, IGitHubManager gitHubManager)
 {
     gitHubConfiguration       = gitHubConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(gitHubConfigurationOptions));
     this.logger               = logger ?? throw new ArgumentNullException(nameof(logger));
     this.pullRequestProcessor = pullRequestProcessor ?? throw new ArgumentNullException(nameof(pullRequestProcessor));
     this.gitHubManager        = gitHubManager ?? throw new ArgumentNullException(nameof(gitHubManager));
 }
예제 #6
0
        private static GitHubClient CreateClient(GitHubConfiguration gitHubConfiguration)
        {
            var client    = new GitHubClient(new ProductHeaderValue(ProductHeader));
            var tokenAuth = new Credentials(gitHubConfiguration.Token);

            client.Credentials = tokenAuth;
            return(client);
        }
예제 #7
0
        /// <summary>
        /// Construct a <see cref="GitHubClientFactory"/>
        /// </summary>
        /// <param name="gitHubConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="gitHubConfiguration"/></param>
        /// <param name="webRequestManager">The value of <see cref="webRequestManager"/></param>
        /// <param name="logger">The value of <see cref="logger"/></param>
        public GitHubClientFactory(IOptions <GitHubConfiguration> gitHubConfigurationOptions, IWebRequestManager webRequestManager, ILogger <GitHubClientFactory> logger)
        {
            gitHubConfiguration    = gitHubConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(gitHubConfigurationOptions));
            this.webRequestManager = webRequestManager ?? throw new ArgumentNullException(nameof(webRequestManager));
            this.logger            = logger ?? throw new ArgumentNullException(nameof(logger));

            httpClientAdapter = new HttpClientAdapter(HttpMessageHandlerFactory.CreateDefault);
        }
 /// <summary>
 /// Construct a <see cref="PayloadsController"/>
 /// </summary>
 /// <param name="gitHubConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing value of <see cref="gitHubConfiguration"/></param>
 /// <param name="logger">The value of <see cref="logger"/></param>
 /// <param name="componentProvider">The value of <see cref="componentProvider"/></param>
 /// <param name="autoMergeHandler">The value of <see cref="autoMergeHandler"/></param>
 /// <param name="backgroundJobClient">The value of <see cref="backgroundJobClient"/></param>
 public PayloadsController(IOptions <GitHubConfiguration> gitHubConfigurationOptions, ILogger <PayloadsController> logger, IComponentProvider componentProvider, IAutoMergeHandler autoMergeHandler, IBackgroundJobClient backgroundJobClient)
 {
     gitHubConfiguration      = gitHubConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(gitHubConfigurationOptions));
     this.logger              = logger ?? throw new ArgumentNullException(nameof(logger));
     this.componentProvider   = componentProvider ?? throw new ArgumentNullException(nameof(componentProvider));
     this.autoMergeHandler    = autoMergeHandler ?? throw new ArgumentNullException(nameof(autoMergeHandler));
     this.backgroundJobClient = backgroundJobClient ?? throw new ArgumentNullException(nameof(backgroundJobClient));
 }
 public IActionResult Configuration(GitHubConfiguration gitHubConfiguration)
 {
     if (ModelState.IsValid)
     {
         _githubConfiguration.RepositoryName  = gitHubConfiguration.RepositoryName;
         _githubConfiguration.RepositoryOwner = gitHubConfiguration.RepositoryOwner;
     }
     return(Ok(gitHubConfiguration));
 }
예제 #10
0
        // Start of the set up action
        public string[] SetUpGitHubEnvironment(string token)
        {
            string jsonFilePath = Server.MapPath("~") + @"\Json\";
            string baseAddress  = System.Configuration.ConfigurationManager.AppSettings["BaseAddress"];

            GitHubConfiguration con = new GitHubConfiguration {
                baseAddress = baseAddress, mediaType = "application/json", scheme = "Bearer", token = token
            };
            Users user = new Users(con);

            HttpResponseMessage res        = user.GetUserDetail();
            UserDetail          userDetail = new UserDetail();

            GitHubRepoResponse.RepoCreated GitHubRepo = new GitHubRepoResponse.RepoCreated();
            if (res.IsSuccessStatusCode)
            {
                userDetail = JsonConvert.DeserializeObject <UserDetail>(res.Content.ReadAsStringAsync().Result);
            }
            if (!string.IsNullOrEmpty(userDetail.login))
            {
                GitHubConfiguration repoCon = new GitHubConfiguration {
                    baseAddress = baseAddress, mediaType = "application/json", scheme = "Bearer", token = token, userName = userDetail.login
                };
                Repository repo = new Repository(repoCon);

                //Reading Create Repo JSON and Source code import JSON
                string createRepoJson    = accessDetails.ReadJsonFile(jsonFilePath + "CreateRepo.json");
                string srcCodeImportJson = accessDetails.ReadJsonFile(jsonFilePath + "SourceImport.json");

                //Deserializing Source code JSON into JObject to get the RepoName by splitting the "vcs_url"
                JObject jobj     = JsonConvert.DeserializeObject <JObject>(srcCodeImportJson);
                string  repoName = jobj["vcs_url"].ToString().Split('/')[jobj["vcs_url"].ToString().Split('/').Length - 1]; // splitting the "vcs_url" to get repoName
                createRepoJson = createRepoJson.Replace("$RepoName$", repoName);                                            // Replacing RepoName in create repo json, which creates repo with same name
                HttpResponseMessage response = repo.CreateRepository(createRepoJson);
                if (response.StatusCode.ToString() == "422")
                {
                    // if the Repo already exist, this part will be executed, will append the GUID and create the Repo
                    CreateRepo CreateRepo   = JsonConvert.DeserializeObject <CreateRepo>(createRepoJson);
                    string     guidToAppend = Guid.NewGuid().ToString();
                    guidToAppend = guidToAppend.Substring(0, 8);

                    string RepoName = CreateRepo.name + "_" + guidToAppend;
                    CreateRepo.name = RepoName;
                    string UpdatedJson = JsonConvert.SerializeObject(CreateRepo);
                    response = repo.CreateRepository(UpdatedJson);
                }
                if (response.IsSuccessStatusCode)
                {
                    GitHubRepo      = JsonConvert.DeserializeObject <GitHubRepoResponse.RepoCreated>(response.Content.ReadAsStringAsync().Result);
                    CreatedRepoName = GitHubRepo.name;
                }
                // Import the source code to user repo[to newly created repo], this is an async process which takes some time to import repo
                repo.ImportRepository(srcCodeImportJson, GitHubRepo.owner.login, GitHubRepo.name);
            }
            return(new string[] { });
        }
예제 #11
0
        public IActionResult Configuration(GitHubConfiguration configuration)
        {
            if (ModelState.IsValid)
            {
                _gitHubConfiguration.RepositoryName  = configuration.RepositoryName;
                _gitHubConfiguration.RepositoryOwner = configuration.RepositoryOwner;
            }

            return(View(configuration));
        }
예제 #12
0
 /// <summary>
 /// Construct a <see cref="PayloadProcessor"/>
 /// </summary>
 /// <param name="gitHubConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="gitHubConfiguration"/></param>
 /// <param name="serviceProvider">The value of <see cref="serviceProvider"/></param>
 /// <param name="ioManager">The value of <see cref="ioManager"/></param>
 /// <param name="logger">The value of <see cref="logger"/></param>
 /// <param name="stringLocalizer">The value of <see cref="stringLocalizer"/></param>
 /// <param name="backgroundJobClient">The value of <see cref="backgroundJobClient"/></param>
 /// <param name="diffGenerator">The value of <see cref="diffGenerator"/></param>
 public PayloadProcessor(IOptions <GitHubConfiguration> gitHubConfigurationOptions, IServiceProvider serviceProvider, IIOManager ioManager, ILogger <PayloadProcessor> logger, IStringLocalizer <PayloadProcessor> stringLocalizer, IBackgroundJobClient backgroundJobClient, IDiffGenerator diffGenerator)
 {
     gitHubConfiguration      = gitHubConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(gitHubConfigurationOptions));
     this.ioManager           = new ResolvingIOManager(ioManager ?? throw new ArgumentNullException(nameof(ioManager)), WorkingDirectory);
     this.serviceProvider     = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     this.logger              = logger ?? throw new ArgumentNullException(nameof(logger));
     this.stringLocalizer     = stringLocalizer ?? throw new ArgumentNullException(nameof(stringLocalizer));
     this.backgroundJobClient = backgroundJobClient ?? throw new ArgumentNullException(nameof(backgroundJobClient));
     this.diffGenerator       = diffGenerator ?? throw new ArgumentNullException(nameof(diffGenerator));
 }
예제 #13
0
 /// <summary>
 /// Construct a <see cref="GitHubManager"/>
 /// </summary>
 /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/></param>
 /// <param name="gitHubConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="gitHubConfiguration"/></param>
 /// <param name="_databaseContext">The value of <see cref="databaseContext"/></param>
 /// <param name="_logger">The value of <see cref="logger"/></param>
 /// <param name="_gitHubClientFactory">The value of <see cref="gitHubClientFactory"/></param>
 public GitHubManager(IOptions <GeneralConfiguration> generalConfigurationOptions, IOptions <GitHubConfiguration> gitHubConfigurationOptions, IDatabaseContext _databaseContext, ILogger <GitHubManager> _logger, IGitHubClientFactory _gitHubClientFactory)
 {
     gitHubConfiguration  = gitHubConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(gitHubConfigurationOptions));
     generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
     logger              = _logger ?? throw new ArgumentNullException(nameof(_logger));
     databaseContext     = _databaseContext ?? throw new ArgumentNullException(nameof(_databaseContext));
     gitHubClientFactory = _gitHubClientFactory ?? throw new ArgumentNullException(nameof(_gitHubClientFactory));
     gitHubClient        = gitHubClientFactory.CreateGitHubClient(gitHubConfiguration.PersonalAccessToken);
     semaphore           = new SemaphoreSlim(1);
 }
예제 #14
0
        private static GitHubClient CreateClient(GitHubConfiguration configuration)
        {
            var client = new GitHubClient(new ProductHeaderValue("PTCS-Repository-Validator"));

            if (!string.IsNullOrWhiteSpace(configuration.Token))
            {
                var tokenAuth = new Credentials(configuration.Token);
                client.Credentials = tokenAuth;
            }
            return(client);
        }
예제 #15
0
 /// <summary>
 /// Construct a <see cref="PayloadProcessor"/>
 /// </summary>
 /// <param name="gitHubConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="gitHubConfiguration"/></param>
 /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/></param>
 /// <param name="generatorFactory">The value of <see cref="generatorFactory"/></param>
 /// <param name="serviceProvider">The value of <see cref="serviceProvider"/></param>
 /// <param name="repositoryManager">The value of <see cref="repositoryManager"/></param>
 /// <param name="ioManager">The value of <see cref="ioManager"/></param>
 /// <param name="logger">The value of <see cref="logger"/></param>
 /// <param name="stringLocalizer">The value of <see cref="stringLocalizer"/></param>
 /// <param name="backgroundJobClient">The value of <see cref="backgroundJobClient"/></param>
 public PayloadProcessor(IOptions <GitHubConfiguration> gitHubConfigurationOptions, IOptions <GeneralConfiguration> generalConfigurationOptions, IGeneratorFactory generatorFactory, IServiceProvider serviceProvider, ILocalRepositoryManager repositoryManager, IIOManager ioManager, ILogger <PayloadProcessor> logger, IStringLocalizer <PayloadProcessor> stringLocalizer, IBackgroundJobClient backgroundJobClient)
 {
     gitHubConfiguration      = gitHubConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(gitHubConfigurationOptions));
     generalConfiguration     = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
     this.ioManager           = new ResolvingIOManager(ioManager ?? throw new ArgumentNullException(nameof(ioManager)), WorkingDirectory);
     this.generatorFactory    = generatorFactory ?? throw new ArgumentNullException(nameof(generatorFactory));
     this.serviceProvider     = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     this.repositoryManager   = repositoryManager ?? throw new ArgumentNullException(nameof(repositoryManager));
     this.logger              = logger ?? throw new ArgumentNullException(nameof(logger));
     this.stringLocalizer     = stringLocalizer ?? throw new ArgumentNullException(nameof(stringLocalizer));
     this.backgroundJobClient = backgroundJobClient ?? throw new ArgumentNullException(nameof(backgroundJobClient));
 }
예제 #16
0
        private static void ValidateConfig(GitHubConfiguration gitHubConfiguration)
        {
            if (string.IsNullOrWhiteSpace(gitHubConfiguration.Organization))
            {
                throw new ArgumentNullException(nameof(gitHubConfiguration.Organization), "Organization was missing.");
            }

            if (string.IsNullOrWhiteSpace(gitHubConfiguration.Token))
            {
                throw new ArgumentNullException(nameof(gitHubConfiguration.Token), "Token was missing.");
            }
        }
예제 #17
0
        private static void ValidateConfig(GitHubConfiguration gitHubConfiguration)
        {
            if (gitHubConfiguration.Organization == null)
            {
                throw new ArgumentNullException(nameof(gitHubConfiguration.Organization), "Organization was missing.");
            }

            if (gitHubConfiguration.Token == null)
            {
                throw new ArgumentNullException(nameof(gitHubConfiguration.Token), "Token was missing.");
            }
        }
 public HangfireDashboardAuthorizationFilter(GitHubConfiguration configuration)
 {
     this._configuration = configuration;
 }
예제 #19
0
 public WebController(IBomberjamRepository repository, IBomberjamStorage storage, ILogger <WebController> logger, GitHubConfiguration github)
     : base(repository, storage, logger)
 {
     this._github = github;
 }
예제 #20
0
 /// <summary>
 /// Construct a <see cref="GitHubClientFactory"/>
 /// </summary>
 /// <param name="gitHubConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="gitHubConfiguration"/></param>
 /// <param name="logger">The value of <see cref="logger"/></param>
 public GitHubClientFactory(IOptions <GitHubConfiguration> gitHubConfigurationOptions, ILogger <GitHubClientFactory> logger)
 {
     gitHubConfiguration = gitHubConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(gitHubConfigurationOptions));
     this.logger         = logger ?? throw new ArgumentNullException(nameof(logger));
 }
예제 #21
0
        public void Configure(IApplicationBuilder app, IRecurringJobManager recurringJobs, ILogger <Startup> logger, GitHubConfiguration gitHubConfiguration)
        {
            app.UseResponseCompression();

            if (this.Environment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Web/Error");
                app.UseHsts();
            }

            // Required to serve files with no extension in the .well-known folder
            var options = new StaticFileOptions
            {
                ServeUnknownFileTypes = true
            };

            app.UseHttpsRedirection();
            app.UseStaticFiles(options);

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();
                endpoints.MapHangfireDashboard(new DashboardOptions
                {
                    Authorization = new[] { new HangfireDashboardAuthorizationFilter(gitHubConfiguration) }
                });
            });

            var matchmakingCronExpr   = this.Configuration["JobCrons:Matchmaking"];
            var orphanedTasksCronExpr = this.Configuration["JobCrons:OrphanedTasks"];

            logger.Log(LogLevel.Information, "Matchmaking cron expression: " + matchmakingCronExpr);
            logger.Log(LogLevel.Information, "Orphaned tasks cron expression: " + orphanedTasksCronExpr);

            recurringJobs.AddOrUpdate <MatchmakingJob>("matchmaking", job => job.Run(), matchmakingCronExpr);
            recurringJobs.AddOrUpdate <OrphanedTaskFixingJob>("orphanedTasks", job => job.Run(), orphanedTasksCronExpr);
        }