public void getJiraTicketId(string featurpath, string bugSummary, string scenarioName, BugState bg) { Console.WriteLine("Bazooka : Entered JIRA TICKET ID"); timestamp = DateTime.Now.ToString("dd-MM-yyyy, HH:mm"); HttpClient client1 = new HttpClient(); string Apiurl = ("https://spiderlogic.jira.com/rest/api/2/search?jql=project=SFLOW&fields=issuetype&fields=summary&fields=description&fields=status"); var credentials = Encoding.ASCII.GetBytes("[email protected]:spiderqa"); client1.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(credentials)); Uri uri = new Uri(Apiurl.ToString()); string ApiResponse = client1.GetStringAsync(uri).Result; var root = JsonConvert.DeserializeObject <RootObject>(ApiResponse); var issues = root.issues; foreach (var item in issues) { summary = (item.fields.summary).ToString(); if (item.fields.issuetype.name == "Bug") { if (item.fields.summary == bugSummary & item.fields.status.name == "Closed") { Console.WriteLine("This is the most important step : In Jiraticket Closed"); closedflag = true; closedtktID = item.id; closedtktkey = item.key; bg.closedtkyKey = item.key; bg.closedflag = true; break; } else if (item.fields.summary == bugSummary & item.fields.status.name == "Open") { if (bg.bugclosed) { Console.WriteLine("Bazooka : In Jiraticket BUG CLOSED AND REOPENED"); opentktID = item.id; opentktkey = item.key; openedafterclosedflag = true; bg.reopentktkey = item.key; bg.openedafterclosedflag = true; continue; } else { Console.WriteLine("Bazooka : In Jiraticket DIRECTLY into OPen"); tktID = item.id; tktkey = item.key; bg.newopentktkey = item.key; break; } } } else { continue; } } //if closed ticket workflow when a new bug ticket is created if (closedflag && (bg.nobugcreated == false)) { Console.WriteLine("Bazooka : In Jiraticket if closedflag"); Console.WriteLine("check the nobugcreated flag: " + bg.nobugcreated); foreach (var item in issues) { if (item.fields.issuetype.name == "Bug") { if (item.fields.summary == bugSummary & item.fields.status.name == "Open") { Console.WriteLine("Bazooka : In Jiraticket if closedflag and now in open"); opentktID = item.id; opentktkey = item.key; openedafterclosedflag = true; break; } } else { continue; } } } //Get the creation/closed date of the bug FetchBugCreationResolutionDate bc = new FetchBugCreationResolutionDate(); //Writing into the Feature file if (openedafterclosedflag) { Console.WriteLine("Bazooka : In Jiraticket if openedafterclosed writing intofeature"); bg = bc.fetchBugCreatedClosedDate(bg); Text = File.ReadAllLines(featurpath).ToList(); keyToInsert = "#" + opentktkey + " Opened on: " + bg.bugcreationdate; Console.WriteLine("Text: " + Text); Console.WriteLine("keyToInsert: " + keyToInsert); bg.reopentktkey = opentktkey; trimmedText = keyToInsert.Remove(10); Console.WriteLine("trimmedText: " + trimmedText); if (Text.Contains(keyToInsert)) { Console.WriteLine("Key already exists"); } else { Console.WriteLine("Key does not exist and will write into the feature file"); int length = scenarioName.Length; int index = Text.FindIndex(x => x.Contains(scenarioName)); index = index + 1; string a = Text[index]; Console.WriteLine("a contains: " + a); Console.WriteLine("trimmedtext contains: " + trimmedText); Console.WriteLine("index +1: " + index); Text.RemoveAt(index); Text.Insert(index, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } } if (closedflag) { Console.WriteLine("Bazooka : In Jiraticket if closedflag writing intofeature"); Console.WriteLine("Upali ClosedKey: " + closedtktkey); bg = bc.fetchBugCreatedClosedDate(bg); Text = File.ReadAllLines(featurpath).ToList(); keyToInsert = "#" + closedtktkey + " Closed on: " + bg.bugcloseddate; trimmedText = keyToInsert.Remove(7); int length = scenarioName.Length; int index = Text.FindIndex(x => x.Contains(scenarioName)); Console.WriteLine("Index: " + index); index = index + 2; string a = Text[index]; Console.WriteLine("Index +2: " + index); Console.WriteLine("In JIRA KEY TICKET, under closed Flag: a contains" + a); Console.WriteLine("In JIRA KEY TICKET, under closed Flag: Trimmed Text contains :" + trimmedText); if (a.Contains(trimmedText)) { if (bg.bugclosedcount == 0) { Console.WriteLine("Do Nothing"); } //april 26 test else if (bg.bugclosedcount >= 1) { if (bg.nobugcreated) { Console.WriteLine("Inside nobugcreated"); int newindex = index - 1; string b = Text[newindex]; if (b.Contains("Opened")) { Console.WriteLine("Inside nobugcreated and if b contains Opened"); Console.WriteLine("Key to insert: " + keyToInsert); Text.Remove(b); Text.Insert(newindex, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } } else { Console.WriteLine("old closed bug :" + bg.buglist[bg.bugclosedcount - 1]); Console.WriteLine("inside if a.contains(trimmedtext) and if bugcount > 1"); string closedbug = Text[index]; if (closedbug.Contains(closedtktkey)) { Console.WriteLine("Do nothing"); } else { Text.Insert(index, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } } } else { Console.WriteLine("inside else bugcount >1"); if (a.Contains(bg.buglist[0])) { Console.WriteLine("in if a.contains closed bug"); Text.Remove(a); Text.Insert(index, keyToInsert); } else { Console.WriteLine("in else a.contains closed bug"); Text.Insert(index, keyToInsert); } System.IO.File.WriteAllLines(featurpath, Text); } } else { Console.WriteLine("inside else a.contains(trimmedtext)"); Text.Insert(index, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } } else if (bg.nobugcreated) { Console.WriteLine("When the test case passes and no bug is created,Do Nothing"); } else { Console.WriteLine("Bazooka : In Jiraticket if opened new writing intofeature"); Text = File.ReadAllLines(featurpath).ToList(); bg = bc.fetchBugCreatedClosedDate(bg); keyToInsert = "#" + tktkey + " Opened on: " + bg.bugcreationdate; Console.WriteLine("Text: " + Text); Console.WriteLine("keyToInsert: " + keyToInsert); trimmedText = keyToInsert.Remove(7); Console.WriteLine("trimmedText: " + trimmedText); if (Text.Contains(keyToInsert)) { Console.WriteLine("Key already exists"); } else { int length = scenarioName.Length; int index = Text.FindIndex(x => x.Contains(scenarioName)); index = index + 1; string a = Text[index]; if (a.Contains(trimmedText)) { Text.Remove(a); Text.Insert(index, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } else { Text.Insert(index, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } } } }
public BugState check(string featurpath, string bugsummary, string scenarioName, BugState bg) { string state = ""; string issuetype = ""; string closedtktID = null; string closedtktkey = null; bg.bugclosed = false; bg.bugexists = false; bg.bugopen = false; bool closedflag = false; List <string> Text = null; string keyToInsert = ""; string trimmedText = ""; string timestamp; timestamp = DateTime.Now.ToString("dd-MM-yyyy, HH:mm"); HttpClient client2 = new HttpClient(); string issueurl = ("https://spiderlogic.jira.com/rest/api/2/search?jql=project=SFLOW&fields=issues&fields=summary&fields=description&fields=status&fields=project&fields=issuetype"); var credentials = Encoding.ASCII.GetBytes("[email protected]:spiderqa"); client2.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(credentials)); Uri uri = new Uri(issueurl.ToString()); string ApiResponse = client2.GetStringAsync(uri).Result; var root = JsonConvert.DeserializeObject <RootObject>(ApiResponse); var Sumry = root.issues.Count; //Checking if the Bug already exists by iterating though the issue list in jira var issues = root.issues; Console.WriteLine("bg.closed: " + bg.closedflag); Console.WriteLine("closedflag : " + closedflag); Console.WriteLine("bg.open : " + bg.bugopen); foreach (var issue in issues) { var fields = issue.fields; var summary = (fields.summary).ToString(); state = (fields.status.name).ToString(); issuetype = (fields.issuetype.name).ToString(); if ((issuetype == "Bug") && summary.Equals(bugsummary) && (state == "Open")) { //control may never come to this block if (bg.bugclosed) { Console.WriteLine("Bazooka : In BugStatus BUG CLOSED AND REOPENED"); bg.openedafterclosedflag = true; bg.reopentktkey = issue.key; bg.openedafterclosedflag = true; continue; } else { Console.WriteLine("In BugStatus : Bug exists"); bg.bugexists = true; bg.newopentktkey = issue.key; Console.WriteLine("Ticket Key: " + issue.key); bg.bugopen = true; } } else if ((issuetype == "Bug") && summary.Equals(bugsummary) && (state == "Closed")) { Console.WriteLine("In BugStatus: Bug exists bug closed "); Console.WriteLine("In Bug Status:This is the most important step "); closedflag = true; bg.closedflag = true; bg.bugexists = false; closedtktID = issue.id; closedtktkey = issue.key; bg.closedtkyKey = issue.key; bg.bugclosed = true; bg.nobugcreated = true; bg.bugclosedcount = bg.bugclosedcount + 1; bg.buglist.Add(closedtktkey); } } Console.WriteLine("closedflag: " + closedflag); Console.WriteLine("bg.closedflag: " + bg.closedflag); Console.WriteLine("closedtktkey: " + closedtktkey); Console.WriteLine("bg.bugopen: " + bg.bugopen); Console.WriteLine("bg.newopentktkey: " + bg.newopentktkey); //Get the creation/closed date of the bug FetchBugCreationResolutionDate bc = new FetchBugCreationResolutionDate(); //Writing into the Feature file if (bg.openedafterclosedflag) { Console.WriteLine("Bazooka : In BugStatus if openedafterclosed writing intofeature"); bg = bc.fetchBugCreatedClosedDate(bg); Text = File.ReadAllLines(featurpath).ToList(); keyToInsert = "#" + bg.reopentktkey + " Opened on: " + bg.bugcreationdate; trimmedText = keyToInsert.Remove(10); Console.WriteLine("trimmedText: " + trimmedText); if (Text.Contains(keyToInsert)) { Console.WriteLine("Key already exists"); } else { Console.WriteLine("Key does not exist and will write into the feature file"); int length = scenarioName.Length; int index = Text.FindIndex(x => x.Contains(scenarioName)); index = index + 1; string a = Text[index]; Console.WriteLine("a contains: " + a); Console.WriteLine("trimmedtext contains: " + trimmedText); Console.WriteLine("index +1: " + index); Text.RemoveAt(index); Text.Insert(index, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } } if (bg.bugopen) { Console.WriteLine("Bazooka : In BugStatus if bug already exists writing intofeature"); Text = File.ReadAllLines(featurpath).ToList(); bg = bc.fetchBugCreatedClosedDate(bg); keyToInsert = "#" + bg.newopentktkey + " Opened on: " + bg.bugcreationdate; Console.WriteLine("Text: " + Text); Console.WriteLine("keyToInsert: " + keyToInsert); trimmedText = keyToInsert.Remove(7); Console.WriteLine("trimmedText: " + trimmedText); if (Text.Contains(keyToInsert)) { Console.WriteLine("Key already exists"); } else { int length = scenarioName.Length; int index = Text.FindIndex(x => x.Contains(scenarioName)); index = index + 1; string a = Text[index]; if (a.Contains(trimmedText)) { Text.Remove(a); Text.Insert(index, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } else { Text.Insert(index, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } } } if (closedflag) { Console.WriteLine("In Bugstatus: if closedflag writing intofeature"); Console.WriteLine("Upali bugclosed: " + bg.bugclosedcount); string newclosedkey = bg.buglist[bg.bugclosedcount - 1]; bg.closedtkyKey = newclosedkey; Console.WriteLine("bg.closedtkyKey" + bg.closedtkyKey); Text = File.ReadAllLines(featurpath).ToList(); bg = bc.fetchBugCreatedClosedDate(bg); keyToInsert = "#" + newclosedkey + " Closed on: " + bg.bugcloseddate; Console.WriteLine(" keyToInsert" + keyToInsert); trimmedText = keyToInsert.Remove(7); int length = scenarioName.Length; int index = Text.FindIndex(x => x.Contains(scenarioName)); int newindex = index + 1; string a = Text[newindex]; Console.WriteLine("a contains: " + a); Console.WriteLine("trimmedText contains: " + trimmedText); Console.WriteLine("bg.nobugcreated" + bg.nobugcreated); if (a.Contains(trimmedText)) { if (bg.bugclosedcount == 0) { Console.WriteLine("Do Nothing"); } else if ((bg.bugclosedcount >= 1)) { if (bg.nobugcreated) { if (a.Contains("Opened")) { Console.WriteLine("Inside Opened"); if (a.Contains(bg.newopentktkey)) { Console.WriteLine("inside a contains bg.newopenkey"); int closeindex = newindex + 1; Console.WriteLine("newindex: " + newindex); Console.WriteLine("closeindex: " + closeindex); // Text.RemoveAt(closeindex); Text.Insert(closeindex, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } else { Console.WriteLine("Inside nobugcreated and if a contains Opened, else newopentktkey"); // when there are only closed keys 2nd may string updatedclosedkey = bg.buglist[0]; bg.closedtkyKey = updatedclosedkey; bg = bc.fetchBugCreatedClosedDate(bg); keyToInsert = "#" + updatedclosedkey + " Closed on: " + bg.bugcloseddate; Console.WriteLine("Key to insert: " + keyToInsert); // Text.Remove(a); Text.RemoveAt(newindex); Text.Insert(newindex, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } } else { Console.WriteLine("Inside nobugcreated and else a contains Opened"); // when there are only closed keys 2nd may string updatedclosedkey = bg.buglist[0]; bg.closedtkyKey = updatedclosedkey; bg = bc.fetchBugCreatedClosedDate(bg); keyToInsert = "#" + updatedclosedkey + " Closed on: " + bg.bugcloseddate; Console.WriteLine("Key to insert: " + keyToInsert); // Text.Remove(a); Text.RemoveAt(newindex); Text.Insert(newindex, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } } else { Console.WriteLine("old closed bug :" + bg.buglist[1]); Console.WriteLine("inside if a.contains(trimmedtext) and if bugcount > 1"); Text.Insert(index, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } } else { Console.WriteLine("inside else bugcount >1"); if (a.Contains(bg.buglist[0])) { Console.WriteLine("in if a.contains closed bug"); Text.Remove(a); Text.Insert(index, keyToInsert); } else { Console.WriteLine("in else a.contains closed bug"); Text.Insert(index, keyToInsert); } System.IO.File.WriteAllLines(featurpath, Text); } } else { Console.WriteLine("inside else a.contains(trimmedtext)"); Console.WriteLine("index : " + index); Console.WriteLine("newindex : " + newindex); Text.Insert(newindex, keyToInsert); System.IO.File.WriteAllLines(featurpath, Text); } } return(bg); }