Skip to content

extend API: project, worklog/updated, worklog/list #36

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

Open
wants to merge 2 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
23 changes: 23 additions & 0 deletions TechTalk.JiraRestClient/Compatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace TechTalk.JiraRestClient
{
public interface IJiraClient
{
/// <summary>Returns a list of projects</summary>
IEnumerable<Project> GetProjects();

/// <summary>Returns all issues for the given project</summary>
IEnumerable<Issue> GetIssues(String projectKey);
/// <summary>Returns all issues of the specified type for the given project</summary>
Expand Down Expand Up @@ -76,6 +79,11 @@ public interface IJiraClient
/// <summary>Removes the given remote link (attached url) of the specified issue</summary>
void DeleteRemoteLink(IssueRef issue, RemoteLink remoteLink);

/// <summary>Returns worklogs id and update time of worklogs that was updated since given time.</summary>
WorklogUpdated GetWorklogUpdated(DateTime since);
/// <summary>Returns worklogs for given worklog ids</summary>
IEnumerable<Worklog> GetWorklogList(int[] ids);

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

Expand All @@ -91,6 +99,11 @@ public JiraClient(string baseUrl, string username, string password)
client = new JiraClient<IssueFields>(baseUrl, username, password);
}

public IEnumerable<Project> GetProjects()
{
return client.GetProjects();
}

public IEnumerable<Issue> GetIssues(String projectKey)
{
return client.GetIssues(projectKey).Select(Issue.From).ToArray();
Expand Down Expand Up @@ -238,6 +251,16 @@ public void DeleteRemoteLink(IssueRef issue, RemoteLink remoteLink)
client.DeleteRemoteLink(issue, remoteLink);
}

public WorklogUpdated GetWorklogUpdated(DateTime since)
{
return client.GetWorklogUpdated(since);
}

public IEnumerable<Worklog> GetWorklogList(int[] ids)
{
return client.GetWorklogList(ids);
}

public IEnumerable<IssueType> GetIssueTypes()
{
return client.GetIssueTypes();
Expand Down
8 changes: 8 additions & 0 deletions TechTalk.JiraRestClient/IJiraClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace TechTalk.JiraRestClient
{
public interface IJiraClient<TIssueFields> where TIssueFields : IssueFields, new()
{
/// <summary>Returns a list of projects</summary>
IEnumerable<Project> GetProjects();

/// <summary>Returns all issues for the given project</summary>
IEnumerable<Issue<TIssueFields>> GetIssues(String projectKey);
/// <summary>Returns all issues of the specified type for the given project</summary>
Expand Down Expand Up @@ -80,6 +83,11 @@ namespace TechTalk.JiraRestClient
/// <summary>Removes the given remote link (attached url) of the specified issue</summary>
void DeleteRemoteLink(IssueRef issue, RemoteLink remoteLink);

/// <summary>Returns worklogs id and update time of worklogs that was updated since given time</summary>
WorklogUpdated GetWorklogUpdated(DateTime since);
/// <summary>Returns worklogs for given worklog ids</summary>
IEnumerable<Worklog> GetWorklogList(int[] ids);

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

Expand Down
6 changes: 6 additions & 0 deletions TechTalk.JiraRestClient/IssueFields.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.Remoting.Messaging;

namespace TechTalk.JiraRestClient
{
Expand All @@ -10,6 +11,9 @@ public IssueFields()
status = new Status();
timetracking = new Timetracking();

project = new Project();
issuetype = new IssueType();

labels = new List<String>();
comments = new List<Comment>();
issuelinks = new List<IssueLink>();
Expand All @@ -19,6 +23,8 @@ public IssueFields()

public String summary { get; set; }
public String description { get; set; }
public Project project { get; set; }
public IssueType issuetype { get; set; }
public Timetracking timetracking { get; set; }
public Status status { get; set; }

Expand Down
64 changes: 64 additions & 0 deletions TechTalk.JiraRestClient/JiraClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using RestSharp;
using RestSharp.Deserializers;
using TechTalk.JiraRestClient.Utils;

namespace TechTalk.JiraRestClient
{
Expand Down Expand Up @@ -49,6 +50,26 @@ private void AssertStatus(IRestResponse response, HttpStatusCode status)
}


public IEnumerable<Project> GetProjects()
{
try
{
var request = CreateRequest(Method.GET, "project");
request.AddHeader("ContentType", "application/json");

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

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

public IEnumerable<Issue<TIssueFields>> GetIssues(String projectKey)
{
return EnumerateIssues(projectKey, null).ToArray();
Expand Down Expand Up @@ -616,6 +637,49 @@ public void DeleteRemoteLink(IssueRef issue, RemoteLink remoteLink)
}
}

public WorklogUpdated GetWorklogUpdated(DateTime since)
{
try
{
var unixSince = TimeUtils.ToUnixTime(since);
var path = string.Format("worklog/updated?since={0}", unixSince);
var request = CreateRequest(Method.GET, path);
request.AddHeader("ContentType", "application/json");

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

var data = deserializer.Deserialize<WorklogUpdated>(response);
return data;
}
catch (Exception ex)
{
Trace.TraceError("GetWorklogUpdated() error: {0}", ex);
throw new JiraClientException("Could not load worklog updated", ex);
}
}

public IEnumerable<Worklog> 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<List<Worklog>>(response);
return data;
}
catch (Exception ex)
{
Trace.TraceError("GetWorklogList() error: {0}", ex);
throw new JiraClientException("Could not load worklog list", ex);
}
}

public IEnumerable<IssueType> GetIssueTypes()
{
try
Expand Down
11 changes: 11 additions & 0 deletions TechTalk.JiraRestClient/Project.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace TechTalk.JiraRestClient
{
public class Project
{
public string id { get; set; }
public string key { get; set; }
public string name { get; set; }
}
}
4 changes: 4 additions & 0 deletions TechTalk.JiraRestClient/TechTalk.JiraRestClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@
<Link>QueryableIssueCollection.cs</Link>
</Compile>
<Compile Include="Attachment.cs" />
<Compile Include="Project.cs" />
<Compile Include="Comment.cs" />
<Compile Include="CommentsContainer.cs" />
<Compile Include="Compatibility.cs" />
<Compile Include="Utils\TimeUtils.cs" />
<Compile Include="Worklog.cs" />
<Compile Include="WorklogUpdated.cs" />
<Compile Include="IssueType.cs" />
<Compile Include="ServerInfo.cs" />
<Compile Include="WatchersContainer.cs" />
Expand Down
22 changes: 22 additions & 0 deletions TechTalk.JiraRestClient/Utils/TimeUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TechTalk.JiraRestClient.Utils
{
public static class TimeUtils
{
public static readonly DateTime unixStart = new DateTime(1970, 1, 1, 0, 0, 0);

public static DateTime FromUnixTime(long unixTime)
{
return unixStart.AddMilliseconds(unixTime);
}

public static long ToUnixTime(DateTime time)
{
return (long)(time - unixStart).TotalMilliseconds;
}
}
}
19 changes: 19 additions & 0 deletions TechTalk.JiraRestClient/Worklog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;

namespace TechTalk.JiraRestClient
{
public class Worklog
{
public JiraUser author { get; set; }
public JiraUser updateAuthor { get; set; }
public string comment { get; set; }
public DateTime created { get; set; }
public DateTime updated { get; set; }
public DateTime started { get; set; }
public string timeSpent { get; set; }
public int timeSpentSeconds { get; set; }
public string id { get; set; }
public string issueId { get; set; }
}
}
44 changes: 44 additions & 0 deletions TechTalk.JiraRestClient/WorklogUpdated.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using TechTalk.JiraRestClient.Utils;

namespace TechTalk.JiraRestClient
{
public class WorklogUpdated
{
public List<WorklogUpdatedValue> values { get; set; }
public long since { get; set; }
public long until { get; set; }
public bool lastPage { get; set; }

public DateTime Since
{
get
{
return TimeUtils.FromUnixTime(since);
}
}

public DateTime Until
{
get
{
return TimeUtils.FromUnixTime(until);
}
}
}

public class WorklogUpdatedValue
{
public int worklogId { get; set; }
public long updatedTime { get; set; }

public DateTime UpdatedTime
{
get
{
return TimeUtils.FromUnixTime(updatedTime);
}
}
}
}