![](/img/trans.png)
[英]Is there a way to specifically set values to an LED pin using the library?
[英]Set time values (specifically OriginalEstimate) using JIRA SDK
我一直在關注這對通過Atlassian的SDK與JIRA接口指南。
但是在使用SDK設置發布時間估算時,我遇到了麻煩。 我想出了一個解決方法,可以通過添加指定新時間的偽造工作日志來設置剩余時間估計:
jiraConn = Jira.CreateRestClient(JIRA_BASE_ADDRESS, J_USER_ID, J_PASSWORD);
Issue newIssue = jiraConn.CreateIssue("CL");
//Inadequate 'solution':
newIssue.AddWorklog("0h", WorklogStrategy.NewRemainingEstimate, "10d");
我對能夠設置OriginalEstimate值特別感興趣,但是有關設置其他時間跟蹤數據的任何建議都很好。 我還嘗試更改了issue.GetTimeTrackingData()返回的IssueTimeTrackingData對象的值-但該對象似乎已與JIRA DB斷開連接,因此對此更改不會提交。
較舊版本的JIRA SDK具有SetEstimate()類型的方法。 它們隨后被刪除,因此盡管您可以訪問時間估計值,但不能更改它們(除了RemainingTime,可以通過添加問題中所述的工作日志來更新它們)。
我建議直接訪問REST API以更新原始估算值
try
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("<Jira URL>/rest/api/2/issue/" + IssueKey);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Accept = "application/json";
httpWebRequest.Method = "PUT";
String username = ConfigurationManager.AppSettings["JiraUserName"];
String password = ConfigurationManager.AppSettings["JiraPassword"];
String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
httpWebRequest.Headers.Add("Authorization", "Basic " + encoded);
using (StreamWriter sw = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{" +
"\"fields\" : { " +
"\"timetracking\":{ \"originalEstimate\":\"12h\" }" +
"} }";
sw.Write(json);
sw.Flush();
sw.Close();
}
using (HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse())
{
httpResponse.Close();
}
}
catch (WebException ex)
{
WebResponse wbResponse = ex.Response;
HttpWebResponse response = (HttpWebResponse)wbResponse;
response.Close();
}
因此,在尋找一種通過Jira API設置原始估算時間的方法時,我無意中發現了該線程。 不幸的是,C#中的Atlassian SDK不允許更改原始的估計時間。 更糟糕的是,拋出的異常根本無法提供信息!
無論如何,這是解決方案:
var jiraConnection = Jira.CreateRestClient(BASE_URL, username, password)
var restRequest = new RestRequest("rest/api/2/issue/" + issue.JiraIdentifier);
restRequest.Method = Method.PUT;
restRequest.RequestFormat = DataFormat.Json;
var requestBody = new { update = new { timetracking = new[]{ new { edit = new { originalEstimate = work.ToString()+"h" } } } } };
restRequest.AddJsonBody(requestBody);
IRestResponse response = jiraConnection.RestClient.ExecuteRequest(restRequest);
if (response.ResponseStatus != ResponseStatus.Completed)
{
throw new System.Net.WebException("Error creating planning issue");
}
它使用第一個示例基於此解決方案 。 我首先嘗試了第二種解決方案,但是它至少對我來說沒有用,因此您必須使用更長的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.