Skip to content
This repository was archived by the owner on Jan 11, 2021. It is now read-only.
Merged
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
79 changes: 69 additions & 10 deletions JiraClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,22 @@ public JiraClient(JiraAccount account)
// Won't throw exception.
var response = client.Execute<T>(request);

if (response.ResponseStatus != ResponseStatus.Completed || response.ErrorException != null)
throw new JiraApiException(string.Format("RestSharp response status: {0} - HTTP response: {1} - {2} - {3}", response.ResponseStatus, response.StatusCode, response.StatusDescription, response.Content));
validateResponse(response);

return response.Data;
}

/// <summary>
/// Throws exception with details if request was not unsucessful
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="response"></param>
private static void validateResponse(IRestResponse response)
{
if (response.ResponseStatus != ResponseStatus.Completed || response.ErrorException != null || response.StatusCode == HttpStatusCode.BadRequest)
throw new JiraApiException(string.Format("RestSharp response status: {0} - HTTP response: {1} - {2} - {3}", response.ResponseStatus, response.StatusCode, response.StatusDescription, response.Content));
}

/// <summary>
/// Returns a comma separated string from the strings in the provided
/// IEnumerable of strings. Returns an empty string if null is provided.
Expand Down Expand Up @@ -75,11 +85,11 @@ private static string ToCommaSeparatedString(IEnumerable<string> strings)
public Issue GetIssue(string issueKey, IEnumerable<string> fields = null)
{
var fieldsString = ToCommaSeparatedString(fields);

var request = new RestRequest();
request.Resource = string.Format("{0}?fields={1}", ResourceUrls.IssueByKey(issueKey), fieldsString);
request.Method = Method.GET;

var issue = Execute<Issue>(request, HttpStatusCode.OK);
return issue.fields != null ? issue : null;
}
Expand Down Expand Up @@ -148,7 +158,7 @@ public List<Project> GetProjects()
};

return Execute<List<Project>>(request, HttpStatusCode.OK);
}
}

/// <summary>
/// Returns a list of all possible priorities. Throws
Expand All @@ -174,10 +184,12 @@ public ProjectMeta GetProjectMeta(string projectKey)
{
var request = new RestRequest();
request.Resource = ResourceUrls.CreateMeta();
request.AddParameter(new Parameter()
{ Name = "projectKeys",
Value = projectKey,
Type = ParameterType.GetOrPost });
request.AddParameter(new Parameter()
{
Name = "projectKeys",
Value = projectKey,
Type = ParameterType.GetOrPost
});
request.Method = Method.GET;
var createMeta = Execute<IssueCreateMeta>(request, HttpStatusCode.OK);
if (createMeta.projects[0].key != projectKey || createMeta.projects.Count != 1)
Expand Down Expand Up @@ -231,7 +243,7 @@ public ApplicationProperty GetApplicationProperty(string propertyKey)
Resource = ResourceUrls.ApplicationProperties(),
RequestFormat = DataFormat.Json
};

request.AddParameter(new Parameter()
{
Name = "key",
Expand Down Expand Up @@ -274,6 +286,53 @@ public void DeleteAttachment(string attachmentId)
var response = client.Execute(request);
if (response.ResponseStatus != ResponseStatus.Completed || response.StatusCode != HttpStatusCode.NoContent)
throw new JiraApiException("Failed to delete attachment with id=" + attachmentId);
}

/// <summary>
/// Update time tracking estimates
/// </summary>
/// <param name="issuekey"></param>
/// <param name="orginialEstimateMinutes"></param>
/// <param name="remainingEstimateMinutes"></param>
/// <returns></returns>
public bool UpdateTimetracking(string issuekey, int orginialEstimateMinutes, int remainingEstimateMinutes)
{
var request = new RestRequest()
{
Resource = string.Format("{0}", ResourceUrls.IssueByKey(issuekey)),
Method = Method.PUT,
RequestFormat = DataFormat.Json,
};

// Alternative for "simple" fields
//request.AddBody(
// new { fields = new { summary = issue.fields.summary } }
//);

request.AddBody(
new
{
update = new
{
timetracking = new object[] {new
{
edit = new
{
// No entry in seconds possible apparently
originalEstimate = string.Format("{0}m", orginialEstimateMinutes),
remainingEstimate= string.Format("{0}m", remainingEstimateMinutes)
}
}}
}
}
);

// No response expected
var response = client.Execute(request);

validateResponse(response);

return response.StatusCode == HttpStatusCode.NoContent;
}
}
}
24 changes: 21 additions & 3 deletions JiraModel/Issue.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AnotherJiraRestClient.JiraModel;
using System;
using AnotherJiraRestClient.JiraModel;
using System.Collections.Generic;

namespace AnotherJiraRestClient
Expand Down Expand Up @@ -59,15 +60,15 @@ public class BasicIssue
public string key { get; set; }
}

public class Fields
public partial class Fields
{
public Progress progress { get; set; }
public string summary { get; set; }
public Timetracking timetracking { get; set; }
public IssueType issuetype { get; set; }
public Votes votes { get; set; }
public Resolution resolution { get; set; }
public List<object> fixVersions { get; set; }
public List<fixversion> fixVersions { get; set; }
public string resolutiondate { get; set; }
public int timespent { get; set; }
public Author reporter { get; set; }
Expand Down Expand Up @@ -98,6 +99,23 @@ public class Fields
public int aggregatetimespent { get; set; }
}

public class fixversion
{
public string self { get; set; }
public string id { get; set; }
public string name { get; set; }
public string archived { get; set; }
public string released { get; set; }
public DateTime releaseDate { get; set; }
}

public class customfield
{
public string self { get; set; }
public string value { get; set; }
public string id { get; set; }
}

public class Subtask
{
public string id { get; set; }
Expand Down