public async Task <JiraTransition[]> GetTransitionsAsync(JiraIssueReference issueReference, CancellationToken cancellationToken) { var issue = await store.Get(issueReference.Key ?? issueReference.Id); return(GetTransitions(issue)); }
public static bool Equals(object value1, string value2) { return(value1 != null && value1 switch { string actualStringValue => string.Equals(actualStringValue, value2, StringComparison.InvariantCultureIgnoreCase), DateTime actualDateValue => actualDateValue == FilterParseHelpers.ParseJiraDate(value2), int actualIntValue => actualIntValue == int.Parse(value2, CultureInfo.InvariantCulture), decimal actualDecimalValue => actualDecimalValue == decimal.Parse(value2, CultureInfo.InvariantCulture), float actualFloatValue => Math.Abs(actualFloatValue - float.Parse(value2, CultureInfo.InvariantCulture)) < 0.0001, double actualDoubleValue => Math.Abs(actualDoubleValue - double.Parse(value2, CultureInfo.InvariantCulture)) < 0.0001, long actualLongValue => actualLongValue == long.Parse(value2), JiraStatus actualStatusValue => actualStatusValue == value2, JiraIssueReference actualIssueReferenceValue => actualIssueReferenceValue == value2, JiraCustomFieldOption actualOptionValue => actualOptionValue == value2, JiraPriority actualPriorityValue => actualPriorityValue == value2, JiraProject actualProjectValue => actualProjectValue == value2, JiraUser actualUserValue => actualUserValue == value2, JiraIssueType actualIssueJiraType => actualIssueJiraType == value2, IEnumerable actualEnumerableValue => actualEnumerableValue.Cast <object>().Any(x => Equals(x, value2)), _ => false });
protected void AssertSingle <TIssue>(IQueryable <TIssue> query, JiraIssueReference reference) where TIssue : JiraIssue { var issues = query.ToArray(); Assert.That(issues.Length, Is.EqualTo(1)); Assert.That(issues[0].Key, Is.EqualTo(reference.Key)); }
public async Task UpdateIssueAsync(JiraIssueReference reference, JiraIssue fields, CancellationToken cancellationToken) { var jObject = fields.Controller.GetChangedFields(); jObject.SetProperty("updated", DateTime.Now); await store.Update(reference.Key ?? reference.Id, jObject); }
public void Strict() { var reference = new JiraIssueReference { Key = "SOME_KEY", Id = "SOME_ID", }; AssertQuery(Source <JiraIssue>() .Where(x => x.Parent == reference), "(parent = \"SOME_KEY\")"); }
public async Task InvokeTransitionAsync(JiraIssueReference issueReference, string transitionId, object fields, CancellationToken cancellationToken) { var identifier = issueReference.Key ?? issueReference.Id; if (identifier == null) { throw new JiraException("issue's key and issue's id are null"); } var invocation = new JiraTransitionInvocation { Fields = fields, Transition = new JiraTransitionDto { Id = transitionId } }; var requestJson = Json.Serialize(invocation); var content = new StringContent(requestJson, Encoding.UTF8, "application/json"); cancellationToken.ThrowIfCancellationRequested(); var responseMessage = await jira.PostAsync($"{hostUrl}/rest/api/2/issue/{identifier}/transitions", content, cancellationToken); cancellationToken.ThrowIfCancellationRequested(); if (!responseMessage.IsSuccessStatusCode) { switch (responseMessage.StatusCode) { case HttpStatusCode.Unauthorized: throw new JiraAuthorizationException(); case HttpStatusCode.BadRequest: var body = await responseMessage.Content.ReadAsStringAsync(); cancellationToken.ThrowIfCancellationRequested(); var errors = Json.Deserialize <JiraErrorMessages>(body); var errorMessages = errors?.ErrorMessages ?? new string[0]; throw new JiraException( $"can not invoke transition '{transitionId}' for issue '{identifier}', reason: " + string.Join("\n", errorMessages)); 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; } } }
public async Task UpdateIssueAsync(JiraIssueReference key, JiraIssue issue, CancellationToken cancellationToken) { var identifier = key.Key ?? key.Id; if (identifier == null) { throw new JiraException("issue's key and issue's id are null"); } var request = issue.Controller.GetChangedFields(); var requestJson = $"{{\"fields\": {request.ToJson()}}}"; cancellationToken.ThrowIfCancellationRequested(); var responseMessage = await jira.PutAsync(hostUrl + "/rest/api/2/issue/" + identifier, new StringContent(requestJson, Encoding.UTF8, "application/json"), cancellationToken); cancellationToken.ThrowIfCancellationRequested(); if (!responseMessage.IsSuccessStatusCode) { switch (responseMessage.StatusCode) { case HttpStatusCode.BadRequest: var body = await responseMessage.Content.ReadAsStringAsync(); cancellationToken.ThrowIfCancellationRequested(); var errors = Json.Deserialize <JiraErrorMessages[]>(body); var errorMessages = errors?.SelectMany(x => x.ErrorMessages).ToArray() ?? new string[0]; throw new JiraException(string.Join("\n", errorMessages)); case HttpStatusCode.Unauthorized: throw new JiraAuthorizationException(); case HttpStatusCode.Forbidden: throw new JiraException( "user uses 'overrideScreenSecurity' or 'overrideEditableFlag' but doesn't have the necessary permission"); 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; } } }
public async Task <JiraAttachment> UploadAttachmentAsync(JiraIssueReference issueReference, string fileName, byte[] bytes, CancellationToken cancellationToken) { var identifier = issueReference.Key ?? issueReference.Id; if (identifier == null) { throw new JiraException("issue's key and issue's id are null"); } var content = new MultipartFormDataContent(); var fileContent = new ByteArrayContent(bytes); content.Add(fileContent, "file", fileName); var responseMessage = await jira.PostAsync($"{hostUrl}/rest/api/2/issue/{identifier}/attachments", content, cancellationToken); if (!responseMessage.IsSuccessStatusCode) { switch (responseMessage.StatusCode) { case HttpStatusCode.Unauthorized: throw new JiraAuthorizationException(); case HttpStatusCode.Forbidden: throw new JiraException("user does not have the necessary permission"); case HttpStatusCode.NotFound: throw new JiraException( $"issue '{identifier}' is not found or the user does not have permission to view the issue"); case HttpStatusCode.RequestEntityTooLarge: throw new JiraException( $"attachments exceed the maximum attachment size for issues, filename [{fileName}]"); default: responseMessage.EnsureSuccessStatusCode(); break; } } var responseBody = await responseMessage.Content.ReadAsStringAsync(); return(Json.Deserialize <JiraAttachment[]>(responseBody)[0]); }
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 <JiraComment> AddCommentAsync(JiraIssueReference issueReference, JiraComment comment, CancellationToken cancellationToken) { var identifier = await store.GenerateId(); var result = new JiraComment { Author = comment.Author == (JiraUser)null ? authorizedUser : comment.Author, Body = comment.Body, Created = comment.Created == default ? DateTime.Now : comment.Created, Id = identifier.ToString(), Self = $"{fakeJiraUrl}/rest/api/2/issue/{issueReference.Id}/comment/{identifier}", Updated = comment.Updated == default ? DateTime.Now : comment.Updated, UpdateAuthor = comment.UpdateAuthor == (JiraUser)null ? authorizedUser : comment.UpdateAuthor }; await store.AddComment(issueReference.Key ?? issueReference.Id, result); return(result); }
public async Task <JiraAttachment> UploadAttachmentAsync(JiraIssueReference issueReference, string fileName, byte[] bytes, CancellationToken cancellationToken) { var identifier = await store.GenerateId(); var attachment = new JiraAttachment { Id = identifier.ToString(), Created = DateTime.Now, Filename = fileName, Size = bytes.Length, Content = $"{fakeJiraUrl}/secure/attachment/{identifier}/{HttpUtility.UrlEncode(fileName)}", Self = $"{fakeJiraUrl}/rest/api/2/attachment/{identifier}" }; await store.UploadAttachment(issueReference.Key ?? issueReference.Id, identifier, attachment, bytes); return(attachment); }
public async Task <JiraComment> AddCommentAsync(JiraIssueReference issueReference, JiraComment comment, CancellationToken cancellationToken) { var identifier = issueReference.Key ?? issueReference.Id; if (identifier == null) { throw new JiraException("issue's key and issue's id are null"); } var requestJson = Json.Serialize(comment); cancellationToken.ThrowIfCancellationRequested(); var content = new StringContent(requestJson, Encoding.UTF8, "application/json"); var responseMessage = await jira.PostAsync($"{hostUrl}/rest/api/2/issue/{identifier}/comment", content, 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(); return(Json.Deserialize <JiraComment>(responseBody)); }
public async Task InvokeTransitionAsync(JiraIssueReference issueReference, string transitionId, object fields, CancellationToken cancellationToken) { var issue = await store.Get(issueReference.Key ?? issueReference.Id); var jiraTransitions = GetTransitions(issue); var currentTransition = jiraTransitions.SingleOrDefault(x => string.Equals(x.Id, transitionId, StringComparison.InvariantCultureIgnoreCase)); if (currentTransition == null) { throw new JiraException( $"transition '{transitionId}' for issue '{issueReference.Key}', id: '{issueReference.Id}' is not found"); } if (fields != null) { throw new NotSupportedException(); } issue.IssueFields.SetProperty("status", currentTransition.To); await store.Update(issueReference.Key ?? issueReference.Id, issue.IssueFields); }
public async Task <JiraTransition[]> GetTransitionsAsync(JiraIssueReference issueReference, CancellationToken cancellationToken) { var identifier = issueReference.Key ?? issueReference.Id; if (identifier == null) { throw new JiraException("issue's key and issue's id are null"); } var responseMessage = await jira.GetAsync($"{hostUrl}/rest/api/2/issue/{identifier}/transitions", 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 jiraTransitionDtos = Json.Deserialize <JiraTransitionsResponse>(responseBody).Transitions; var autoMapper = AutoMapper.Create <JiraTransitionDto, JiraTransition>(); return(jiraTransitionDtos.Select(x => (JiraTransition)autoMapper.Map(x)).ToArray()); }
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)); }
/// <summary> /// Adds comment to an existing issue. /// </summary> /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param> /// <param name="issueReference">Reference to an existing issue. Should contains issue's key or issue's id.</param> /// <param name="comment">Comment model. Should contains Body.</param> /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception> /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception> /// <returns> /// Comment model with comment's id, comment's API url, comment's author, others. /// </returns> public static Task <JiraComment> AddCommentAsync(this IJira jira, JiraIssueReference issueReference, JiraComment comment) { return(jira.AddCommentAsync(issueReference, comment, CancellationToken.None)); }
/// <summary> /// Does update an existing issue. /// </summary> /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param> /// <param name="issueReference">Reference to an existing issue. Should contains issue's key or issue's id.</param> /// <param name="issue">An issue that contains fields to update.</param> /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception> /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception> public static void UpdateIssue(this IJira jira, JiraIssueReference issueReference, JiraIssue issue) { jira.UpdateIssueAsync(issueReference, issue, CancellationToken.None).GetAwaiter().GetResult(); }
/// <summary> /// Does update an existing issue. /// </summary> /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param> /// <param name="issueReference">Reference to an existing issue. Should contains issue's key or issue's id.</param> /// <param name="issue">An issue that contains fields to update.</param> /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception> /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception> public static Task UpdateIssueAsync(this IJira jira, JiraIssueReference issueReference, JiraIssue issue) { return(jira.UpdateIssueAsync(issueReference, issue, CancellationToken.None)); }
/// <summary> /// Uploads attachment to an existing issue. /// </summary> /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param> /// <param name="issueReference">Reference to an existing issue. Should contains issue's key or issue's id.</param> /// <param name="fileName">Filename of the attachment.</param> /// <param name="bytes">Content of the attachment.</param> /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception> /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception> /// <returns> /// Attachment's model that contains id of the attachment, URL to download, filename of attachment, others. /// </returns> public static JiraAttachment UploadAttachment(this IJira jira, JiraIssueReference issueReference, string fileName, byte[] bytes) { return(jira.UploadAttachmentAsync(issueReference, fileName, bytes, CancellationToken.None).GetAwaiter() .GetResult()); }
/// <summary> /// Invokes issue's transition. /// </summary> /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param> /// <param name="issueReference">Reference to an existing issue. Should contains issue's key or issue's id.</param> /// <param name="transitionId">Identifier of the transition.</param> /// <param name="fields">Fields to update.</param> /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception> /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception> public static Task InvokeTransitionAsync(this IJira jira, JiraIssueReference issueReference, string transitionId, object fields) { return(jira.InvokeTransitionAsync(issueReference, transitionId, fields, CancellationToken.None)); }
/// <summary> /// Invokes issue's transition. /// </summary> /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param> /// <param name="issueReference">Reference to an existing issue. Should contains issue's key or issue's id.</param> /// <param name="transitionId">Identifier of the transition.</param> /// <param name="fields">Fields to update.</param> /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception> /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception> public static void InvokeTransition(this IJira jira, JiraIssueReference issueReference, string transitionId, object fields) { jira.InvokeTransitionAsync(issueReference, transitionId, fields, CancellationToken.None).GetAwaiter() .GetResult(); }
/// <summary> /// Gets transitions' list of an existing issue. /// </summary> /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param> /// <param name="issueReference">Reference to an existing issue. Should contains issue's key or issue's id.</param> /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception> /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception> /// <returns> /// List of issue's transitions. /// </returns> public static Task <JiraTransition[]> GetTransitionsAsync(this IJira jira, JiraIssueReference issueReference) { return(jira.GetTransitionsAsync(issueReference, CancellationToken.None)); }
/// <summary> /// Uploads attachment to an existing issue. /// </summary> /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param> /// <param name="issueReference">Reference to an existing issue. Should contains issue's key or issue's id.</param> /// <param name="fileName">Filename of the attachment.</param> /// <param name="bytes">Content of the attachment.</param> /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception> /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception> /// <returns> /// Attachment's model that contains id of the attachment, URL to download, filename of attachment, others. /// </returns> public static Task <JiraAttachment> UploadAttachmentAsync(this IJira jira, JiraIssueReference issueReference, string fileName, byte[] bytes) { return(jira.UploadAttachmentAsync(issueReference, fileName, bytes, CancellationToken.None)); }
/// <summary> /// Adds comment to an existing issue. /// </summary> /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param> /// <param name="issueReference">Reference to an existing issue. Should contains issue's key or issue's id.</param> /// <param name="comment">Comment model. Should contains Body.</param> /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception> /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception> /// <returns> /// Comment model with comment's id, comment's API url, comment's author, others. /// </returns> public static JiraComment AddComment(this IJira jira, JiraIssueReference issueReference, JiraComment comment) { return(jira.AddCommentAsync(issueReference, comment, CancellationToken.None).GetAwaiter().GetResult()); }
/// <summary> /// Gets an issue's comments. /// </summary> /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param> /// <param name="issueReference">Reference to an existing issue. Should contains issue's key or issue's id.</param> /// <param name="request">Request that contains information about a required window.</param> /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception> /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception> /// <returns> /// Response that contains comments, comments' count, additional information from request. /// </returns> public static JiraCommentsResponse GetComments(this IJira jira, JiraIssueReference issueReference, JiraCommentsRequest request) { return(jira.GetCommentsAsync(issueReference, request, CancellationToken.None).GetAwaiter().GetResult()); }
/// <summary> /// Gets an issue's comments. /// </summary> /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param> /// <param name="issueReference">Reference to an existing issue. Should contains issue's key or issue's id.</param> /// <param name="request">Request that contains information about a required window.</param> /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception> /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception> /// <returns> /// Response that contains comments, comments' count, additional information from request. /// </returns> public static Task <JiraCommentsResponse> GetCommentsAsync(this IJira jira, JiraIssueReference issueReference, JiraCommentsRequest request) { return(jira.GetCommentsAsync(issueReference, request, CancellationToken.None)); }
/// <summary> /// Gets transitions' list of an existing issue. /// </summary> /// <param name="jira">Instance of <c>SimpleJira.Interface.IJira</c>.</param> /// <param name="issueReference">Reference to an existing issue. Should contains issue's key or issue's id.</param> /// <exception cref="SimpleJira.Interface.JiraAuthorizationException">Throws exception when user is not authorized.</exception> /// <exception cref="SimpleJira.Interface.JiraException">Throws exception in other cases.</exception> /// <returns> /// List of issue's transitions. /// </returns> public static JiraTransition[] GetTransitions(this IJira jira, JiraIssueReference issueReference) { return(jira.GetTransitionsAsync(issueReference, CancellationToken.None).GetAwaiter().GetResult()); }