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,12 +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
34
Private m_GitHubApiAuthorizationToken As String
35
35
Private m_LastCommit As Date
36
- Private m_UseDraftBranch As Boolean
36
+
37
+ Private m_RepositoryOwner As String
38
+ Private m_RepositoryName As String
39
+ Private m_BranchName As String
37
40
38
41
#If VBA7 Then
39
42
Private Declare PtrSafe Function DeleteUrlCacheEntry Lib "wininet .dll " Alias "DeleteUrlCacheEntryA " (ByVal lpszUrlName As String ) As Long
@@ -55,23 +58,57 @@ Public Property Let GitHubApiAuthorizationToken(ByVal NewValue As String)
55
58
End Property
56
59
57
60
'---------------------------------------------------------------------------------------
58
- ' Property: UseDraftBranch
61
+ ' Property: RepositoryOwner
59
62
'---------------------------------------------------------------------------------------
60
- Public Property Get UseDraftBranch() As Boolean
61
- 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
62
69
End Property
63
70
64
- Public Property Let UseDraftBranch(ByVal NewValue As Boolean )
65
- 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
66
103
End Property
67
104
68
105
'---------------------------------------------------------------------------------------
69
106
' Property: RevisionString
70
107
'---------------------------------------------------------------------------------------
71
108
Public Property Get RevisionString(Optional ByVal Requery As Boolean = False ) As String
72
109
RevisionString = Format(LastCommit, "yyyymmddhhnnss" )
73
- If UseDraftBranch Then
74
- RevisionString = RevisionString & "-draft"
110
+ If BranchName <> "master" Then
111
+ RevisionString = RevisionString & "-" & BranchName
75
112
End If
76
113
End Property
77
114
@@ -129,20 +166,26 @@ End Sub
129
166
Friend Sub DownloadACLibFileFromWeb (ByVal ACLibPath As String , ByVal TargetFilePath As String )
130
167
131
168
Dim DownLoadUrl As String
132
- Dim BranchName As String
133
169
134
- If UseDraftBranch Then
135
- BranchName = "draft"
136
- Else
137
- BranchName = "master"
138
- End If
139
- DownLoadUrl = Replace(GitHubContentBaseUrl, "{branch}" , BranchName)
170
+ DownLoadUrl = FillRepositoryData(GitHubContentBaseUrl)
140
171
DownLoadUrl = Replace(DownLoadUrl, "{path}" , ACLibPath)
141
172
142
173
DownloadFileFromWeb DownLoadUrl, TargetFilePath
143
174
144
175
End Sub
145
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
+
146
189
Private Function GetLastCommitFromWeb () As Date
147
190
148
191
'alternative: git rev-list HEAD --count
@@ -151,14 +194,9 @@ Private Function GetLastCommitFromWeb() As Date
151
194
152
195
Dim CommitUrl As String
153
196
Dim LastCommitInfo As String
154
- CommitUrl = GitHubApiBaseUrl & "commits/"
155
-
156
- If UseDraftBranch Then
157
- CommitUrl = CommitUrl & "draft"
158
- Else
159
- CommitUrl = CommitUrl & "master"
160
- End If
161
197
198
+ CommitUrl = FillRepositoryData(GitHubApiBaseUrl) & "commits/" & BranchName
199
+
162
200
Const RevisionTag As String = "Revision "
163
201
164
202
Dim JsonString As String
@@ -179,7 +217,9 @@ Friend Function GetJsonString(ByVal ApiUrl As String) As String
179
217
Dim ApiResponse As String
180
218
Dim ApiAuthToken As String
181
219
Dim json As Object
182
- Dim xml As Object 'MSXML2.XMLHTTP60
220
+ Dim xml As Object 'MSXML2.XMLHTTP6
221
+
222
+ ApiUrl = FillRepositoryData(ApiUrl)
183
223
184
224
ApiAuthToken = GitHubApiAuthorizationToken
185
225
0 commit comments