Skip to content

Commit ffe6771

Browse files
committed
getting default branch
1 parent a8037ff commit ffe6771

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/cls/ZPM/Package.cls

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,29 @@ ClassMethod GetPackageNameFromRepositoryURL(url As %String) As %String
273273
Return $PIECE(url, "/", *-1)
274274
}
275275

276+
ClassMethod GetDefaultBranch(path As %String) As %String
277+
{
278+
If ($Extract(path,$Length(path))="/") {
279+
Set path = $Extract(path,1,*-1)
280+
}
281+
Set branch = "main"
282+
Set ht = ##class(%Net.HttpRequest).%New()
283+
Set ht.Server = "api.github.com"
284+
Set ht.SSLConfiguration = ..GetSSLConfiguration(ht.Server)
285+
Set ht.Https = 1
286+
Set ht.Location = "/repos"_path
287+
$$$ThrowOnError(ht.Get())
288+
If (ht.HttpResponse.StatusCode=200) {
289+
Set jo = {}.%FromJSON(ht.HttpResponse.Data)
290+
Set branch = jo."default_branch"
291+
}
292+
return branch
293+
}
294+
276295
ClassMethod DownloadPackageFromGitHub(url As %String) As %String
277296
{
278-
SET url = url _ "archive/master.tar.gz"
279297
Do ##class(%Net.URLParser).Parse(url, .tComponents)
298+
Set branch = ..GetDefaultBranch(tComponents("path"))
280299
Set ht = ##class(%Net.HttpRequest).%New()
281300
Set ht.Server = tComponents("host")
282301
If $get(tComponents("scheme"))="https" {
@@ -286,8 +305,7 @@ ClassMethod DownloadPackageFromGitHub(url As %String) As %String
286305
If $data(tComponents("port"), port), port'="" {
287306
Set ht.Port = port
288307
}
289-
Set ht.Location = tComponents("path")
290-
308+
Set ht.Location = tComponents("path")_"archive/"_branch_".tar.gz"
291309
$$$ThrowOnError(ht.Get())
292310
If (ht.HttpResponse.StatusCode'=200) {
293311
$$$ThrowStatus($$$ERROR(5001,"Unable to download repository "_url))

0 commit comments

Comments
 (0)