Skip to content

Commit

Permalink
Small fix for the comment methods, and the used entities, in the issu…
Browse files Browse the repository at this point in the history
…e domain.

[release]
  • Loading branch information
Lakritzator committed Jan 24, 2017
1 parent 685ece5 commit 62e95df
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Dapplo.Jira/Entities/BaseId.cs
Expand Up @@ -21,6 +21,7 @@

#region using

using System.ComponentModel;
using System.Runtime.Serialization;

#endregion
Expand All @@ -36,7 +37,7 @@ public class BaseId<TId>
/// <summary>
/// Id of this entity
/// </summary>
[DataMember(Name = "id", EmitDefaultValue = false)]
[DataMember(Name = "id", EmitDefaultValue = false), ReadOnly(true)]
public TId Id { get; set; }
}
}
3 changes: 2 additions & 1 deletion Dapplo.Jira/Entities/BaseProperties.cs
Expand Up @@ -22,6 +22,7 @@
#region using

using System;
using System.ComponentModel;
using System.Runtime.Serialization;

#endregion
Expand All @@ -37,7 +38,7 @@ public class BaseProperties<TId> : BaseId<TId>
/// <summary>
/// Link to itself
/// </summary>
[DataMember(Name = "self", EmitDefaultValue = false)]
[DataMember(Name = "self", EmitDefaultValue = false), ReadOnly(true)]
public Uri Self { get; set; }
}
}
9 changes: 5 additions & 4 deletions Dapplo.Jira/Entities/Comment.cs
Expand Up @@ -22,6 +22,7 @@
#region using

using System;
using System.ComponentModel;
using System.Runtime.Serialization;

#endregion
Expand All @@ -38,7 +39,7 @@ public class Comment : BaseProperties<long>
/// <summary>
/// Who created the comment
/// </summary>
[DataMember(Name = "author", EmitDefaultValue = false)]
[DataMember(Name = "author", EmitDefaultValue = false), ReadOnly(true)]
public User Author { get; set; }

/// <summary>
Expand All @@ -50,19 +51,19 @@ public class Comment : BaseProperties<long>
/// <summary>
/// When was the comment created
/// </summary>
[DataMember(Name = "created", EmitDefaultValue = false)]
[DataMember(Name = "created", EmitDefaultValue = false), ReadOnly(true)]
public DateTimeOffset Created { get; set; }

/// <summary>
/// Who updated the comment
/// </summary>
[DataMember(Name = "updateAuthor", EmitDefaultValue = false)]
[DataMember(Name = "updateAuthor", EmitDefaultValue = false), ReadOnly(true)]
public User UpdateAuthor { get; set; }

/// <summary>
/// When was the comment updated
/// </summary>
[DataMember(Name = "updated", EmitDefaultValue = false)]
[DataMember(Name = "updated", EmitDefaultValue = false), ReadOnly(true)]
public DateTimeOffset Updated { get; set; }

/// <summary>
Expand Down
21 changes: 10 additions & 11 deletions Dapplo.Jira/IssueExtensions.cs
Expand Up @@ -58,7 +58,8 @@ public static class IssueExtensions
/// <param name="body">the body of the comment</param>
/// <param name="visibility">optional visibility role</param>
/// <param name="cancellationToken">CancellationToken</param>
public static async Task AddCommentAsync(this IIssueDomain jiraClient, string issueKey, string body, string visibility = null, CancellationToken cancellationToken = default(CancellationToken))
/// <returns>Comment</returns>
public static async Task<Comment> AddCommentAsync(this IIssueDomain jiraClient, string issueKey, string body, string visibility = null, CancellationToken cancellationToken = default(CancellationToken))
{
if (issueKey == null)
{
Expand All @@ -76,7 +77,8 @@ public static async Task AddCommentAsync(this IIssueDomain jiraClient, string is
};
jiraClient.Behaviour.MakeCurrent();
var attachUri = jiraClient.JiraRestUri.AppendSegments("issue", issueKey, "comment");
await attachUri.PostAsync(comment, cancellationToken).ConfigureAwait(false);
var response = await attachUri.PostAsync<HttpResponse<Comment, Error>>(comment, cancellationToken).ConfigureAwait(false);
return response.HandleErrors(HttpStatusCode.Created);
}

/// <summary>
Expand Down Expand Up @@ -195,7 +197,8 @@ public static async Task<IList<Transition>> GetPossibleTransitionsAsync(this IIs
/// <param name="issueKey">jira key to which the comment belongs</param>
/// <param name="comment">Comment to update</param>
/// <param name="cancellationToken">CancellationToken</param>
public static async Task UpdateCommentAsync(this IIssueDomain jiraClient, string issueKey, Comment comment, CancellationToken cancellationToken = default(CancellationToken))
/// <returns>Comment</returns>
public static async Task<Comment> UpdateCommentAsync(this IIssueDomain jiraClient, string issueKey, Comment comment, CancellationToken cancellationToken = default(CancellationToken))
{
if (issueKey == null)
{
Expand All @@ -207,7 +210,8 @@ public static async Task UpdateCommentAsync(this IIssueDomain jiraClient, string
jiraClient.Behaviour.MakeCurrent();

var attachUri = jiraClient.JiraRestUri.AppendSegments("issue", issueKey, "comment", comment.Id);
await attachUri.PutAsync(comment, cancellationToken).ConfigureAwait(false);
var response = await attachUri.PutAsync<HttpResponse<Comment, Error>>(comment, cancellationToken).ConfigureAwait(false);
return response.HandleErrors();
}

/// <summary>
Expand Down Expand Up @@ -241,7 +245,7 @@ public static async Task<Issue> CreateAsync(this IIssueDomain jiraClient, Issue
jiraClient.Behaviour.MakeCurrent();
var issueUri = jiraClient.JiraRestUri.AppendSegments("issue");
var response = await issueUri.PostAsync<HttpResponse<Issue, Error>>(issue, cancellationToken).ConfigureAwait(false);
return response.HandleErrors();
return response.HandleErrors(HttpStatusCode.Created);
}

/// <summary>
Expand All @@ -265,12 +269,7 @@ public static async Task DeleteAsync(this IIssueDomain jiraClient, string issueK
issueUri = issueUri.ExtendQuery("deleteSubtasks", true);
}
var response = await issueUri.DeleteAsync<HttpResponse>(cancellationToken).ConfigureAwait(false);
if (response.StatusCode != HttpStatusCode.NoContent)
{
var message = response.StatusCode.ToString();
Log.Warn().WriteLine("Http status code: {0}. Response from server: {1}", response.StatusCode, message);
throw new Exception($"Status: {response.StatusCode} Message: {message}");
}
response.HandleStatusCode(HttpStatusCode.NoContent);
}

/// <summary>
Expand Down

0 comments on commit 62e95df

Please sign in to comment.