Skip to content

Commit 284e49c

Browse files
authored
Import from any GitHub repository (#7)
* Select a GitHub Repository (alternative to AccessCodeLib)
1 parent b02ce37 commit 284e49c

File tree

7 files changed

+78
-52
lines changed

7 files changed

+78
-52
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ Details: https://wiki.access-codelib.net/ACLib-Import-Wizard
55

66
#### Using the Import-Wizard:
77
[Video: create new Access application](https://access-codelib.net/videos/ACLib-Import-Wizard/neue-anwendung-erstellen/)
8+
9+
[Video: Import from GitHub repository](https://access-codelib.net/videos/ACLib-Import-Wizard/ACLib-Import-Wizard_ImportFromGitHub.mp4)

access-add-in/ACLibImportWizard.accda

16 KB
Binary file not shown.

source/ACLibImportWizardForm.frm

20.2 KB
Binary file not shown.

source/ACLibRepositoryTreeForm.frm

-312 Bytes
Binary file not shown.

source/GitHubTreeNode.cls

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ Attribute VB_Exposed = False
1010
Option Compare Database
1111
Option Explicit
1212

13-
Private Const GitHubApiTreesUrl As String = "https://api.github.com/repos/AccessCodeLib/AccessCodeLib/git/trees/{SHA}"
13+
Private Const GitHubApiTreesUrl As String = "https://api.github.com/repos/{owner}/{repo}/git/trees/{SHA}"
1414

1515
Private m_Properties As Dictionary
1616
Private m_Nodes As Dictionary
17-
Private m_GitHubApiAuthToken As String
1817

1918
Private Sub Class_Initialize()
2019
Set m_Properties = New Dictionary
@@ -56,25 +55,20 @@ Public Property Get Sha() As String
5655
End Property
5756

5857
Public Sub BuildFromSHA(ByVal Sha As String, _
59-
Optional ByVal ReadSubTreeLevel As Long = 0, _
60-
Optional ByVal GitHubApiAuthToken As String = vbNullString)
58+
Optional ByVal ReadSubTreeLevel As Long = 0)
6159

6260
Dim JsonString As String
6361

64-
With New ACLibGitHubImporter
65-
If Len(GitHubApiAuthToken) > 0 Then
66-
m_GitHubApiAuthToken = GitHubApiAuthToken
67-
End If
68-
If Len(m_GitHubApiAuthToken) > 0 Then
69-
.GitHubApiAuthorizationToken = m_GitHubApiAuthToken
70-
End If
62+
With ACLibGitHubImporter
63+
7164
JsonString = .GetJsonString(Replace(GitHubApiTreesUrl, "{SHA}", Sha))
7265

7366
If JsonString Like "{""message"":*" Then
7467
Err.Raise vbObjectError, "GitHubTreeNode.BuildFromSHA", BuildErrMsgFromGitHubApiMessage(JsonString)
7568
End If
7669

7770
BuildFromJson JsonString, ReadSubTreeLevel
71+
7872
End With
7973

8074
End Sub
@@ -103,16 +97,11 @@ Friend Sub BuildFromJson(ByVal JsonString As String, Optional ByVal ReadSubTreeL
10397

10498
End Sub
10599

106-
Friend Sub InitFromJsonProperties(ByVal Props As JsonProperties, Optional ByVal ReadSubTreeLevel As Long = 0, _
107-
Optional ByVal GitHubApiAuthToken As String = vbNullString)
100+
Friend Sub InitFromJsonProperties(ByVal Props As JsonProperties, Optional ByVal ReadSubTreeLevel As Long = 0)
108101

109102
Dim Prop As JsonProperty
110103
Dim i As Long
111104

112-
If Len(GitHubApiAuthToken) > 0 Then
113-
m_GitHubApiAuthToken = GitHubApiAuthToken
114-
End If
115-
116105
For i = 1 To Props.Count
117106
Set Prop = Props.Item(i)
118107
If Prop.Name = "Tree" Then
@@ -145,28 +134,23 @@ Private Function GetNodeFromNodeProps(ByVal NodeProps As JsonProperties) As GitH
145134
Dim Node As GitHubTreeNode
146135

147136
Set Node = New GitHubTreeNode
148-
Node.InitFromJsonProperties NodeProps, , m_GitHubApiAuthToken
137+
Node.InitFromJsonProperties NodeProps
149138

150139
Set GetNodeFromNodeProps = Node
151140

152141
End Function
153142

154-
Friend Sub FillNextTreeLevel(Optional ByVal ReadSubTreeLevel As Long = 0, _
155-
Optional ByVal GitHubApiAuthToken As String = vbNullString)
143+
Friend Sub FillNextTreeLevel(Optional ByVal ReadSubTreeLevel As Long = 0)
156144

157145
Dim Node As GitHubTreeNode
158146
Dim NodeKey As Variant
159147

160148
If Not IsFolder Then
161149
Exit Sub
162150
End If
163-
164-
If Len(GitHubApiAuthToken) > 0 Then
165-
m_GitHubApiAuthToken = GitHubApiAuthToken
166-
End If
167151

168152
If m_Nodes.Count = 0 Then
169-
Me.BuildFromSHA Me.Sha, ReadSubTreeLevel, m_GitHubApiAuthToken
153+
Me.BuildFromSHA Me.Sha, ReadSubTreeLevel
170154
Exit Sub
171155
End If
172156

source/_config_Application.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Option Compare Database
3131
Option Explicit
3232

3333
'Versionsnummer
34-
Private Const APPLICATION_VERSION As String = "1.3.0"
34+
Private Const APPLICATION_VERSION As String = "1.3.1"
3535

3636
#Const USE_CLASS_ApplicationHandler_AppFile = 1
3737
#Const USE_CLASS_ApplicationHandler_DirTextbox = 1

source/codelib/_codelib/addins/shared/ACLibGitHubImporter.cls

Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ END
55
Attribute VB_Name = "ACLibGitHubImporter"
66
Attribute VB_GlobalNameSpace = False
77
Attribute VB_Creatable = False
8-
Attribute VB_PredeclaredId = False
8+
Attribute VB_PredeclaredId = True
99
Attribute VB_Exposed = False
1010
'---------------------------------------------------------------------------------------
1111
' Class: _codelib.addins.shared.ACLibGitHubImporter
@@ -28,12 +28,15 @@ Attribute VB_Exposed = False
2828
Option Compare Database
2929
Option 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

3434
Private m_GitHubApiAuthorizationToken As String
3535
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
3740

3841
#If VBA7 Then
3942
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)
5558
End 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
6269
End 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
66103
End Property
67104

68105
'---------------------------------------------------------------------------------------
69106
' Property: RevisionString
70107
'---------------------------------------------------------------------------------------
71108
Public 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
76113
End Property
77114

@@ -129,20 +166,26 @@ End Sub
129166
Friend 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

144175
End 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+
146189
Private 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

Comments
 (0)