private string BuildJiraIssue(SubmitBugListingModel model) { var jiraJson = new { fields = new Dictionary <string, object> { { "project", new { id = "11600" } }, { "summary", model.BugSummary }, { "description", model.BugDescription + Environment.NewLine + model.BuildNumber }, { "issuetype", new { id = "10004" } } } }; string url = "https://jira-stage.control4.com/rest/api/2/issue/"; string user = "******"; string password = "******"; var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/json"; string credentials = Convert.ToBase64String( Encoding.ASCII.GetBytes(user + ":" + password)); request.Headers[HttpRequestHeader.Authorization] = string.Format( "Basic {0}", credentials); string data = JsonConvert.SerializeObject(jiraJson); using (var webStream = request.GetRequestStream()) using (var requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII)) { requestWriter.Write(data); } try { var webResponse = request.GetResponse(); using (var responseReader = new StreamReader(webResponse.GetResponseStream())) { string response = responseReader.ReadToEnd(); var values = JsonConvert.DeserializeObject <Dictionary <string, string> >(response); var key = values["key"]; return(key); } } catch (Exception ex) { throw ex; } }
public IActionResult SubmitBug(int id) { var betaProject = _context.BetaOpportunity .Where(b => b.Id == id).FirstOrDefault(); var model = new SubmitBugListingModel { Id = betaProject.Id, ProjectName = betaProject.ProjectName, }; return(View(model)); }
public async Task <IActionResult> SubmitBug(SubmitBugListingModel model) { if (ModelState.IsValid) { var jiraResponse = BuildJiraIssue(model); var values = new Dictionary <string, string> { { "title", "[" + jiraResponse + "]" + " " + model.BugSummary }, { "category", "8" }, { "raw", model.BugDescription + Environment.NewLine + model.BuildNumber }, { "api_key", "39946de7bedac9af2676dfca3be92ae943e85ea2dd9f35e12b7ecb6a732b2747" }, { "api_username", "amunford" } }; var content = new FormUrlEncodedContent(values); var response = await _client.PostAsync("http://control4discourse.westus.cloudapp.azure.com/posts.json", content); var responseString = await response.Content.ReadAsStringAsync(); var bugUrl = ""; if (!string.IsNullOrEmpty(jiraResponse)) { var bugSummary = Regex.Replace(model.BugSummary.ToLower(), @"\s-", ""); bugUrl = "http://control4discourse.westus.cloudapp.azure.com/t/" + jiraResponse + "-" + Regex.Replace(bugSummary, @"\s", "-"); } else { var bugSummary = Regex.Replace(model.BugSummary.ToLower(), @"\s-", ""); bugUrl = "http://control4discourse.westus.cloudapp.azure.com/t/" + Regex.Replace(bugSummary, @"\s", "-"); } var submittedBug = new BugSubmittedListingModel { ReferenceNumber = jiraResponse, ForumPostUrl = bugUrl }; return(RedirectToAction("BugSubmitted", "Betas", submittedBug)); } return(View(model)); }