public async Task <JiraCommentsResponse> GetCommentsAsync(JiraIssueReference issueReference, JiraCommentsRequest request, CancellationToken cancellationToken) { var comments = await store.GetComments(issueReference.Key ?? issueReference.Id); var maxResults = request.MaxResults == 0 ? maxPacketSize : Math.Min(request.MaxResults, maxPacketSize); return(new JiraCommentsResponse { Comments = comments.Skip(request.StartAt).Take(maxResults).ToArray(), Total = comments.Length, MaxResults = maxResults, StartAt = request.StartAt }); }
public async Task <JiraCommentsResponse> GetCommentsAsync(JiraIssueReference issueReference, JiraCommentsRequest request, CancellationToken cancellationToken) { var identifier = issueReference.Key ?? issueReference.Id; if (identifier == null) { throw new JiraException("issue's key and issue's id are null"); } var maxResults = request.MaxResults == 0 ? 50 : request.MaxResults; var responseMessage = await jira.GetAsync( $"{hostUrl}/rest/api/2/issue/{identifier}/comment?startAt={request.StartAt}&maxResults={maxResults}", cancellationToken); cancellationToken.ThrowIfCancellationRequested(); if (!responseMessage.IsSuccessStatusCode) { switch (responseMessage.StatusCode) { case HttpStatusCode.Unauthorized: throw new JiraAuthorizationException(); case HttpStatusCode.NotFound: throw new JiraException( $"issue '{identifier}' is not found or the user does not have permission to view it"); default: responseMessage.EnsureSuccessStatusCode(); break; } } var responseBody = await responseMessage.Content.ReadAsStringAsync(); cancellationToken.ThrowIfCancellationRequested(); var dto = Json.Deserialize <JiraCommentsResponseDto>(responseBody); return((JiraCommentsResponse)AutoMapper.Create <JiraCommentsResponseDto, JiraCommentsResponse>().Map(dto)); }