public async Task <ActionResult> Get(int id, [FromQuery] string repo, [FromQuery] string state) { // Check if organization exists, otherwise not found if (!DoesOrganizationExist(id, out Organization organization)) { return(NotFound()); } // Then fetch data from PRs using that organization _logger.LogDebug("Fetching PRs for organization ID: " + id); // Create internal PullRequestRequest from data and fetch it PullRequestRequest request = CreatePullRequest(repo, state, organization.Repository.Name); IRepoBrowser browser = RepoBrowserFactory.CreateRepoBrowser(organization, _repoConfig, _memoryCache); PullRequestResponse response = await RepoBrowserFactory.GetPullRequests(request, browser); return(Json(response)); }
public void CreateSearchRepository_GH_RepoCreated() { IRepoBrowser searchRepo = RepoBrowserFactory.CreateRepoBrowser(_gitHubOrg, _repoConfigList, null); Assert.IsType <GithubRepoBrowser>(searchRepo); }
/// <summary> /// Gets the pull requests. /// </summary> /// <returns>The pull requests.</returns> /// <param name="pullRequest">Pull request request object.</param> /// <param name="repoBrowser">Repo browser.</param> public static async Task <PullRequestResponse> GetPullRequests(PullRequestRequest pullRequest, IRepoBrowser repoBrowser) { IAuthenticationService authService = repoBrowser.GetAuthenticationService(); ITransformationService transformationService = repoBrowser.GetTransformationService(); HttpMessageHandler httpMessageHandler = repoBrowser.GetHttpMessageHandler(); if (authService != null) { try { // First check authentication if (!authService.IsAuthenticated()) { await authService.Authenticate(httpMessageHandler); } } catch (Exception ex) { throw new InvalidOperationException("During authentication, the custom authentication service threw an exception: " + ex.Message); } } // Make the requests and repeat as necessary by the transformation class HttpClient httpClient = new HttpClient(httpMessageHandler); HttpResponseMessage httpResponse = null; PullRequestResponse prResponse = new PullRequestResponse(); bool repeatRequest = true; while (repeatRequest) { // Need a new request message every time HttpRequestMessage httpRequest = new HttpRequestMessage(); // Always add User-Agent header by default httpRequest.Headers.Add("User-Agent", "RepoBrowserService"); // Now make any transformations try { if (!transformationService.BeforeRequest(pullRequest, httpRequest)) { return(prResponse); } } catch (Exception ex) { throw new InvalidOperationException("Before making the request the custom transformation service threw an exception: " + ex.Message); } // Call the authentication transformation try { if (authService != null) { authService.BeforeRequest(httpRequest); httpResponse = await httpClient.SendAsync(httpRequest); authService.AfterResponse(httpResponse); } else { httpResponse = await httpClient.SendAsync(httpRequest); } } catch (Exception ex) { throw new InvalidOperationException("There was an error while making the actual web request: " + ex.Message); } try { repeatRequest = transformationService.AfterResponse(httpResponse, prResponse); } catch (Exception ex) { throw new InvalidOperationException("After receiving the response the custom transformation service threw an exception: " + ex.Message); } } return(prResponse); }