diff --git a/TechTalk.JiraRestClient/Compatibility.cs b/TechTalk.JiraRestClient/Compatibility.cs index 9089172..cb30bb0 100644 --- a/TechTalk.JiraRestClient/Compatibility.cs +++ b/TechTalk.JiraRestClient/Compatibility.cs @@ -198,6 +198,16 @@ public void DeleteAttachment(Attachment attachment) client.DeleteAttachment(attachment); } + public IEnumerable GetWorklogList(int[] ids) + { + return client.GetWorklogList(ids); + } + + public IEnumerable GetWorklogsByIssueId(int id) + { + return client.GetWorklogsByIssueId(id); + } + public IEnumerable GetIssueLinks(IssueRef issue) { return client.GetIssueLinks(issue); diff --git a/TechTalk.JiraRestClient/IJiraClient.cs b/TechTalk.JiraRestClient/IJiraClient.cs index 5205faa..4534b7b 100644 --- a/TechTalk.JiraRestClient/IJiraClient.cs +++ b/TechTalk.JiraRestClient/IJiraClient.cs @@ -45,6 +45,12 @@ namespace TechTalk.JiraRestClient /// Changes the state of the given issue as described by the transition Issue TransitionIssue(IssueRef issue, Transition transition); + /// Returns worklogs for given worklog ids + IEnumerable GetWorklogList(int[] ids); + + /// Returns worklogs by issue id + IEnumerable GetWorklogsByIssueId(int id); + /// Returns all watchers for the given issue IEnumerable GetWatchers(IssueRef issue); diff --git a/TechTalk.JiraRestClient/IssueFields.cs b/TechTalk.JiraRestClient/IssueFields.cs index 1790e6a..7f323d0 100644 --- a/TechTalk.JiraRestClient/IssueFields.cs +++ b/TechTalk.JiraRestClient/IssueFields.cs @@ -30,5 +30,7 @@ public IssueFields() public List comments { get; set; } public List issuelinks { get; set; } public List attachment { get; set; } + + public List worklogs { get; set; } } } diff --git a/TechTalk.JiraRestClient/JiraClient.cs b/TechTalk.JiraRestClient/JiraClient.cs index 42fc27e..7c976b0 100644 --- a/TechTalk.JiraRestClient/JiraClient.cs +++ b/TechTalk.JiraRestClient/JiraClient.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Net; using System.Text; +using TechTalk.JiraRestClient.Utils; using RestSharp; using RestSharp.Deserializers; @@ -48,6 +49,51 @@ private void AssertStatus(IRestResponse response, HttpStatusCode status) throw new JiraClientException("JIRA returned wrong status: " + response.StatusDescription, response.Content); } + /// + /// Get Worklog List by worklog's id + /// + /// + /// + public IEnumerable GetWorklogList(int[] ids) + { + try + { + var request = CreateRequest(Method.GET, "worklog/list"); + request.AddHeader("ContentType", "application/json"); + request.AddBody(new { ids = ids }); + + var response = ExecuteRequest(request); + AssertStatus(response, HttpStatusCode.OK); + + var data = deserializer.Deserialize>(response); + return data; + } + catch (Exception ex) + { + Trace.TraceError("GetWorklogList() error: {0}", ex); + throw new JiraClientException("Could not load worklog list", ex); + } + } + + public IEnumerable GetWorklogsByIssueId(int id) + { + try + { + var request = CreateRequest(Method.GET, $"/{id}/worklog"); + request.AddHeader("ContentType", "application/json"); + + var response = ExecuteRequest(request); + AssertStatus(response, HttpStatusCode.OK); + + var data = deserializer.Deserialize>(response); + return data; + } + catch (Exception ex) + { + Trace.TraceError("GetWorklogsByIssueId() error: {0}", ex); + throw new JiraClientException("Could not load worklog list of issue", ex); + } + } public IEnumerable> GetIssues(String projectKey) { diff --git a/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj b/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj index bd93afe..4b309a0 100644 --- a/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj +++ b/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj @@ -63,6 +63,7 @@ + diff --git a/TechTalk.JiraRestClient/Worklog.cs b/TechTalk.JiraRestClient/Worklog.cs new file mode 100644 index 0000000..1885056 --- /dev/null +++ b/TechTalk.JiraRestClient/Worklog.cs @@ -0,0 +1,16 @@ +using System; + +namespace TechTalk.JiraRestClient +{ + public class Worklog + { + public JiraUser author { get; set; } + public JiraUser updateAuthor { get; set; } + public string comment { get; set; } + public DateTime updated { get; set; } + public string timeSpent { get; set; } + public int timeSpentSeconds { get; set; } + public string id { get; set; } + public string issueId { get; set; } + } +}