Skip to content

Instantly share code, notes, and snippets.

@YoannArasLab
Last active May 8, 2017 15:03
Show Gist options
  • Save YoannArasLab/e1779f9c35d566d4696c40e57f8e4c65 to your computer and use it in GitHub Desktop.
Save YoannArasLab/e1779f9c35d566d4696c40e57f8e4c65 to your computer and use it in GitHub Desktop.
// to be set on after get
// setup (should be moved to variables)
string username= "user";
string password="mypassword1234";
// build search string
string ids="(";
for (int i=0;i<this.getItemCount();i++){
if (i!=0){
ids=ids+",";
}
ids=ids+this.getItemByIndex(i).getProperty("jiraid","");
}
ids=ids+")";
// prepare the REST Call
string html = string.Empty;
string encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username+":"+password));
// execute the REST Call
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://myJiraServer.com/jira/rest/api/2/search?jql=project=MYPROJECT&id+in+"+ids);
request.Headers.Add("Authorization","Basic "+encoded);
JObject Result;
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using(Stream stream = response.GetResponseStream())
// parse the result
using(StreamReader reader= new StreamReader(stream))
{
html = reader.ReadToEnd();
Result = JObject.Parse(html);
}
IList<JToken> issueResults = Result["issues"].Children().ToList();
// merge data
foreach (JToken issue in issueResults){
for (int j =0;j<this.getItemCount();j++){
if (this.getItemByIndex(j).getProperty("jiraid","")==issue["id"].ToString()){
this.getItemByIndex(j).setProperty("jiraid",issue["id"].ToString());
this.getItemByIndex(j).setProperty("title",issue["fields"]["summary"].ToString());
this.getItemByIndex(j).setProperty("description",issue["fields"]["description"].ToString());
this.getItemByIndex(j).setProperty("jirakey",issue["key"].ToString());
this.getItemByIndex(j).setProperty("jiraurl",issue["self"].ToString());
this.getItemByIndex(j).setProperty("issuetype",issue["fields"]["issuetype"]["name"].ToString());
}
}
}
return this;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment