Subversion Repositories DevTools

Rev

Blame | Last modification | View Log | RSS feed

'-------------------------------------------------
' Function:     getJiraIssueList  
' Description:  Populate a Scripting.Dictionary variable with a list of issues
' Args:         NNpv_id     - PV_ID List to process (Comma sep)
'               issueInfo   - Scripting Dictionary to populate
'                             Will be cleared before use
'  
Sub getJiraIssueList ( NNpv_id,  issueInfo)
   Dim rsTemp, sqlstr, jkey, retVal
   
   ' Extract Data
   sqlstr = "SELECT iss_key FROM JIRA_ISSUES WHERE pv_id in (" & NNpv_id & ")"& " ORDER BY iss_key ASC"
   Set rsTemp = OraDatabase.DbCreateDynaset( sqlstr, cint(0))
   retVal = rsTemp.RecordCount

   ' Insert into clean Dictionary
   issueInfo.RemoveAll
   While ((NOT rsTemp.BOF) AND (NOT rsTemp.EOF))
       jkey = rsTemp("iss_key")
       issueInfo.Add jkey, CreateObject( "Scripting.Dictionary" ) 
      rsTemp.MoveNext
   WEnd
 
   rsTemp.Close()
   Set rsTemp = nothing
End Sub
'-------------------------------------------------
' Function:     getJiraIssueDetails
' Description:  Extract Issue details from Jira
' Args:         NNpv_id     - PV_ID List to process (Comma sep)
'               issueInfo   - Scripting Dictionary to populate
'                             Will be cleared before use
'               mode        - 0: All Issues 1: Only Resolved
'  
Sub getJiraIssueDetails(NNpv_id,issueInfo,mode)
    Dim objXML, qry, post, iJSON, dJSON, oJSON, this, jkey, fields, data , resolution, el
    Dim dumpOutput, dumpInput

    ' Determine issues to process    
    Call getJiraIssueList (NNpv_id, issueInfo)
    If issueInfo.Count > 0 Then
        qry = "/rest/api/2/search"
        resolution = ""
        If mode = 1 Then resolution = " AND resolution is not null"

        dumpOutput = 0
        dumpInput = 0

        ' Create the JSON input via code
        ' Can do it as a string, as thats all we want
        set iJSON = New aspJSON
        With iJSON.data
        .Add "jql", "key in ("& Join(issueInfo.Keys, ",") &")" & resolution
        .Add "startAt", 0
        .Add "maxResults",  issueInfo.Count
        .Add "validateQuery", "false"
        .Add "fields", iJSON.Collection()
            With .item("fields")
                .Add 0, "key"
                .Add 1, "summary"
                .Add 2, "status"
                .Add 3, "priority"
                .Add 4, "issuetype"
                .Add 5, "resolution"
            End With
        End With
        post = iJSON.JSONoutput() 

        ' Display what we are doing
        If dumpInput <> 0 Then
            Response.Write "<br>Rest Query:" & JIRA_URL & qry
            set dJSON = New aspJSON
            dJSON.loadJSON( post ) 
            Response.Write "<br>Post json:<pre>" & dJSON.JSONoutput() & "</pre>"
        End If


        Set objXML = CreateObject("MSXML2.ServerXMLHTTP.6.0")
        objXML.Open "POST", JIRA_URL & qry , false
        objXML.setRequestHeader "Authorization", "Basic " & Base64Encode(JIRA_CREDENTAILS)
        objXML.setRequestHeader "Content-Type", "application/json"
        On Error Resume Next
        objXML.Send(post)
        if Err.Number <> 0 then
            Response.Write "<br>Error Code: " & Err.Number & ": " & Err.Description
            On Error Goto 0
        else
            On Error Goto 0
            if  objXML.status <> 200 then
                Response.Write "<br>Status: " & objXML.status
                Response.Write "<pre>"
                Response.Write objXML.responseText
                Response.Write "</pre>"

            Else
                'Response.Write "<pre>"
                'Response.Write objXML.responseText
                'Response.Write "</pre>"

                Set oJSON = New aspJSON
                oJSON.loadJSON( objXML.responseText )

                if dumpOutput <> 0 then
                    Response.Write "<br>Pretty JSON display<pre>"
                    Response.Write oJSON.JSONoutput()
                    Response.Write "</pre>"
                end if
                
                ' Add info from Jira into the issueInfo
        On Error Resume Next
                For Each el In oJSON.data("issues")
                   Set this = oJSON.data("issues").item(el)
                   jkey = this.item("key")
                    
                   If issueInfo.Exists(jkey) Then
                        Set fields = this.item("fields")
                        Set data = issueInfo.Item(jkey) 
                        data.add "type","JIRA"
                        data.add "key",this.item("key")
                        data.add "url",JIRA_URL & "/browse/" & this.item("key")
                        data.add "statusIcon",fields.item("status").item("iconUrl")
                        data.add "status",fields.item("status").item("name")
                        data.add "issuetypeIcon",fields.item("issuetype").item("iconUrl")
                        data.add "issuetype",fields.item("issuetype").item("name")
                        data.add "priorityIcon",fields.item("priority").item("iconUrl")
                        data.add "priority",fields.item("priority").item("name")
                        data.add "summary",fields.item("summary")
                        If TypeName(fields.item("resolution")) = "Dictionary" Then
                                data.add "resolution", fields.item("resolution").item("name")
                        End If
                   End If
                Next

                ' Delete empty entries
                If mode <> 0 Then
                    For Each jkey In issueInfo
                        Set el = issueInfo.item(jkey)
                        If el.Count = 0 Then
                            issueInfo.remove(jkey)
                        End If
                    Next
                End If

            end if
        end if
    End If
End Sub
'--- End of File