public async Task <bool> UpdateGitHubSetting(string clientId, string clientSecret, TableStorageAuth tableStorageAuth, string settingsTable, string owner, string repo, string branch, string workflowName, string workflowId, string resourceGroupName, int itemOrder) { string partitionKey = "GitHubSettings"; string rowKey = CreateGitHubSettingsPartitionKey(owner, repo, workflowName); GitHubSettings settings = new GitHubSettings { RowKey = rowKey, ClientId = clientId, ClientSecret = clientSecret, Owner = owner, Repo = repo, Branch = branch, WorkflowName = workflowName, WorkflowId = workflowId, ProductionResourceGroup = resourceGroupName, ItemOrder = itemOrder }; string json = JsonConvert.SerializeObject(settings); AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, json); TableStorageCommonDA tableDA = new TableStorageCommonDA(tableStorageAuth, settingsTable); return(await tableDA.SaveItem(newItem)); }
public IActionResult CheckCommits(GitHubInformationForm form, RequestTypes request) { var commintsNumber = 10; IList <Commit> commits = new List <Commit>(); var url = string.Empty; if (!string.IsNullOrEmpty(form.UserName) && !string.IsNullOrEmpty(form.RepositoryName)) { var gihubSettings = new GitHubSettings { UserName = form.UserName, RepositoryName = form.RepositoryName, RequestType = request }; url = _urlGenerator.GenerateUrlForGitHubApi(gihubSettings); try { commits = _githubService.ProcessCommits(url); if (commits.Any()) { commits = commits.OrderByDescending(c => c.PurpleCommit.Committer.DateOfCommit).Take(commintsNumber).ToList(); } } catch (Exception ex) { ViewBag.InnerException = ex.Message; } } return(PartialView("_Commits", commits)); }
public async Task <bool> UpdateGitHubSettingInStorage(TableStorageConfiguration tableStorageConfig, string settingsTable, string owner, string repo, string branch, string workflowName, string workflowId, string resourceGroupName, int itemOrder, bool showSetting) { string partitionKey = "GitHubSettings"; string rowKey = PartitionKeys.CreateGitHubSettingsPartitionKey(owner, repo); GitHubSettings settings = new GitHubSettings { RowKey = rowKey, Owner = owner, Repo = repo, Branch = branch, WorkflowName = workflowName, WorkflowId = workflowId, ProductionResourceGroup = resourceGroupName, ItemOrder = itemOrder, ShowSetting = showSetting }; string json = JsonConvert.SerializeObject(settings); AzureStorageTableModel newItem = new AzureStorageTableModel(partitionKey, rowKey, json); TableStorageCommonDA tableDA = new TableStorageCommonDA(tableStorageConfig, settingsTable); return(await tableDA.SaveItem(newItem)); }
static async Task Main(string[] args) { try { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true) .AddJsonFile("appsettings.production.json", optional: true) .Build(); var userMapper = new UserMapper(); config.GetSection("UserMapper").Bind(userMapper); var gitLabSettings = new GitLabSettings(); config.GetSection("GitLab").Bind(gitLabSettings); var gitLabConnector = new GitLabConnector(gitLabSettings); var gitHubSettings = new GitHubSettings(); config.GetSection("GitHub").Bind(gitHubSettings); var gitHubConnector = new GitHubConnector(gitHubSettings, userMapper); var migration = new Migration(gitLabConnector, gitHubConnector); await migration.MigrateOneProject(); } catch (Exception e) { Console.WriteLine(e); throw; } }
public IssuesRepository(IGitHubClient gitHubClient, IOptions <GitHubSettings> gitHubOptions, IStringLocalizer <IssuesRepository> stringLocalizer, ILogger <IssuesRepository> logger) { _gitHubClient = gitHubClient; _gitHubSettings = gitHubOptions.Value; _localizer = stringLocalizer; _logger = logger; }
public static void AddGitHubServices(this IServiceCollection services, GitHubSettings gitHubSettings) { services.AddSingleton <IGitHubClient, GitHubClient>(s => new GitHubClient(new ProductHeaderValue(gitHubSettings.ProductHeaderValue)) { Credentials = new Credentials(gitHubSettings.PersonalAccessToken) }); services.AddTransient <IIssuesRepository, IssuesRepository>(); }
public GitHubConnector(GitHubSettings gitHubSettings, UserMapper userMapper) { _gitHubSettings = gitHubSettings; _userMapper = userMapper; _gitHubClient = new GitHubClient(new ProductHeaderValue("GitLabToGitHub")) { Credentials = new Credentials(gitHubSettings.AccessToken) }; }
public ConfigurationTest() { _fakeGitHubSettings = new GitHubSettings { ClientId = "myClientId", CallbackPath = "/not/a/path" }; _fakeOptions = Options.Create(_fakeGitHubSettings); _controller = new ConfigurationController(_fakeOptions); }
private readonly Regex _mentionRegex = new Regex(@"(?<=\B\@)([\w\._\-\/]+)", RegexOptions.Compiled); // Get any word starting with '@' public TicketImportService(AppSettings settings, IGitHubService gitHubService, IBacklogItemCommandService backlogItemService, IBacklogItemCommentCommandService backlogCommentService, ISeededUsers seededUser, IAsyncDocumentSession dbSession) { _gitHubService = gitHubService; _gitHubSettings = settings.GitHub; _dbSession = dbSession; _backlogItemService = backlogItemService; _backlogCommentService = backlogCommentService; _seededUser = seededUser; }
public IActionResult CheckBranches(GitHubInformationForm form, RequestTypes request) { IList <Branch> branches = new List <Branch>(); var url = string.Empty; if (!string.IsNullOrEmpty(form.UserName) && !string.IsNullOrEmpty(form.RepositoryName)) { var gihubSettings = new GitHubSettings { UserName = form.UserName, RepositoryName = form.RepositoryName, RequestType = request }; url = _urlGenerator.GenerateUrlForGitHubApi(gihubSettings); try { branches = _githubService.ProcessBranches(url); } catch (Exception ex) { ViewBag.InnerException = ex.Message; } } return(PartialView("_Branches", branches)); }
public IActionResult CheckRepository(GitHubInformationForm form, RequestTypes request) { Repository repositoryInformation = null; var url = string.Empty; if (!string.IsNullOrEmpty(form.UserName) && !string.IsNullOrEmpty(form.RepositoryName)) { var gihubSettings = new GitHubSettings { UserName = form.UserName, RepositoryName = form.RepositoryName, RequestType = request }; url = _urlGenerator.GenerateUrlForGitHubApi(gihubSettings); try { repositoryInformation = _githubService.ProcessRepositoryInfoByUrl(url); } catch (Exception ex) { ViewBag.InnerException = ex.Message; } } return(PartialView("_Repository", repositoryInformation)); }
public GitHubFileLogic(ILogger <GitHubFileLogic> logger, Settings settings, IHttpClientFactory httpClientFactory) { this.logger = logger; this.settings = settings; gitHubSettings = settings.FoxIDsGitHub; this.httpClientFactory = httpClientFactory; var blobServiceClient = new BlobServiceClient(settings.BlobConnectionString); var containerName = $"{MaxLengthSubString(settings.BaseSitePath.TrimEnd('/').Substring(8).Replace(".azurewebsites.net", string.Empty).Replace('.', '-').Replace(':', '-').Replace("--", "-"), 30)}-github-{settings.FoxIDsGitHub.Branch}-{settings.GitHubSiteFolder.Trim('/')}".ToLower(); try { containerClient = blobServiceClient.GetBlobContainerClient(containerName); if (!containerClient.Exists()) { containerClient = blobServiceClient.CreateBlobContainer(containerName); } } catch (Exception ex) { throw new Exception($"Failing blob container name '{containerName}'.", ex); } }
public string GenerateUrlForGitHubApi(GitHubSettings settings) { var urlString = string.Empty; switch (settings.RequestType) { case RequestTypes.CheckIfRepositoryExists: if (!string.IsNullOrEmpty(settings.UserName) && !string.IsNullOrEmpty(settings.RepositoryName)) { urlString = SetUpApiString(GITHUB_REPO_URL, settings.UserName, settings.RepositoryName); } break; case RequestTypes.GetAllPullRequests: if (!string.IsNullOrEmpty(settings.UserName) && !string.IsNullOrEmpty(settings.RepositoryName)) { urlString = SetUpApiString(GITHUB_PULL_REQUESTS_URL, settings.UserName, settings.RepositoryName); } break; case RequestTypes.GetAllBranches: if (!string.IsNullOrEmpty(settings.UserName) && !string.IsNullOrEmpty(settings.RepositoryName)) { urlString = SetUpApiString(GITHUB_BRANCHES_URL, settings.UserName, settings.RepositoryName); } break; case RequestTypes.LastCommits: if (!string.IsNullOrEmpty(settings.UserName) && !string.IsNullOrEmpty(settings.RepositoryName)) { urlString = SetUpApiString(GITHUB_COMMITS_URL, settings.UserName, settings.RepositoryName); } break; } return(urlString); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddHealthChecks(); // TODO: Permitir que a implementação seja escolhida por Settings services.AddGenerators(); services.AddMemoryPersistence(); services.AddAutoMapper(ProfileRegistration.GetProfiles()); services.AddMvc(); GitHubSettings = _configuration.GetSection(nameof(GitHubSettings)).Get <GitHubSettings>(); // TODO: Criar uma extension para facilitar a vida if (GitHubSettings == null) { throw new ArgumentNullException(nameof(GitHubSettings), "GitHub OAuth settings were not found. Did you forget to edit your appSettings.json?"); } services .AddAuthentication(opt => { opt.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; opt.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; opt.DefaultChallengeScheme = "GitHub"; }) .AddCookie() .AddGitHub("GitHub", opt => { opt.ClientId = GitHubSettings.ClientId; opt.ClientSecret = GitHubSettings.ClientSecret; opt.CallbackPath = new PathString(GitHubSettings.CallbackPath); opt.SaveTokens = true; opt.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id"); opt.ClaimActions.MapJsonKey(ClaimTypes.Name, "name"); opt.ClaimActions.MapJsonKey("urn:github:login", "login"); opt.ClaimActions.MapJsonKey("urn:github:url", "html_url"); opt.ClaimActions.MapJsonKey("urn:github:avatar", "avatar_url"); opt.Events = new OAuthEvents { OnCreatingTicket = async context => { var request = new HttpRequestMessage(HttpMethod.Get, context.Options.UserInformationEndpoint); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken); var response = await context.Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, context.HttpContext.RequestAborted); response.EnsureSuccessStatusCode(); var user = JObject.Parse(await response.Content.ReadAsStringAsync()); context.RunClaimActions(user); } }; }); // Armazenando as configurações do GitHub para uso Futuro services.Configure <GitHubSettings>(_configuration.GetSection(nameof(GitHubSettings))); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v1", Title = "NetCore Playground API", Description = "API para testes com .NET Core 2.2", Contact = new Contact { Name = "Rodolpho Alves", Url = @"https://github.com/rodolphocastro", Email = "*****@*****.**" } // TODO: Algum dia colocar um e-mail válido :shrug: }); c.AddSecurityDefinition("GitHub", new OAuth2Scheme { Type = "oauth2", Flow = "accessCode", AuthorizationUrl = "https://github.com/login/oauth/authorize", TokenUrl = "https://github.com/login/oauth/access_token" }); c.OperationFilter <SecurityRequirementsOperationFilter>(); }); }
public CoreGitHubRepositoriesFunction(GitHubSettings github, HttpClient httpClient) { _github = github; _httpClient = httpClient; }