From 6ff208899cd529370b36a5e492c409bdd6ef4b2b Mon Sep 17 00:00:00 2001 From: schoetbi Date: Mon, 13 Apr 2015 15:50:55 +0200 Subject: [PATCH 1/8] Added Attribute to name properties This was needed to implement initialization of the "environment" field Now it is possible to have differences between propertynames and form-keys --- TechTalk.JiraRestClient/FieldAttribute.cs | 14 ++ TechTalk.JiraRestClient/JiraClient.cs | 44 +++++- .../TechTalk.JiraRestClient.csproj | 143 +++++++++--------- TechTalk.JiraRestClient/packages.config | 6 +- 4 files changed, 125 insertions(+), 82 deletions(-) create mode 100644 TechTalk.JiraRestClient/FieldAttribute.cs diff --git a/TechTalk.JiraRestClient/FieldAttribute.cs b/TechTalk.JiraRestClient/FieldAttribute.cs new file mode 100644 index 0000000..e778471 --- /dev/null +++ b/TechTalk.JiraRestClient/FieldAttribute.cs @@ -0,0 +1,14 @@ +namespace TechTalk.JiraRestClient +{ + using System; + + public class FieldAttribute : Attribute + { + public string FieldName { get; set; } + + public FieldAttribute(string fieldName) + { + this.FieldName = fieldName; + } + } +} \ No newline at end of file diff --git a/TechTalk.JiraRestClient/JiraClient.cs b/TechTalk.JiraRestClient/JiraClient.cs index b13346e..5128cf7 100644 --- a/TechTalk.JiraRestClient/JiraClient.cs +++ b/TechTalk.JiraRestClient/JiraClient.cs @@ -9,7 +9,12 @@ using RestSharp.Deserializers; namespace TechTalk.JiraRestClient -{ +{ + using System.Diagnostics.Eventing.Reader; + using System.Reflection; + + using RestSharp.Extensions; + //JIRA REST API documentation: https://docs.atlassian.com/jira/REST/latest public class JiraClient : IJiraClient where TIssueFields : IssueFields, new() @@ -147,7 +152,7 @@ public Issue CreateIssue(String projectKey, String issueType, TIss { try { - var request = CreateRequest(Method.POST, "issue"); + var request = this.CreateRequest(Method.POST, "issue"); request.AddHeader("ContentType", "application/json"); var issueData = new Dictionary(); @@ -163,11 +168,21 @@ public Issue CreateIssue(String projectKey, String issueType, TIss if (issueFields.timetracking != null) issueData.Add("timetracking", new { originalEstimate = issueFields.timetracking.originalEstimate }); - var propertyList = typeof(TIssueFields).GetProperties().Where(p => p.Name.StartsWith("customfield_")); - foreach (var property in propertyList) + var propertyInfos = typeof(TIssueFields).GetProperties().ToArray(); + var propertiesFromAttribute = propertyInfos.Select(p => new { Property = p, FieldAttribute = p.GetAttribute() }) + .Where(a => a.FieldAttribute != null) + .Select(p => new NamedProperty(p.Property, p.FieldAttribute.FieldName)); + + var customFields = propertyInfos.Where(p => p.Name.StartsWith("customfield_")).Select(p => new NamedProperty(p, p.Name)); + var propertyList = customFields.Concat(propertiesFromAttribute); + + foreach (var namedProperty in propertyList) { - var value = property.GetValue(issueFields, null); - if (value != null) issueData.Add(property.Name, value); + var value = namedProperty.Property.GetValue(issueFields, null); + if (value != null) + { + issueData.Add(namedProperty.FieldName, value); + } } request.AddBody(new { fields = issueData }); @@ -623,6 +638,19 @@ public ServerInfo GetServerInfo() Trace.TraceError("GetServerInfo() error: {0}", ex); throw new JiraClientException("Could not retrieve server information", ex); } - } - } + } + } + + public class NamedProperty + { + public PropertyInfo Property { get; set; } + + public string FieldName { get; set; } + + public NamedProperty(PropertyInfo property, string fieldName) + { + this.Property = property; + this.FieldName = fieldName; + } + } } diff --git a/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj b/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj index cf1f1d6..94c3338 100644 --- a/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj +++ b/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj @@ -1,78 +1,79 @@ - - - - Debug - x86 - 8.0.30703 - 2.0 - {210529FA-454E-4C32-A2C8-353ECBD4DA05} - Library - Properties - TechTalk.JiraRestClient - TechTalk.JiraRestClient - v4.0 - Client - 512 - ..\ - true - - - - - - AnyCPU - bin\Debug\ - DEBUG;TRACE - - - AnyCPU - bin\Release\ - TRACE - - - - ..\packages\RestSharp.104.1\lib\net4-client\RestSharp.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - - + + + + Debug + x86 + 8.0.30703 + 2.0 + {210529FA-454E-4C32-A2C8-353ECBD4DA05} + Library + Properties + TechTalk.JiraRestClient + TechTalk.JiraRestClient + v4.0 + Client + 512 + ..\ + true + + + + + + AnyCPU + bin\Debug\ + DEBUG;TRACE + + + AnyCPU + bin\Release\ + TRACE + + + + ..\packages\RestSharp.104.1\lib\net4-client\RestSharp.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Designer + + + + + --> \ No newline at end of file diff --git a/TechTalk.JiraRestClient/packages.config b/TechTalk.JiraRestClient/packages.config index a64d06c..0ff7e92 100644 --- a/TechTalk.JiraRestClient/packages.config +++ b/TechTalk.JiraRestClient/packages.config @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file From c92f2d4aa16e2b92ec8aad80492c9ab182c7e442 Mon Sep 17 00:00:00 2001 From: schoetbi Date: Tue, 14 Apr 2015 08:51:48 +0200 Subject: [PATCH 2/8] Changed lineendings back to LF --- TechTalk.JiraRestClient/FieldAttribute.cs | 26 ++-- TechTalk.JiraRestClient/JiraClient.cs | 62 ++++---- .../TechTalk.JiraRestClient.csproj | 144 +++++++++--------- TechTalk.JiraRestClient/packages.config | 6 +- 4 files changed, 119 insertions(+), 119 deletions(-) diff --git a/TechTalk.JiraRestClient/FieldAttribute.cs b/TechTalk.JiraRestClient/FieldAttribute.cs index e778471..a504363 100644 --- a/TechTalk.JiraRestClient/FieldAttribute.cs +++ b/TechTalk.JiraRestClient/FieldAttribute.cs @@ -1,14 +1,14 @@ -namespace TechTalk.JiraRestClient -{ - using System; - - public class FieldAttribute : Attribute - { - public string FieldName { get; set; } - - public FieldAttribute(string fieldName) - { - this.FieldName = fieldName; - } - } +namespace TechTalk.JiraRestClient +{ + using System; + + public class FieldAttribute : Attribute + { + public string FieldName { get; set; } + + public FieldAttribute(string fieldName) + { + this.FieldName = fieldName; + } + } } \ No newline at end of file diff --git a/TechTalk.JiraRestClient/JiraClient.cs b/TechTalk.JiraRestClient/JiraClient.cs index 5128cf7..c0cbf36 100644 --- a/TechTalk.JiraRestClient/JiraClient.cs +++ b/TechTalk.JiraRestClient/JiraClient.cs @@ -9,12 +9,12 @@ using RestSharp.Deserializers; namespace TechTalk.JiraRestClient -{ - using System.Diagnostics.Eventing.Reader; - using System.Reflection; - - using RestSharp.Extensions; - +{ + using System.Diagnostics.Eventing.Reader; + using System.Reflection; + + using RestSharp.Extensions; + //JIRA REST API documentation: https://docs.atlassian.com/jira/REST/latest public class JiraClient : IJiraClient where TIssueFields : IssueFields, new() @@ -168,20 +168,20 @@ public Issue CreateIssue(String projectKey, String issueType, TIss if (issueFields.timetracking != null) issueData.Add("timetracking", new { originalEstimate = issueFields.timetracking.originalEstimate }); - var propertyInfos = typeof(TIssueFields).GetProperties().ToArray(); - var propertiesFromAttribute = propertyInfos.Select(p => new { Property = p, FieldAttribute = p.GetAttribute() }) - .Where(a => a.FieldAttribute != null) - .Select(p => new NamedProperty(p.Property, p.FieldAttribute.FieldName)); - - var customFields = propertyInfos.Where(p => p.Name.StartsWith("customfield_")).Select(p => new NamedProperty(p, p.Name)); + var propertyInfos = typeof(TIssueFields).GetProperties().ToArray(); + var propertiesFromAttribute = propertyInfos.Select(p => new { Property = p, FieldAttribute = p.GetAttribute() }) + .Where(a => a.FieldAttribute != null) + .Select(p => new NamedProperty(p.Property, p.FieldAttribute.FieldName)); + + var customFields = propertyInfos.Where(p => p.Name.StartsWith("customfield_")).Select(p => new NamedProperty(p, p.Name)); var propertyList = customFields.Concat(propertiesFromAttribute); foreach (var namedProperty in propertyList) { - var value = namedProperty.Property.GetValue(issueFields, null); - if (value != null) - { - issueData.Add(namedProperty.FieldName, value); + var value = namedProperty.Property.GetValue(issueFields, null); + if (value != null) + { + issueData.Add(namedProperty.FieldName, value); } } @@ -638,19 +638,19 @@ public ServerInfo GetServerInfo() Trace.TraceError("GetServerInfo() error: {0}", ex); throw new JiraClientException("Could not retrieve server information", ex); } - } - } - - public class NamedProperty - { - public PropertyInfo Property { get; set; } - - public string FieldName { get; set; } - - public NamedProperty(PropertyInfo property, string fieldName) - { - this.Property = property; - this.FieldName = fieldName; - } - } + } + } + + public class NamedProperty + { + public PropertyInfo Property { get; set; } + + public string FieldName { get; set; } + + public NamedProperty(PropertyInfo property, string fieldName) + { + this.Property = property; + this.FieldName = fieldName; + } + } } diff --git a/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj b/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj index 94c3338..b840dbc 100644 --- a/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj +++ b/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj @@ -1,79 +1,79 @@ - - - - Debug - x86 - 8.0.30703 - 2.0 - {210529FA-454E-4C32-A2C8-353ECBD4DA05} - Library - Properties - TechTalk.JiraRestClient - TechTalk.JiraRestClient - v4.0 - Client - 512 - ..\ - true - - - - - - AnyCPU - bin\Debug\ - DEBUG;TRACE - - - AnyCPU - bin\Release\ - TRACE - - - - ..\packages\RestSharp.104.1\lib\net4-client\RestSharp.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - - + + + + Debug + x86 + 8.0.30703 + 2.0 + {210529FA-454E-4C32-A2C8-353ECBD4DA05} + Library + Properties + TechTalk.JiraRestClient + TechTalk.JiraRestClient + v4.0 + Client + 512 + ..\ + true + + + + + + AnyCPU + bin\Debug\ + DEBUG;TRACE + + + AnyCPU + bin\Release\ + TRACE + + + + ..\packages\RestSharp.104.1\lib\net4-client\RestSharp.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Designer + + + + + --> \ No newline at end of file diff --git a/TechTalk.JiraRestClient/packages.config b/TechTalk.JiraRestClient/packages.config index 0ff7e92..93631e3 100644 --- a/TechTalk.JiraRestClient/packages.config +++ b/TechTalk.JiraRestClient/packages.config @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file From 7cf009ab79a3315e617dee8c9148c3c261e89e75 Mon Sep 17 00:00:00 2001 From: schoetbi Date: Tue, 14 Apr 2015 08:53:21 +0200 Subject: [PATCH 3/8] Extracted class NamedProperty packages.config: Restsharp is now 104.1 --- TechTalk.JiraRestClient/JiraClient.cs | 23 +++---------------- TechTalk.JiraRestClient/NamedProperty.cs | 17 ++++++++++++++ .../TechTalk.JiraRestClient.csproj | 1 + TechTalk.JiraRestClient/packages.config | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) create mode 100644 TechTalk.JiraRestClient/NamedProperty.cs diff --git a/TechTalk.JiraRestClient/JiraClient.cs b/TechTalk.JiraRestClient/JiraClient.cs index c0cbf36..26e6a23 100644 --- a/TechTalk.JiraRestClient/JiraClient.cs +++ b/TechTalk.JiraRestClient/JiraClient.cs @@ -5,18 +5,14 @@ using System.Linq; using System.Net; using System.Text; + using RestSharp; using RestSharp.Deserializers; +using RestSharp.Extensions; namespace TechTalk.JiraRestClient { - using System.Diagnostics.Eventing.Reader; - using System.Reflection; - - using RestSharp.Extensions; - - //JIRA REST API documentation: https://docs.atlassian.com/jira/REST/latest - + // JIRA REST API documentation: https://docs.atlassian.com/jira/REST/latest public class JiraClient : IJiraClient where TIssueFields : IssueFields, new() { private readonly string username; @@ -640,17 +636,4 @@ public ServerInfo GetServerInfo() } } } - - public class NamedProperty - { - public PropertyInfo Property { get; set; } - - public string FieldName { get; set; } - - public NamedProperty(PropertyInfo property, string fieldName) - { - this.Property = property; - this.FieldName = fieldName; - } - } } diff --git a/TechTalk.JiraRestClient/NamedProperty.cs b/TechTalk.JiraRestClient/NamedProperty.cs new file mode 100644 index 0000000..dd65cdd --- /dev/null +++ b/TechTalk.JiraRestClient/NamedProperty.cs @@ -0,0 +1,17 @@ +namespace TechTalk.JiraRestClient +{ + using System.Reflection; + + internal class NamedProperty + { + public PropertyInfo Property { get; set; } + + public string FieldName { get; set; } + + public NamedProperty(PropertyInfo property, string fieldName) + { + this.Property = property; + this.FieldName = fieldName; + } + } +} \ No newline at end of file diff --git a/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj b/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj index b840dbc..783958c 100644 --- a/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj +++ b/TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj @@ -43,6 +43,7 @@ + diff --git a/TechTalk.JiraRestClient/packages.config b/TechTalk.JiraRestClient/packages.config index 93631e3..a64d06c 100644 --- a/TechTalk.JiraRestClient/packages.config +++ b/TechTalk.JiraRestClient/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file From 123e97816c746cc564d280c1eb87ad85078fddd6 Mon Sep 17 00:00:00 2001 From: schoetbi Date: Tue, 14 Apr 2015 08:42:17 +0200 Subject: [PATCH 4/8] FieldAttribute: Moved usings to start of file, Added LF at end of file JiraClient: - Avoided long lines - Removed .ToArray() after GetProperties() - Placed one line if out of block --- TechTalk.JiraRestClient/FieldAttribute.cs | 6 +++--- TechTalk.JiraRestClient/JiraClient.cs | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/TechTalk.JiraRestClient/FieldAttribute.cs b/TechTalk.JiraRestClient/FieldAttribute.cs index a504363..1935f1c 100644 --- a/TechTalk.JiraRestClient/FieldAttribute.cs +++ b/TechTalk.JiraRestClient/FieldAttribute.cs @@ -1,7 +1,7 @@ +using System; + namespace TechTalk.JiraRestClient { - using System; - public class FieldAttribute : Attribute { public string FieldName { get; set; } @@ -11,4 +11,4 @@ public FieldAttribute(string fieldName) this.FieldName = fieldName; } } -} \ No newline at end of file +} diff --git a/TechTalk.JiraRestClient/JiraClient.cs b/TechTalk.JiraRestClient/JiraClient.cs index 26e6a23..ce4defe 100644 --- a/TechTalk.JiraRestClient/JiraClient.cs +++ b/TechTalk.JiraRestClient/JiraClient.cs @@ -164,21 +164,22 @@ public Issue CreateIssue(String projectKey, String issueType, TIss if (issueFields.timetracking != null) issueData.Add("timetracking", new { originalEstimate = issueFields.timetracking.originalEstimate }); - var propertyInfos = typeof(TIssueFields).GetProperties().ToArray(); - var propertiesFromAttribute = propertyInfos.Select(p => new { Property = p, FieldAttribute = p.GetAttribute() }) + var propertyInfos = typeof(TIssueFields).GetProperties(); + var propertiesFromAttribute = propertyInfos + .Select(p => new { Property = p, FieldAttribute = p.GetAttribute() }) .Where(a => a.FieldAttribute != null) .Select(p => new NamedProperty(p.Property, p.FieldAttribute.FieldName)); - var customFields = propertyInfos.Where(p => p.Name.StartsWith("customfield_")).Select(p => new NamedProperty(p, p.Name)); + var customFields = propertyInfos + .Where(p => p.Name.StartsWith("customfield_")) + .Select(p => new NamedProperty(p, p.Name)); + var propertyList = customFields.Concat(propertiesFromAttribute); foreach (var namedProperty in propertyList) { var value = namedProperty.Property.GetValue(issueFields, null); - if (value != null) - { - issueData.Add(namedProperty.FieldName, value); - } + if (value != null) issueData.Add(namedProperty.FieldName, value); } request.AddBody(new { fields = issueData }); From 292f6009e20dbb1d9899ae00eadecb4d7fdc408a Mon Sep 17 00:00:00 2001 From: schoetbi Date: Tue, 14 Apr 2015 08:56:30 +0200 Subject: [PATCH 5/8] JiraClient: Reduced changes to master --- TechTalk.JiraRestClient/JiraClient.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TechTalk.JiraRestClient/JiraClient.cs b/TechTalk.JiraRestClient/JiraClient.cs index ce4defe..a0634fe 100644 --- a/TechTalk.JiraRestClient/JiraClient.cs +++ b/TechTalk.JiraRestClient/JiraClient.cs @@ -5,14 +5,14 @@ using System.Linq; using System.Net; using System.Text; - using RestSharp; using RestSharp.Deserializers; using RestSharp.Extensions; namespace TechTalk.JiraRestClient { - // JIRA REST API documentation: https://docs.atlassian.com/jira/REST/latest + //JIRA REST API documentation: https://docs.atlassian.com/jira/REST/latest + public class JiraClient : IJiraClient where TIssueFields : IssueFields, new() { private readonly string username; @@ -148,7 +148,7 @@ public Issue CreateIssue(String projectKey, String issueType, TIss { try { - var request = this.CreateRequest(Method.POST, "issue"); + var request = CreateRequest(Method.POST, "issue"); request.AddHeader("ContentType", "application/json"); var issueData = new Dictionary(); From 17fe15dc19d53c259a2840a4e93f85bee4f52d6d Mon Sep 17 00:00:00 2001 From: schoetbi Date: Fri, 10 Nov 2017 07:24:06 +0100 Subject: [PATCH 6/8] JiraClient: Add method to query issues from more than one project --- TechTalk.JiraRestClient/IJiraClient.cs | 5 +- TechTalk.JiraRestClient/JiraClient.cs | 87 +++++++++++++++++++------- 2 files changed, 68 insertions(+), 24 deletions(-) diff --git a/TechTalk.JiraRestClient/IJiraClient.cs b/TechTalk.JiraRestClient/IJiraClient.cs index a023181..0dc895d 100644 --- a/TechTalk.JiraRestClient/IJiraClient.cs +++ b/TechTalk.JiraRestClient/IJiraClient.cs @@ -9,8 +9,11 @@ namespace TechTalk.JiraRestClient /// Returns all issues for the given project IEnumerable> GetIssues(String projectKey); /// Returns all issues of the specified type for the given project - IEnumerable> GetIssues(String projectKey, String issueType); + IEnumerable> GetIssues(String projectKey, String issueType); /// Returns all issues of the given type and the given project filtered by the given JQL query + + IEnumerable> GetIssuesByQuery(string[] projects, string issueType, string jqlQuery); + IEnumerable> GetIssuesByQuery(String projectKey, String issueType, String jqlQuery); /// Enumerates through all issues for the given project IEnumerable> EnumerateIssues(String projectKey); diff --git a/TechTalk.JiraRestClient/JiraClient.cs b/TechTalk.JiraRestClient/JiraClient.cs index a0634fe..c5f01ed 100644 --- a/TechTalk.JiraRestClient/JiraClient.cs +++ b/TechTalk.JiraRestClient/JiraClient.cs @@ -8,6 +8,7 @@ using RestSharp; using RestSharp.Deserializers; using RestSharp.Extensions; +using static System.String; namespace TechTalk.JiraRestClient { @@ -31,7 +32,7 @@ public JiraClient(string baseUrl, string username, string password) private RestRequest CreateRequest(Method method, String path) { var request = new RestRequest { Method = method, Resource = path, RequestFormat = DataFormat.Json }; - request.AddHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(String.Format("{0}:{1}", username, password)))); + request.AddHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(Format("{0}:{1}", username, password)))); return request; } @@ -65,6 +66,46 @@ public IEnumerable> GetIssuesByQuery(string projectKey, stri return EnumerateIssuesInternal(projectKey, issueType, jqlQuery); } + public IEnumerable> GetIssuesByQuery(string[] projectes, string issueType, string jqlQuery) + { + return EnumerateIssuesInternal(projectes, issueType, jqlQuery); + } + + private IEnumerable> EnumerateIssuesInternal(string[] projectes, string issueType, string jqlQuery) + { + { + var queryCount = 50; + var resultCount = 0; + while (true) + { + var projectsClause = string.Join("%2C+", projectes.Select(p => $"%22{Uri.EscapeUriString(p)}%22")); + var jql = $"project+in+({projectsClause})"; + if (!IsNullOrEmpty(issueType)) + jql += $"+AND+issueType={Uri.EscapeUriString(issueType)}"; + if (!IsNullOrEmpty(jqlQuery)) + jql += $"+AND+{Uri.EscapeUriString(jqlQuery)}"; + var path = $"search?jql={jql}&startAt={resultCount}&maxResults={queryCount}"; + var request = CreateRequest(Method.GET, path); + + var response = ExecuteRequest(request); + AssertStatus(response, HttpStatusCode.OK); + + var data = deserializer.Deserialize>(response); + var issues = data.issues?.ToArray() ?? Enumerable.Empty>().ToArray(); + + foreach (var item in issues) + { + yield return item; + } + + resultCount += issues.Length; + + if (resultCount < data.total) continue; + else /* all issues received */ break; + } + } + } + public IEnumerable> EnumerateIssues(String projectKey) { return EnumerateIssues(projectKey, null); @@ -89,12 +130,12 @@ private IEnumerable> EnumerateIssuesInternal(String projectK var resultCount = 0; while (true) { - var jql = String.Format("project={0}", Uri.EscapeUriString(projectKey)); - if (!String.IsNullOrEmpty(issueType)) - jql += String.Format("+AND+issueType={0}", Uri.EscapeUriString(issueType)); - if (!String.IsNullOrEmpty(jqlQuery)) - jql += String.Format("+AND+{0}", Uri.EscapeUriString(jqlQuery)); - var path = String.Format("search?jql={0}&startAt={1}&maxResults={2}", jql, resultCount, queryCount); + var jql = Format("project={0}", Uri.EscapeUriString(projectKey)); + if (!IsNullOrEmpty(issueType)) + jql += Format("+AND+issueType={0}", Uri.EscapeUriString(issueType)); + if (!IsNullOrEmpty(jqlQuery)) + jql += Format("+AND+{0}", Uri.EscapeUriString(jqlQuery)); + var path = Format("search?jql={0}&startAt={1}&maxResults={2}", jql, resultCount, queryCount); var request = CreateRequest(Method.GET, path); var response = ExecuteRequest(request); @@ -120,7 +161,7 @@ public Issue LoadIssue(String issueRef) { try { - var path = String.Format("issue/{0}", issueRef); + var path = Format("issue/{0}", issueRef); var request = CreateRequest(Method.GET, path); var response = ExecuteRequest(request); @@ -201,7 +242,7 @@ public Issue UpdateIssue(Issue issue) { try { - var path = String.Format("issue/{0}", issue.JiraIdentifier); + var path = Format("issue/{0}", issue.JiraIdentifier); var request = CreateRequest(Method.PUT, path); request.AddHeader("ContentType", "application/json"); @@ -240,7 +281,7 @@ public void DeleteIssue(IssueRef issue) { try { - var path = String.Format("issue/{0}?deleteSubtasks=true", issue.id); + var path = Format("issue/{0}?deleteSubtasks=true", issue.id); var request = CreateRequest(Method.DELETE, path); var response = ExecuteRequest(request); @@ -258,7 +299,7 @@ public IEnumerable GetTransitions(IssueRef issue) { try { - var path = String.Format("issue/{0}/transitions?expand=transitions.fields", issue.id); + var path = Format("issue/{0}/transitions?expand=transitions.fields", issue.id); var request = CreateRequest(Method.GET, path); var response = ExecuteRequest(request); @@ -278,7 +319,7 @@ public Issue TransitionIssue(IssueRef issue, Transition transition { try { - var path = String.Format("issue/{0}/transitions", issue.id); + var path = Format("issue/{0}/transitions", issue.id); var request = CreateRequest(Method.POST, path); request.AddHeader("ContentType", "application/json"); @@ -306,7 +347,7 @@ public IEnumerable GetWatchers(IssueRef issue) { try { - var path = String.Format("issue/{0}/watchers", issue.id); + var path = Format("issue/{0}/watchers", issue.id); var request = CreateRequest(Method.GET, path); var response = ExecuteRequest(request); @@ -326,7 +367,7 @@ public IEnumerable GetComments(IssueRef issue) { try { - var path = String.Format("issue/{0}/comment", issue.id); + var path = Format("issue/{0}/comment", issue.id); var request = CreateRequest(Method.GET, path); var response = ExecuteRequest(request); @@ -346,7 +387,7 @@ public Comment CreateComment(IssueRef issue, String comment) { try { - var path = String.Format("issue/{0}/comment", issue.id); + var path = Format("issue/{0}/comment", issue.id); var request = CreateRequest(Method.POST, path); request.AddHeader("ContentType", "application/json"); request.AddBody(new Comment { body = comment }); @@ -367,7 +408,7 @@ public void DeleteComment(IssueRef issue, Comment comment) { try { - var path = String.Format("issue/{0}/comment/{1}", issue.id, comment.id); + var path = Format("issue/{0}/comment/{1}", issue.id, comment.id); var request = CreateRequest(Method.DELETE, path); var response = ExecuteRequest(request); @@ -390,7 +431,7 @@ public Attachment CreateAttachment(IssueRef issue, Stream fileStream, String fil { try { - var path = String.Format("issue/{0}/attachments", issue.id); + var path = Format("issue/{0}/attachments", issue.id); var request = CreateRequest(Method.POST, path); request.AddHeader("X-Atlassian-Token", "nocheck"); request.AddHeader("ContentType", "multipart/form-data"); @@ -412,7 +453,7 @@ public void DeleteAttachment(Attachment attachment) { try { - var path = String.Format("attachment/{0}", attachment.id); + var path = Format("attachment/{0}", attachment.id); var request = CreateRequest(Method.DELETE, path); var response = ExecuteRequest(request); @@ -482,7 +523,7 @@ public void DeleteIssueLink(IssueLink link) { try { - var path = String.Format("issueLink/{0}", link.id); + var path = Format("issueLink/{0}", link.id); var request = CreateRequest(Method.DELETE, path); var response = ExecuteRequest(request); @@ -500,7 +541,7 @@ public IEnumerable GetRemoteLinks(IssueRef issue) { try { - var path = string.Format("issue/{0}/remotelink", issue.id); + var path = Format("issue/{0}/remotelink", issue.id); var request = CreateRequest(Method.GET, path); request.AddHeader("ContentType", "application/json"); @@ -521,7 +562,7 @@ public RemoteLink CreateRemoteLink(IssueRef issue, RemoteLink remoteLink) { try { - var path = string.Format("issue/{0}/remotelink", issue.id); + var path = Format("issue/{0}/remotelink", issue.id); var request = CreateRequest(Method.POST, path); request.AddHeader("ContentType", "application/json"); request.AddBody(new @@ -557,7 +598,7 @@ public RemoteLink UpdateRemoteLink(IssueRef issue, RemoteLink remoteLink) { try { - var path = string.Format("issue/{0}/remotelink/{1}", issue.id, remoteLink.id); + var path = Format("issue/{0}/remotelink/{1}", issue.id, remoteLink.id); var request = CreateRequest(Method.PUT, path); request.AddHeader("ContentType", "application/json"); @@ -583,7 +624,7 @@ public void DeleteRemoteLink(IssueRef issue, RemoteLink remoteLink) { try { - var path = string.Format("issue/{0}/remotelink/{1}", issue.id, remoteLink.id); + var path = Format("issue/{0}/remotelink/{1}", issue.id, remoteLink.id); var request = CreateRequest(Method.DELETE, path); request.AddHeader("ContentType", "application/json"); From 29be4da89ee365281e9eba872c6acbeae4244cdd Mon Sep 17 00:00:00 2001 From: schoetbi Date: Fri, 10 Nov 2017 07:28:35 +0100 Subject: [PATCH 7/8] Added project file --- .../TechTalk.JiraRestClient_NoNuget.csproj | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 TechTalk.JiraRestClient/TechTalk.JiraRestClient_NoNuget.csproj diff --git a/TechTalk.JiraRestClient/TechTalk.JiraRestClient_NoNuget.csproj b/TechTalk.JiraRestClient/TechTalk.JiraRestClient_NoNuget.csproj new file mode 100644 index 0000000..3c90391 --- /dev/null +++ b/TechTalk.JiraRestClient/TechTalk.JiraRestClient_NoNuget.csproj @@ -0,0 +1,72 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {210529FA-454E-4C32-A2C8-353ECBD4DA05} + Library + Properties + TechTalk.JiraRestClient + TechTalk.JiraRestClient + v4.0 + Client + 512 + ..\ + true + + + + + + AnyCPU + bin\Debug\ + DEBUG;TRACE + + + AnyCPU + bin\Release\ + TRACE + + + + ..\..\packages\RestSharp.104.1\lib\net4-client\RestSharp.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Designer + + + + \ No newline at end of file From f6369d7e7700ed7adf70f17702bcf6929f06e92d Mon Sep 17 00:00:00 2001 From: schoetbi Date: Wed, 5 Jun 2019 16:12:10 +0200 Subject: [PATCH 8/8] Added basic authentication --- TechTalk.JiraRestClient/JiraClient.cs | 6 ++++-- .../TechTalk.JiraRestClient_NoNuget.csproj | 9 ++++++--- TechTalk.JiraRestClient/packages.config | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/TechTalk.JiraRestClient/JiraClient.cs b/TechTalk.JiraRestClient/JiraClient.cs index c5f01ed..f3de56a 100644 --- a/TechTalk.JiraRestClient/JiraClient.cs +++ b/TechTalk.JiraRestClient/JiraClient.cs @@ -31,8 +31,10 @@ public JiraClient(string baseUrl, string username, string password) private RestRequest CreateRequest(Method method, String path) { - var request = new RestRequest { Method = method, Resource = path, RequestFormat = DataFormat.Json }; - request.AddHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(Format("{0}:{1}", username, password)))); + var request = new RestRequest { Method = method, Resource = path }; + var encodedLogin = Encoding.ASCII.GetBytes($"{username}:{password}"); + var base64String = Convert.ToBase64String(encodedLogin); + request.AddHeader("Authorization", $"Basic {base64String}"); return request; } diff --git a/TechTalk.JiraRestClient/TechTalk.JiraRestClient_NoNuget.csproj b/TechTalk.JiraRestClient/TechTalk.JiraRestClient_NoNuget.csproj index 3c90391..03d3631 100644 --- a/TechTalk.JiraRestClient/TechTalk.JiraRestClient_NoNuget.csproj +++ b/TechTalk.JiraRestClient/TechTalk.JiraRestClient_NoNuget.csproj @@ -1,5 +1,5 @@  - + Debug x86 @@ -10,8 +10,9 @@ Properties TechTalk.JiraRestClient TechTalk.JiraRestClient - v4.0 - Client + v4.6.2 + + 512 ..\ true @@ -23,11 +24,13 @@ AnyCPU bin\Debug\ DEBUG;TRACE + false AnyCPU bin\Release\ TRACE + false diff --git a/TechTalk.JiraRestClient/packages.config b/TechTalk.JiraRestClient/packages.config index a64d06c..3ef434c 100644 --- a/TechTalk.JiraRestClient/packages.config +++ b/TechTalk.JiraRestClient/packages.config @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file