简体   繁体   中英

JSON Payload from JIRA webhook does not always enter into SQL database

I am having a bit of trouble implementing Json Paylaods from a JIRA webhook in MVC VB.net because of the fields IssueType and Priority in JIRA. the only time when the JSON payload will successfully enter is when the IssueType = Bug and priority = major .

I am think that the problem lies with mismatching ID's of these two fields. I found out that when the priority is major it's ID is 3. When the IssueType is Bug it's ID is 1. I think that because in my company's JIRA application only has certain options to choose from these two fields eg The Priority field can't choose fatal as an option so that ID is never chosen.

So my question is how to I correctly match up these two fields in my application. At the moment In my table the Priority Table is as follows:

ID ----- Name
2 ------ Critical
3 ------ Major
4 ------ Minor

The IssueType Table is as follows:

ID ----- Name
1 ------ Bug
2 ------ Query

I am deserializing the Json like this:

 Dim r As System.IO.StreamReader = New System.IO.StreamReader(HttpContext.Request.InputStream)
 Dim json As String = r.ReadToEnd()
 Dim iss As object = JsonConvert.DeserializeObject(Of object )(json)
System.Diagnostics.Trace.TraceError(json )

Then I am reading the Data into my Database using Entity Framework like this:

 Dim newIssue As New IssueResultTable
 newIssue.issueKey = issue.issue.key
 newIssue.status = issue.issue.fields.status.name
 newIssue.IssueType = issue.issue.fields.issuetype.id
 newIssue.Priority = issue.issue.fields.priority.id

 Using db As New GartanIssueTrackerEntities
 db.IssueResultTables.Add(newIssue)
 db.SaveChanges()
 End Using
 Catch ex As Exception

 End Try

I then display this information in my View but it only works with the examples I said above. What is the correctly way to order these fields in the database, should it matter? Or can it be any order or does it have to be the exact same as the JIRA fields that also includes all the fields from JIRA not just ones my application uses eg Do I have to add Fatal as ID 1 to my table?

I was correct in saying that the problem was due to mismatching ID's and columns from the JIRA application and my SQL database.

Using RequestBin I was able to fire the webhook to the RequestBin where I would inspect the Json Payload. Once I inspected the data I had to change the columns and add additional columns so that my application would successfully all the data that I needed.

The ID's in Jira that you want to use must match the one's that are in your database if you want to retrieve them successfully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM