public Task <IEnumerable <CustomField> > GetCustomFieldsForProjectAsync(string projectKey, CancellationToken token = default(CancellationToken)) { var options = new CustomFieldFetchOptions(); options.ProjectKeys.Add(projectKey); return(GetCustomFieldsAsync(options, token)); }
public async void CustomFieldsForProject_ShouldReturnAllCustomFieldsOfAllIssueTypes(Jira jira) { var options = new CustomFieldFetchOptions(); options.ProjectKeys.Add("TST"); var results = await jira.Fields.GetCustomFieldsAsync(options); Assert.Equal(21, results.Count()); }
public async void CustomFieldsForProject_IfProjectDoesNotExist_ShouldThrowException(Jira jira) { var options = new CustomFieldFetchOptions(); options.ProjectKeys.Add("FOO"); Exception ex = await Assert.ThrowsAsync <InvalidOperationException>(async() => await jira.Fields.GetCustomFieldsAsync(options)); Assert.Contains("Project with key 'FOO' was not found on the Jira server.", ex.Message); }
public async void CustomFieldsForProjectAndIssueType_ShouldReturnAllCustomFieldsTheIssueType(Jira jira) { var options = new CustomFieldFetchOptions(); options.ProjectKeys.Add("TST"); options.IssueTypeNames.Add("Bug"); var results = await jira.Fields.GetCustomFieldsAsync(options); Assert.Equal(19, results.Count()); }
public async Task <IEnumerable <CustomField> > GetCustomFieldsAsync(CustomFieldFetchOptions options, CancellationToken token = default(CancellationToken)) { var cache = _jira.Cache; var projectKey = options.ProjectKeys.FirstOrDefault(); var issueTypeId = options.IssueTypeIds.FirstOrDefault(); var issueTypeName = options.IssueTypeNames.FirstOrDefault(); if (!String.IsNullOrEmpty(issueTypeId) || !String.IsNullOrEmpty(issueTypeName)) { projectKey = $"{projectKey}::{issueTypeId}::{issueTypeName}"; } else if (String.IsNullOrEmpty(projectKey)) { return(await GetCustomFieldsAsync(token)); } if (!cache.ProjectCustomFields.TryGetValue(projectKey, out JiraEntityDictionary <CustomField> fields)) { var resource = $"rest/api/2/issue/createmeta?expand=projects.issuetypes.fields"; if (options.ProjectKeys.Any()) { resource += $"&projectKeys={String.Join(",", options.ProjectKeys)}"; } if (options.IssueTypeIds.Any()) { resource += $"&issuetypeIds={String.Join(",", options.IssueTypeIds)}"; } if (options.IssueTypeNames.Any()) { resource += $"&issuetypeNames={String.Join(",", options.IssueTypeNames)}"; } var jObject = await _jira.RestClient.ExecuteRequestAsync(Method.GET, resource, null, token).ConfigureAwait(false); var jProject = jObject["projects"].FirstOrDefault(); if (jProject == null) { throw new InvalidOperationException($"Project with key '{projectKey}' was not found on the Jira server."); } var serializerSettings = _jira.RestClient.Settings.JsonSerializerSettings; var customFields = jProject["issuetypes"].SelectMany(issueType => GetCustomFieldsFromIssueType(issueType, serializerSettings)); var distinctFields = customFields.GroupBy(c => c.Id).Select(g => g.First()); cache.ProjectCustomFields.TryAdd(projectKey, new JiraEntityDictionary <CustomField>(distinctFields)); } return(cache.ProjectCustomFields[projectKey].Values); }