5
5
Attribute VB_Name = "ACLibGitHubImporter"
6
6
Attribute VB_GlobalNameSpace = False
7
7
Attribute VB_Creatable = False
8
- Attribute VB_PredeclaredId = False
8
+ Attribute VB_PredeclaredId = True
9
9
Attribute VB_Exposed = False
10
10
'---------------------------------------------------------------------------------------
11
11
' Class: _codelib.addins.shared.ACLibGitHubImporter
@@ -28,11 +28,15 @@ Attribute VB_Exposed = False
28
28
Option Compare Database
29
29
Option Explicit
30
30
31
- Private Const GitHubContentBaseUrl As String = "https://raw.githubusercontent.com/AccessCodeLib/AccessCodeLib /{branch}/{path}"
32
- Private Const GitHubApiBaseUrl As String = "https://api.github.com/repos/AccessCodeLib/AccessCodeLib /"
31
+ Private Const GitHubContentBaseUrl As String = "https://raw.githubusercontent.com/{owner}/{repo} /{branch}/{path}"
32
+ Private Const GitHubApiBaseUrl As String = "https://api.github.com/repos/{owner}/{repo} /"
33
33
34
+ Private m_GitHubApiAuthorizationToken As String
34
35
Private m_LastCommit As Date
35
- Private m_UseDraftBranch As Boolean
36
+
37
+ Private m_RepositoryOwner As String
38
+ Private m_RepositoryName As String
39
+ Private m_BranchName As String
36
40
37
41
#If VBA7 Then
38
42
Private Declare PtrSafe Function DeleteUrlCacheEntry Lib "wininet .dll " Alias "DeleteUrlCacheEntryA " (ByVal lpszUrlName As String ) As Long
@@ -43,23 +47,68 @@ Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFile
43
47
#End If
44
48
45
49
'---------------------------------------------------------------------------------------
46
- ' Property: UseDraftBranch
50
+ ' Property: GitHubAuthorizationubAuthToken
51
+ '---------------------------------------------------------------------------------------
52
+ Public Property Get GitHubApiAuthorizationToken() As String
53
+ GitHubApiAuthorizationToken = m_GitHubApiAuthorizationToken
54
+ End Property
55
+
56
+ Public Property Let GitHubApiAuthorizationToken(ByVal NewValue As String )
57
+ m_GitHubApiAuthorizationToken = NewValue
58
+ End Property
59
+
60
+ '---------------------------------------------------------------------------------------
61
+ ' Property: RepositoryOwner
47
62
'---------------------------------------------------------------------------------------
48
- Public Property Get UseDraftBranch() As Boolean
49
- UseDraftBranch = m_UseDraftBranch
63
+ Public Property Get RepositoryOwner() As String
64
+ If Len(m_RepositoryOwner) > 0 Then
65
+ RepositoryOwner = m_RepositoryOwner
66
+ Else ' Default: AccessCodeLib
67
+ RepositoryOwner = "AccessCodeLib"
68
+ End If
50
69
End Property
51
70
52
- Public Property Let UseDraftBranch(ByVal NewValue As Boolean )
53
- m_UseDraftBranch = NewValue
71
+ Public Property Let RepositoryOwner(ByVal NewValue As String )
72
+ m_RepositoryOwner = NewValue
73
+ End Property
74
+
75
+ '---------------------------------------------------------------------------------------
76
+ ' Property: RepositoryName
77
+ '---------------------------------------------------------------------------------------
78
+ Public Property Get RepositoryName() As String
79
+ If Len(m_RepositoryName) > 0 Then
80
+ RepositoryName = m_RepositoryName
81
+ Else ' Default: AccessCodeLib
82
+ RepositoryName = "AccessCodeLib"
83
+ End If
84
+ End Property
85
+
86
+ Public Property Let RepositoryName(ByVal NewValue As String )
87
+ m_RepositoryName = NewValue
88
+ End Property
89
+
90
+ '---------------------------------------------------------------------------------------
91
+ ' Property: BranchName
92
+ '---------------------------------------------------------------------------------------
93
+ Public Property Get BranchName() As String
94
+ If Len(m_BranchName) > 0 Then
95
+ BranchName = m_BranchName
96
+ Else ' Default: master
97
+ BranchName = "master"
98
+ End If
99
+ End Property
100
+
101
+ Public Property Let BranchName(ByVal NewValue As String )
102
+ m_BranchName = NewValue
54
103
End Property
55
104
56
105
'---------------------------------------------------------------------------------------
57
106
' Property: RevisionString
58
107
'---------------------------------------------------------------------------------------
59
108
Public Property Get RevisionString(Optional ByVal Requery As Boolean = False ) As String
60
109
RevisionString = Format(LastCommit, "yyyymmddhhnnss" )
61
- If UseDraftBranch Then
62
- RevisionString = RevisionString & "-draft"
110
+ If BranchName <> "master" Then
111
+ RevisionString = RevisionString & "-" & BranchName
63
112
End If
64
113
End Property
65
114
@@ -104,25 +153,39 @@ End Sub
104
153
Private Sub UpdateCodeModuleInTable (ByVal ModuleName As String , ByVal ACLibPath As String , Optional ByVal Requery As Boolean = False )
105
154
106
155
Dim TempFile As String
107
- Dim DownLoadUrl As String
108
- Dim BranchName As String
109
156
110
- TempFile = FileTools.TempPath & ModuleName & FileTools.GetFileExtension(ACLibPath, True )
111
157
112
- If UseDraftBranch Then
113
- BranchName = "draft"
114
- Else
115
- BranchName = "master"
116
- End If
117
- DownLoadUrl = Replace(GitHubContentBaseUrl, "{branch}" , BranchName)
118
- DownLoadUrl = Replace(DownLoadUrl, "{path}" , ACLibPath)
158
+ TempFile = FileTools.TempPath & ModuleName & FileTools.GetFileExtension(ACLibPath, True )
159
+ DownloadACLibFileFromWeb ACLibPath, TempFile
119
160
120
- DownloadFileFromWeb DownLoadUrl, TempFile
121
161
CurrentApplication.SaveAppFile ModuleName, TempFile, False , "SccRev" , Me.RevisionString(Requery)
122
162
Kill TempFile
123
163
124
164
End Sub
125
165
166
+ Friend Sub DownloadACLibFileFromWeb (ByVal ACLibPath As String , ByVal TargetFilePath As String )
167
+
168
+ Dim DownLoadUrl As String
169
+
170
+ DownLoadUrl = FillRepositoryData(GitHubContentBaseUrl)
171
+ DownLoadUrl = Replace(DownLoadUrl, "{path}" , ACLibPath)
172
+
173
+ DownloadFileFromWeb DownLoadUrl, TargetFilePath
174
+
175
+ End Sub
176
+
177
+ Private Function FillRepositoryData (ByVal StringWithPlaceHolder As String ) As String
178
+
179
+ Dim TempValue As String
180
+
181
+ TempValue = Replace(StringWithPlaceHolder, "{owner}" , RepositoryOwner)
182
+ TempValue = Replace(TempValue, "{repo}" , RepositoryName)
183
+ TempValue = Replace(TempValue, "{branch}" , BranchName)
184
+
185
+ FillRepositoryData = TempValue
186
+
187
+ End Function
188
+
126
189
Private Function GetLastCommitFromWeb () As Date
127
190
128
191
'alternative: git rev-list HEAD --count
@@ -131,14 +194,9 @@ Private Function GetLastCommitFromWeb() As Date
131
194
132
195
Dim CommitUrl As String
133
196
Dim LastCommitInfo As String
134
- CommitUrl = GitHubApiBaseUrl & "commits/"
135
-
136
- If UseDraftBranch Then
137
- CommitUrl = CommitUrl & "draft"
138
- Else
139
- CommitUrl = CommitUrl & "master"
140
- End If
141
197
198
+ CommitUrl = FillRepositoryData(GitHubApiBaseUrl) & "commits/" & BranchName
199
+
142
200
Const RevisionTag As String = "Revision "
143
201
144
202
Dim JsonString As String
@@ -154,23 +212,31 @@ Private Function GetLastCommitFromWeb() As Date
154
212
155
213
End Function
156
214
157
- Private Function GetJsonString (ByVal ApiUrl As String ) As String
158
-
159
- Dim ApiResponse As String
160
- Dim json As Object
161
-
162
- Dim xml As Object ' MSXML2.XMLHTTP60
163
- Set xml = CreateObject("MSXML2.XMLHTTP.6.0" )
164
-
165
- xml.Open "GET" , ApiUrl, False
166
- xml.setRequestHeader "Content-type" , "application/json"
167
- xml.send
168
- While xml.ReadyState <> 4
169
- DoEvents
170
- Wend
171
- ApiResponse = xml.responseText
172
-
173
- GetJsonString = ApiResponse
215
+ Friend Function GetJsonString (ByVal ApiUrl As String ) As String
216
+
217
+ Dim ApiResponse As String
218
+ Dim ApiAuthToken As String
219
+ Dim json As Object
220
+ Dim xml As Object 'MSXML2.XMLHTTP6
221
+
222
+ ApiUrl = FillRepositoryData(ApiUrl)
223
+
224
+ ApiAuthToken = GitHubApiAuthorizationToken
225
+
226
+ Set xml = CreateObject("MSXML2.XMLHTTP.6.0" )
227
+
228
+ xml.Open "GET" , ApiUrl, False
229
+ If Len(ApiAuthToken) > 0 Then
230
+ xml.setRequestHeader "Authorization" , ApiAuthToken
231
+ End If
232
+ xml.setRequestHeader "Content-type" , "application/json"
233
+ xml.send
234
+ While xml.ReadyState <> 4
235
+ DoEvents
236
+ Wend
237
+ ApiResponse = xml.responseText
238
+
239
+ GetJsonString = ApiResponse
174
240
175
241
End Function
176
242
0 commit comments