private async Task UploadIssuesBatch(IPagedQueryResult <Issue> jiraResponse) { var elasticRequest = new JiraElasticUpsertRequest { Entities = CreateUpsertData(jiraResponse) }; await _elasticsearchClient.UpsertManyAsync(elasticRequest); var titlesWithIds = jiraResponse.Select(s => $" {s.Summary}-{s.Key}"); _logger.LogInformation("JiraJob | {BatchUploadDate} | remains to load: {countOfRemaining} | batch loaded: [{uploadedDataIdentifiers}]", DateTime.Now, jiraResponse.TotalItems, string.Join(',', titlesWithIds)); }
public async Task <IList <IssueLight> > GetAllIssuesInProject(IReadOnlyCollection <JiraNamedObjectLight> customFields) { if (customFields == null) { throw new ArgumentNullException(nameof(customFields)); } var epicField = customFields.First(cf => cf.Name == _jiraContext.EpicLinkName); var storyPointsField = customFields.First(cf => cf.Name == _jiraContext.StoryPointsName); bool useStatus = _jiraContext.ExcludedStatuses?.LongLength > 0; bool useCreated = false; bool useEpics = _jiraContext.Epics?.Any() ?? false; string epics = string.Join(',', _jiraContext.Epics?.Select(i => $"\"{i}\"") ?? Enumerable.Empty <string>()); string excludedStatuses = string.Join(',', _jiraContext.ExcludedStatuses ?? Enumerable.Empty <string>()); var createdFilterPart = $@" AND Created > ""{DateTime.Today.AddDays(-_jiraContext.DaysBackToFetchIssues).Date:yyyy-MM-dd}"" "; var statusFilterPart = $" AND Status NOT IN ( {excludedStatuses} ) "; var epicFilterPart = $@" AND (""{epicField.Name}"" in ({epics}) OR parent in ({epics}) OR id in ({epics}) ) "; var searchOptions = new IssueSearchOptions( $@" Project = ""{_jiraContext.Project}""{(useStatus ? statusFilterPart:"")}{(useEpics ? epicFilterPart:"")}{(useCreated ? createdFilterPart: "")} ") { StartAt = 0, FetchBasicFields = false, AdditionalFields = new[] { "key", "assignee", "reporter", "created", "summary", "status", "issuetype", epicField.Id, storyPointsField.Id, "parent", "labels" } }; Console.WriteLine($"JQL: {searchOptions.Jql}"); var result = new List <IssueLight>(); IPagedQueryResult <Issue> pages = null; do { pages = await _jira.Issues.GetIssuesFromJqlAsync(searchOptions).ConfigureAwait(false); Debug.Assert(pages != null); result.AddRange(pages.Select(i => i.ToIssueLight(epicField.Id, storyPointsField.Id))); searchOptions.StartAt = Math.Min(searchOptions.StartAt + pages.ItemsPerPage, pages.TotalItems); } while (searchOptions.StartAt < pages.TotalItems); return(result); }