Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4253 dpurdie 1
'-------------------------------------------------
2
' Function:     getJiraIssueList  
3
' Description:  Populate a Scripting.Dictionary variable with a list of issues
4
' Args:         NNpv_id     - PV_ID to process
5
'               issueInfo   - Scripting Dictionary to populate
6
'  
7
Sub getJiraIssueList ( NNpv_id,  issueInfo)
8
   Dim rsTemp, sqlstr, jkey
9
 
10
   ' Extract Data
11
   sqlstr = "SELECT iss_key FROM JIRA_ISSUES WHERE pv_id=" & NNpv_id & " ORDER BY iss_key ASC"
12
   Set rsTemp = OraDatabase.DbCreateDynaset( sqlstr, cint(0))
13
   retVal = rsTemp.RecordCount
14
 
15
   ' Insert into Dictionary
16
   While ((NOT rsTemp.BOF) AND (NOT rsTemp.EOF))
17
       jkey = rsTemp("iss_key")
18
       issueInfo.Add jkey, CreateObject( "Scripting.Dictionary" ) 
19
      rsTemp.MoveNext
20
   WEnd
21
 
22
   rsTemp.Close()
23
   Set rsTemp = nothing
24
End Sub
25
'-------------------------------------------------
26
' Function:     getJiraIssueDetails
27
' Description:  Extract Issue details from Jira
28
' Args:         NNpv_id     - PV_ID to process
29
'               issueInfo   - Scripting Dictionary to populate
30
'               mode        - 0: All Issues 1: Only Resolved
31
'  
32
Sub getJiraIssueDetails(NNpv_id,issueInfo,mode)
33
    Dim objXML, qry, post, iJSON, dJSON, oJSON, this, jkey, fields, data , resolution, el
34
    Dim dumpOutput, dumpInput
35
 
36
    ' Determine issues to process    
37
    Call getJiraIssueList (NNpv_id, issueInfo)
38
    If issueInfo.Count > 0 Then
39
        qry = "/rest/api/2/search"
40
        resolution = ""
41
        If mode = 1 Then resolution = " AND resolution is not null"
42
 
43
        dumpOutput = 0
44
        dumpInput = 0
45
 
46
        ' Create the JSON input via code
47
        ' Can do it as a string, as thats all we want
48
        set iJSON = New aspJSON
49
        With iJSON.data
50
        .Add "jql", "key in ("& Join(issueInfo.Keys, ",") &")" & resolution
51
        .Add "startAt", 0
52
        .Add "maxResults",  issueInfo.Count
53
        .Add "validateQuery", "false"
54
        .Add "fields", iJSON.Collection()
55
            With .item("fields")
56
                .Add 0, "key"
57
                .Add 1, "summary"
58
                .Add 2, "status"
59
                .Add 3, "priority"
60
                .Add 4, "issuetype"
61
                .Add 5, "resolution"
62
            End With
63
        End With
64
        post = iJSON.JSONoutput() 
65
 
66
        ' Display what we are doing
67
        If dumpInput <> 0 Then
68
            Response.Write "<br>Rest Query:" & JIRA_URL & qry
69
            set dJSON = New aspJSON
70
            dJSON.loadJSON( post ) 
71
            Response.Write "<br>Post json:<pre>" & dJSON.JSONoutput() & "</pre>"
72
        End If
73
 
74
 
75
        Set objXML = CreateObject("MSXML2.ServerXMLHTTP.6.0")
76
        objXML.Open "POST", JIRA_URL & qry , false
77
        objXML.setRequestHeader "Authorization", "Basic " & Base64Encode(JIRA_CREDENTAILS)
78
        objXML.setRequestHeader "Content-Type", "application/json"
79
        On Error Resume Next
80
        objXML.Send(post)
81
        if Err.Number <> 0 then
82
            Response.Write "<br>Error Code: " & Err.Number & ": " & Err.Description
83
            On Error Goto 0
84
        else
85
            On Error Goto 0
86
            if  objXML.status <> 200 then
87
                Response.Write "<br>Status: " & objXML.status
88
                Response.Write "<pre>"
89
                Response.Write objXML.responseText
90
                Response.Write "</pre>"
91
 
92
            Else
93
                'Response.Write "<pre>"
94
                'Response.Write objXML.responseText
95
                'Response.Write "</pre>"
96
 
97
                Set oJSON = New aspJSON
98
                oJSON.loadJSON( objXML.responseText )
99
 
100
                if dumpOutput <> 0 then
101
                    Response.Write "<br>Pretty JSON display<pre>"
102
                    Response.Write oJSON.JSONoutput()
103
                    Response.Write "</pre>"
104
                end if
105
 
106
                ' Add info from Jira into the issueInfo
107
        On Error Resume Next
108
                For Each el In oJSON.data("issues")
109
                   Set this = oJSON.data("issues").item(el)
110
                   jkey = this.item("key")
111
 
112
                   If issueInfo.Exists(jkey) Then
113
                        Set fields = this.item("fields")
114
                        Set data = issueInfo.Item(jkey) 
115
                        data.add "type","JIRA"
116
                        data.add "key",this.item("key")
117
                        data.add "url",JIRA_URL & "/browse/" & this.item("key")
118
                        data.add "statusIcon",fields.item("status").item("iconUrl")
119
                        data.add "status",fields.item("status").item("name")
120
                        data.add "issuetypeIcon",fields.item("issuetype").item("iconUrl")
121
                        data.add "issuetype",fields.item("issuetype").item("name")
122
                        data.add "priorityIcon",fields.item("priority").item("iconUrl")
123
                        data.add "priority",fields.item("priority").item("name")
124
                        data.add "summary",fields.item("summary")
125
                        If TypeName(fields.item("resolution")) = "Dictionary" Then
126
                                data.add "resolution", fields.item("resolution").item("name")
127
                        End If
128
                   End If
129
                Next
130
 
131
                ' Delete empty entries
132
                If mode <> 0 Then
133
                    For Each jkey In issueInfo
134
                        Set el = issueInfo.item(jkey)
135
                        If el.Count = 0 Then
136
                            issueInfo.remove(jkey)
137
                        End If
138
                    Next
139
                End If
140
 
141
            end if
142
        end if
143
    End If
144
End Sub
145
'--- End of File