public virtual async Task <DataResponse <IEnumerable <IBuildDefinition> > > GetBuildDefinitionsAsync(BuildMonitorSettings settings) { var projectUrl = settings.GetValueStrict <String>(ProjectUrlSettingKey).TrimEnd('/'); if (!String.IsNullOrWhiteSpace(projectUrl)) { var requestUrl = $"{projectUrl}/_apis/build/definitions?api-version={ApiVersion}"; var requestResponse = await GetRequestResponseAsync(requestUrl, settings).ConfigureAwait(false); requestResponse.ThrowIfUnsuccessful(); var result = await requestResponse.Content.ReadAsStringAsync().ConfigureAwait(false); var data = JsonConvert.DeserializeObject <List <TBuildDefinition> >(JObject.Parse(result)["value"].ToString()); foreach (var buildDefinition in data) { buildDefinition.BuildSettingsId = settings.UniqueId; } return(new DataResponse <IEnumerable <IBuildDefinition> > { Data = data, StatusCode = requestResponse.StatusCode }); } throw new Exception("Error while processing method!"); }
private static async Task <HttpResponseMessage> GetRequestResponseAsync(String requestUrl, BuildMonitorSettings settings) { var credentials = settings.GetValueStrict <ICredentials>(ProjectCredentialsSettingKey); var accessToken = settings.GetDefaultValueIfNotExists <String>(PersonalAccessTokenSettingsKey); if (!String.IsNullOrWhiteSpace(accessToken)) { return(await HttpRequestHelper.GetRequestResponseAsync(requestUrl, accessToken).ConfigureAwait(false)); } return(await HttpRequestHelper.GetRequestResponseAsync(requestUrl, credentials).ConfigureAwait(false)); }
public virtual async Task <DataResponse <IEnumerable <IBuild> > > GetBuildsByPullRequestsAsync(BuildMonitorSettings settings) { var projectUrl = settings.GetValueStrict <String>(ProjectUrlSettingKey).TrimEnd('/'); var requestUrl = $"{projectUrl}/_apis/git/pullrequests?api-version={ApiVersion}"; var requestResponse = await GetRequestResponseAsync(requestUrl, settings).ConfigureAwait(false); requestResponse.ThrowIfUnsuccessful(); var dict = new Dictionary <IPullRequest, IEnumerable <TBuild> >(); var result = await requestResponse.Content.ReadAsStringAsync().ConfigureAwait(false); var data = JsonConvert.DeserializeObject <List <TPullRequest> >(JObject.Parse(result)["value"].ToString()); foreach (var pullRequest in data) { var buildsResponse = await GetBuildsOfPullRequestAsync(pullRequest, settings).ConfigureAwait(false); if (buildsResponse.IsSuccessStatusCode) { dict.Add(pullRequest, buildsResponse.Data); } else { throw new Exception("Error while processing method!"); } } // sets the relation of the PR to the build object foreach (var keyValuePair in dict) { foreach (var build in keyValuePair.Value) { build.PullRequest = keyValuePair.Key; } } return(new DataResponse <IEnumerable <IBuild> > { Data = dict.Values.SelectMany(a => a).ToList(), StatusCode = requestResponse.StatusCode }); }
private async Task <DataResponse <IEnumerable <TBuild> > > GetBuildsOfPullRequestAsync(IPullRequest pullRequest, BuildMonitorSettings settings) { var projectUrl = settings.GetValueStrict <String>(ProjectUrlSettingKey).TrimEnd('/'); var maxBuilds = settings.GetDefaultValueIfNotExists <Int32?>(MaxBuildsPerDefinitionSettingsKey) ?? 5; // use fallback value when no value was defined via settings var requestUrl = $"{projectUrl}/_apis/build/builds?api-version={ApiVersion}&branchName=refs%2Fpull%2F{pullRequest.Id}%2Fmerge&$top={maxBuilds}"; var requestResponse = await GetRequestResponseAsync(requestUrl, settings).ConfigureAwait(false); requestResponse.ThrowIfUnsuccessful(); var result = await requestResponse.Content.ReadAsStringAsync().ConfigureAwait(false); var data = JsonConvert.DeserializeObject <List <TBuild> >(JObject.Parse(result)["value"].ToString()); await ResolveAdditionalBuildDataAsync(settings, data, projectUrl).ConfigureAwait(false); return(new DataResponse <IEnumerable <TBuild> > { Data = data, StatusCode = requestResponse.StatusCode }); }
public virtual async Task <DataResponse <IEnumerable <IBuild> > > GetBuildsAsync(IEnumerable <IBuildDefinition> buildDefinitions, BuildMonitorSettings settings) { var buildDefinitionsList = buildDefinitions.ToList(); if (!buildDefinitionsList.Any()) { return(new DataResponse <IEnumerable <IBuild> > { Data = Enumerable.Empty <TBuild>(), StatusCode = HttpStatusCode.NoContent }); } var projectUrl = settings.GetValueStrict <String>(ProjectUrlSettingKey).TrimEnd('/'); var maxBuilds = settings.GetDefaultValueIfNotExists <Int32?>(MaxBuildsPerDefinitionSettingsKey) ?? 5; // use fallback value when no value was defined via settings if (!String.IsNullOrWhiteSpace(projectUrl)) { var buildDefinitionsCommaList = String.Join(",", buildDefinitionsList.Select(a => a.Id)); var requestUrl = $"{projectUrl}/_apis/build/builds?api-version={ApiVersion}&definitions={buildDefinitionsCommaList}&maxBuildsPerDefinition={maxBuilds}"; var requestResponse = await GetRequestResponseAsync(requestUrl, settings).ConfigureAwait(false); requestResponse.ThrowIfUnsuccessful(); var result = await requestResponse.Content.ReadAsStringAsync().ConfigureAwait(false); var data = JsonConvert.DeserializeObject <List <TBuild> >(JObject.Parse(result)["value"].ToString()); await ResolveAdditionalBuildDataAsync(settings, data, projectUrl).ConfigureAwait(false); return(new DataResponse <IEnumerable <IBuild> > { Data = data, StatusCode = requestResponse.StatusCode }); } throw new Exception("Error while processing method!"); }