Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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