-
-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathGitLab.bas
More file actions
136 lines (99 loc) · 4.18 KB
/
Copy pathGitLab.bas
File metadata and controls
136 lines (99 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
Attribute VB_Name = "gitlab"
Private pGitLabClient As WebClient
Private pToken As String
Private Property Get Token() As String
If pToken = "" Then
If Credentials.Loaded Then
pToken = Credentials.Values("GitLab")("token")
Else
pToken = InputBox("GitLab Token?")
End If
End If
Token = pToken
End Property
Private Property Get GitLabClient() As WebClient
If pGitLabClient Is Nothing Then
Set pGitLabClient = New WebClient
pGitLabClient.BaseUrl = "https://gitlab.com/api/v4"
Dim Auth As New TokenAuthenticator
Auth.Setup _
Header:="PRIVATE-TOKEN", _
value:=Token
Set pGitLabClient.Authenticator = Auth
End If
Set GitLabClient = pGitLabClient
End Property
Function GetProjects() As Object
'On Error GoTo ErrorHandler
Dim Request As New WebRequest
Dim Response As WebResponse
Request.Resource = "/projects?membership=true"
' Set the request format (Set {format} segment, content-types, and parse the response)
Request.Format = WebFormat.Json
' (GET, POST, PUT, DELETE, PATCH)
Request.Method = WebMethod.HttpGet
Set Response = GitLabClient.Execute(Request)
If Response.StatusCode <> WebStatusCode.Ok Then
Button = MsgBox(Response.StatusDescription, vbAbortRetryIgnore + vbCritical, "Hata olustu")
Else
Set GetProjects = Response.Data
'GetIssiues = WebHelpers.ConvertToJson(Response.Data, " ", 2)
'MsgBox WebHelpers.ConvertToJson(Response.Data, " ", 2)
End If
'ErrorHandler:
' MsgBox "The following error occurred: " & Err.Description
End Function
Function GetIssiues(ProjectId As Long, Start As Integer) As Object
'On Error GoTo ErrorHandler
Dim Request As New WebRequest
Dim Response As WebResponse
Request.Resource = "/issues?project=" & ProjectId & "&page=" & Start & "&per_page=100"
' Set the request format (Set {format} segment, content-types, and parse the response)
Request.Format = WebFormat.Json
' (GET, POST, PUT, DELETE, PATCH)
Request.Method = WebMethod.HttpGet
Set Response = GitLabClient.Execute(Request)
If Response.StatusCode <> WebStatusCode.Ok Then
Button = MsgBox(Response.StatusDescription, vbAbortRetryIgnore + vbCritical, "Hata olustu")
Else
Set GetIssiues = Response.Data
'GetIssiues = WebHelpers.ConvertToJson(Response.Data, " ", 2)
'MsgBox WebHelpers.ConvertToJson(Response.Data, " ", 2)
End If
'ErrorHandler:
' MsgBox "The following error occurred: " & Err.Description
End Function
Function GetEvents(ProjectId As Long) As Object
'On Error GoTo ErrorHandler
Dim Request As New WebRequest
Dim Response As WebResponse
Request.Resource = "/events?project=" & ProjectId & "&target_type=issue&action=closed&per_page=100"
' Set the request format (Set {format} segment, content-types, and parse the response)
Request.Format = WebFormat.Json
' (GET, POST, PUT, DELETE, PATCH)
Request.Method = WebMethod.HttpGet
Set Response = GitLabClient.Execute(Request)
If Response.StatusCode <> WebStatusCode.Ok Then
Button = MsgBox(Response.StatusDescription, vbAbortRetryIgnore + vbCritical, "Hata olustu")
Else
Set GetEvents = Response.Data
End If
End Function
Function GetNotes(ProjectId As Long, IssueId As Integer) As Object
'On Error GoTo ErrorHandler
Dim Request As New WebRequest
Dim Response As WebResponse
Request.Resource = "/projects/" & ProjectId & "/issues/" & IssueId & "/notes"
' Set the request format (Set {format} segment, content-types, and parse the response)
Request.Format = WebFormat.Json
' (GET, POST, PUT, DELETE, PATCH)
Request.Method = WebMethod.HttpGet
Set Response = GitLabClient.Execute(Request)
If Response.StatusCode = WebStatusCode.NotFound Then
'GetNotes = Null
ElseIf Response.StatusCode <> WebStatusCode.Ok Then
Button = MsgBox(Response.StatusDescription, vbAbortRetryIgnore + vbCritical, "Hata olustu")
Else
Set GetNotes = Response.Data
End If
End Function