From 08acd3d81c2dea8fc4010c8c355ccf7bf9e2a0d4 Mon Sep 17 00:00:00 2001 From: Daryayan Date: Wed, 16 Mar 2022 20:23:01 +0300 Subject: [PATCH 1/4] #38 issue for Worklog Adding new Entity - worklog Adding the ability to get the worklog list --- TechTalk.JiraRestClient/Compatibility.cs | 10 ++++ TechTalk.JiraRestClient/IJiraClient.cs | 6 +++ TechTalk.JiraRestClient/IssueFields.cs | 2 + TechTalk.JiraRestClient/JiraClient.cs | 46 +++++++++++++++++++ .../TechTalk.JiraRestClient.csproj | 1 + TechTalk.JiraRestClient/Worklog.cs | 6 +++ 6 files changed, 71 insertions(+) create mode 100644 TechTalk.JiraRestClient/Worklog.cs 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..20e1281 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.POST, "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.POST, $"/{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..3cc75e9 --- /dev/null +++ b/TechTalk.JiraRestClient/Worklog.cs @@ -0,0 +1,6 @@ +namespace TechTalk.JiraRestClient +{ + public class Worklog + { + } +} \ No newline at end of file From 4481895e2ee9a39b4c12665ca436090844065e53 Mon Sep 17 00:00:00 2001 From: Daryayan Date: Wed, 16 Mar 2022 20:27:34 +0300 Subject: [PATCH 2/4] Adding properties for Worklog --- TechTalk.JiraRestClient/Worklog.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/TechTalk.JiraRestClient/Worklog.cs b/TechTalk.JiraRestClient/Worklog.cs index 3cc75e9..e23f254 100644 --- a/TechTalk.JiraRestClient/Worklog.cs +++ b/TechTalk.JiraRestClient/Worklog.cs @@ -1,6 +1,16 @@ -namespace TechTalk.JiraRestClient +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; } } } \ No newline at end of file From c285015792ddc9db5889fded08411081d7a6922e Mon Sep 17 00:00:00 2001 From: Daryayan Date: Sun, 20 Mar 2022 12:12:46 +0300 Subject: [PATCH 3/4] #fix method --- TechTalk.JiraRestClient/JiraClient.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TechTalk.JiraRestClient/JiraClient.cs b/TechTalk.JiraRestClient/JiraClient.cs index 20e1281..7c976b0 100644 --- a/TechTalk.JiraRestClient/JiraClient.cs +++ b/TechTalk.JiraRestClient/JiraClient.cs @@ -58,7 +58,7 @@ public IEnumerable GetWorklogList(int[] ids) { try { - var request = CreateRequest(Method.POST, "worklog/list"); + var request = CreateRequest(Method.GET, "worklog/list"); request.AddHeader("ContentType", "application/json"); request.AddBody(new { ids = ids }); @@ -79,7 +79,7 @@ public IEnumerable GetWorklogsByIssueId(int id) { try { - var request = CreateRequest(Method.POST, $"/{id}/worklog"); + var request = CreateRequest(Method.GET, $"/{id}/worklog"); request.AddHeader("ContentType", "application/json"); var response = ExecuteRequest(request); From 9c0498bcff0968b53bd2fae347ea072f564778a1 Mon Sep 17 00:00:00 2001 From: Daryayan Date: Sun, 20 Mar 2022 12:14:47 +0300 Subject: [PATCH 4/4] # Adding newline --- TechTalk.JiraRestClient/Worklog.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TechTalk.JiraRestClient/Worklog.cs b/TechTalk.JiraRestClient/Worklog.cs index e23f254..1885056 100644 --- a/TechTalk.JiraRestClient/Worklog.cs +++ b/TechTalk.JiraRestClient/Worklog.cs @@ -13,4 +13,4 @@ public class Worklog public string id { get; set; } public string issueId { get; set; } } -} \ No newline at end of file +}