55Attribute VB_Name = "ACLibGitHubImporter"
66Attribute VB_GlobalNameSpace = False
77Attribute VB_Creatable = False
8- Attribute VB_PredeclaredId = False
8+ Attribute VB_PredeclaredId = True
99Attribute VB_Exposed = False
1010'---------------------------------------------------------------------------------------
1111' Class: _codelib.addins.shared.ACLibGitHubImporter
@@ -28,12 +28,15 @@ Attribute VB_Exposed = False
2828Option Compare Database
2929Option Explicit
3030
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} /"
3333
3434Private m_GitHubApiAuthorizationToken As String
3535Private 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
3740
3841#If VBA7 Then
3942Private 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)
5558End Property
5659
5760'---------------------------------------------------------------------------------------
58- ' Property: UseDraftBranch
61+ ' Property: RepositoryOwner
5962'---------------------------------------------------------------------------------------
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
6269End Property
6370
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
66103End Property
67104
68105'---------------------------------------------------------------------------------------
69106' Property: RevisionString
70107'---------------------------------------------------------------------------------------
71108Public Property Get RevisionString(Optional ByVal Requery As Boolean = False ) As String
72109 RevisionString = Format(LastCommit, "yyyymmddhhnnss" )
73- If UseDraftBranch Then
74- RevisionString = RevisionString & "-draft"
110+ If BranchName <> "master" Then
111+ RevisionString = RevisionString & "-" & BranchName
75112 End If
76113End Property
77114
@@ -129,20 +166,26 @@ End Sub
129166Friend Sub DownloadACLibFileFromWeb (ByVal ACLibPath As String , ByVal TargetFilePath As String )
130167
131168 Dim DownLoadUrl As String
132- Dim BranchName As String
133169
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)
140171 DownLoadUrl = Replace(DownLoadUrl, "{path}" , ACLibPath)
141172
142173 DownloadFileFromWeb DownLoadUrl, TargetFilePath
143174
144175End Sub
145176
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+
146189Private Function GetLastCommitFromWeb () As Date
147190
148191'alternative: git rev-list HEAD --count
@@ -151,14 +194,9 @@ Private Function GetLastCommitFromWeb() As Date
151194
152195 Dim CommitUrl As String
153196 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
161197
198+ CommitUrl = FillRepositoryData(GitHubApiBaseUrl) & "commits/" & BranchName
199+
162200 Const RevisionTag As String = "Revision "
163201
164202 Dim JsonString As String
@@ -179,7 +217,9 @@ Friend Function GetJsonString(ByVal ApiUrl As String) As String
179217 Dim ApiResponse As String
180218 Dim ApiAuthToken As String
181219 Dim json As Object
182- Dim xml As Object 'MSXML2.XMLHTTP60
220+ Dim xml As Object 'MSXML2.XMLHTTP6
221+
222+ ApiUrl = FillRepositoryData(ApiUrl)
183223
184224 ApiAuthToken = GitHubApiAuthorizationToken
185225
0 commit comments