Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get list of all issue statuses; fix: transitions href format allow issue key, not only id #34

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TechTalk.JiraRestClient/Compatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void DeleteRemoteLink(IssueRef issue, RemoteLink remoteLink)

public IEnumerable<IssueType> GetIssueTypes()
{
return client.GetIssueTypes();
return client.GetIssueTypes<IssueType>();
}

public ServerInfo GetServerInfo()
Expand Down
14 changes: 13 additions & 1 deletion TechTalk.JiraRestClient/IJiraClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ namespace TechTalk.JiraRestClient
/// <summary>Returns all watchers for the given issue</summary>
IEnumerable<JiraUser> GetWatchers(IssueRef issue);

List<T> GetProjects<T>() where T : JiraProject;

List<T> FindUsers<T>(string search) where T : JiraUser;
T FindUser<T>(string search) where T : JiraUser;


/// <summary>Returns all comments for the given issue</summary>
IEnumerable<Comment> GetComments(IssueRef issue);
/// <summary>Adds a comment to the given issue</summary>
Expand Down Expand Up @@ -81,7 +87,13 @@ namespace TechTalk.JiraRestClient
void DeleteRemoteLink(IssueRef issue, RemoteLink remoteLink);

/// <summary>Returns all issue types</summary>
IEnumerable<IssueType> GetIssueTypes();
IEnumerable<T> GetIssueTypes<T>() where T : IssueType;

/// <summary>Returns all issue statuses</summary>
IEnumerable<T> GetIssueStatuses<T>() where T : Status;

/// <summary>Returns all issue priorities</summary>
IEnumerable<T> GetIssuePriorities<T>() where T : IssuePriority;

/// <summary>Returns information about the JIRA server</summary>
ServerInfo GetServerInfo();
Expand Down
10 changes: 10 additions & 0 deletions TechTalk.JiraRestClient/IssuePriority.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace TechTalk.JiraRestClient
{
public class IssuePriority
{
public string self { get; set; }
public string iconUrl { get; set; }
public string name { get; set; }
public int id { get; set; }
}
}
94 changes: 91 additions & 3 deletions TechTalk.JiraRestClient/JiraClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public IEnumerable<Transition> GetTransitions(IssueRef issue)
{
try
{
var path = String.Format("issue/{0}/transitions?expand=transitions.fields", issue.id);
var path = String.Format("issue/{0}/transitions?expand=transitions.fields", issue.JiraIdentifier);
var request = CreateRequest(Method.GET, path);

var response = ExecuteRequest(request);
Expand Down Expand Up @@ -340,6 +340,51 @@ public IEnumerable<JiraUser> GetWatchers(IssueRef issue)
}
}

public List<T> GetProjects<T>() where T: JiraProject
{
try
{
var path = "project";
var request = CreateRequest(Method.GET, path);

var response = ExecuteRequest(request);
AssertStatus(response, HttpStatusCode.OK);

return deserializer.Deserialize<List<T>>(response);
}
catch (Exception ex)
{
Trace.TraceError("GetProjects() error: {0}", ex);
throw new JiraClientException("Could not load projects", ex);
}

}

public List<T> FindUsers<T>(string search) where T : JiraUser
{
try
{
var path = String.Format("user/search?username={0}", search);
var request = CreateRequest(Method.GET, path);
var response = ExecuteRequest(request);
AssertStatus(response, HttpStatusCode.OK);

var result = deserializer.Deserialize<List<T>>(response);
return result;
}
catch (Exception ex)
{
Trace.TraceError("FindUsers(issue) error: {0}", ex);
throw new JiraClientException(String.Format("Could find user {0}. {1}", search, ex));
}
}

public T FindUser<T>(string search) where T : JiraUser
{
return FindUsers<T>(search).FirstOrDefault();
}



public IEnumerable<Comment> GetComments(IssueRef issue)
{
Expand Down Expand Up @@ -616,7 +661,8 @@ public void DeleteRemoteLink(IssueRef issue, RemoteLink remoteLink)
}
}

public IEnumerable<IssueType> GetIssueTypes()
//public IEnumerable<IssueType> GetIssueTypes()
public IEnumerable<T> GetIssueTypes<T>() where T : IssueType
{
try
{
Expand All @@ -626,7 +672,7 @@ public IEnumerable<IssueType> GetIssueTypes()
var response = ExecuteRequest(request);
AssertStatus(response, HttpStatusCode.OK);

var data = deserializer.Deserialize<List<IssueType>>(response);
var data = deserializer.Deserialize<List<T>>(response);
return data;

}
Expand All @@ -637,6 +683,48 @@ public IEnumerable<IssueType> GetIssueTypes()
}
}

public IEnumerable<T> GetIssueStatuses<T>() where T:Status
{
try
{
var request = CreateRequest(Method.GET, "status");
request.AddHeader("ContentType", "application/json");

var response = ExecuteRequest(request);
AssertStatus(response, HttpStatusCode.OK);

var data = deserializer.Deserialize<List<T>>(response);
return data;

}
catch (Exception ex)
{
Trace.TraceError("GetIssueStatuses() error: {0}", ex);
throw new JiraClientException("Could not load issue statuses", ex);
}
}

public IEnumerable<T> GetIssuePriorities<T>() where T : IssuePriority
{
try
{
var request = CreateRequest(Method.GET, "priority");
request.AddHeader("ContentType", "application/json");

var response = ExecuteRequest(request);
AssertStatus(response, HttpStatusCode.OK);

var data = deserializer.Deserialize<List<T>>(response);
return data;

}
catch (Exception ex)
{
Trace.TraceError("GetIssuePriorities() error: {0}", ex);
throw new JiraClientException("Could not load issue priorities", ex);
}
}

public ServerInfo GetServerInfo()
{
try
Expand Down
17 changes: 17 additions & 0 deletions TechTalk.JiraRestClient/JiraProject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TechTalk.JiraRestClient
{
public class JiraProject
{
public string self { get; set; }
public int id { get; set; }
public string key { get; set; }
public string name { get; set; }
public string projectTypeKey { get; set; }

}
}
2 changes: 2 additions & 0 deletions TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
<Compile Include="Comment.cs" />
<Compile Include="CommentsContainer.cs" />
<Compile Include="Compatibility.cs" />
<Compile Include="IssuePriority.cs" />
<Compile Include="IssueType.cs" />
<Compile Include="JiraProject.cs" />
<Compile Include="ServerInfo.cs" />
<Compile Include="WatchersContainer.cs" />
<Compile Include="IJiraClient.cs" />
Expand Down