private GitHubClient GetClient(WatchedRepository repo) { if (string.IsNullOrWhiteSpace(repo.ApiToken)) { throw new ArgumentNullException(nameof(repo.ApiToken)); } if (string.IsNullOrWhiteSpace(repo.Url)) { throw new ArgumentNullException(nameof(repo.Url)); } if (_clientsByApiKey.TryGetValue(repo.ApiToken, out var existingClient)) { return(existingClient); } var authority = new Uri(repo.Url).GetLeftPart(UriPartial.Authority); var github = new Uri(authority, UriKind.Absolute); var client = new GitHubClient(new ProductHeaderValue(_productHeaderValue), github); var auth = new Credentials(repo.ApiToken); client.Credentials = auth; _clientsByApiKey[repo.ApiToken] = client; return(client); }
public async Task <IRepoManager> GetManagerAsync(WatchedRepository repo, bool refreshFromUpstream) { var prReader = _prReaderFactory.GetReader(repo); var manager = await RepositoryManager.InitializeAsync( repo.Owner, repo.Name, repo.Url, prReader, _cacheManager, _prApiDosBuffer, refreshFromUpstream, _logger); return(manager); }
public IRepoPullRequestReader GetReader(WatchedRepository repo) { if (repo is null) { throw new ArgumentNullException(nameof(repo)); } var allowed = repo.RepositoryKind == RepositoryKind.GitHub || repo.RepositoryKind == RepositoryKind.GitHubEnterprise; if (!allowed) { throw new ArgumentException($"Watched repository must be of type {RepositoryKind.GitHub} or {RepositoryKind.GitHubEnterprise}, but was {repo.RepositoryKind}"); } var client = GetClient(repo); return(new GitHubRepoPullRequestReader(repo.Owner, repo.Name, client, _bodyNormalizer)); }
public IRepoPullRequestReader GetReader(WatchedRepository repo) { switch (repo.RepositoryKind) { case RepositoryKind.GitHub: case RepositoryKind.GitHubEnterprise: return(_ghReaderFactory.GetReader(repo)); case RepositoryKind.BitBucketCloud: return(_bbReaderFactory.GetReader(repo)); case RepositoryKind.BitBucketServer: throw new NotImplementedException($"{RepositoryKind.BitBucketServer} is not implemented yet"); default: throw new ArgumentOutOfRangeException(); } }
public IRepoPullRequestReader GetReader(WatchedRepository repo) { if (repo is null) { throw new ArgumentNullException(nameof(repo)); } if (repo.RepositoryKind != RepositoryKind.BitBucketCloud) { throw new ArgumentException($"Watched repository must be of type {RepositoryKind.BitBucketCloud}, but was {repo.RepositoryKind}"); } var httpClient = GetClient(repo.Login, repo.ApiToken, repo.Url); return(new BitBucketCloudPullRequestReader( repo.Url, repo.Owner, repo.Name, httpClient, _jsonSerializerSettings, _clock, _logger)); }