add first default branch on DNS query

This commit is contained in:
Simon Vieille 2022-08-18 11:40:29 +02:00
parent 865cc9f1f6
commit 320564ec18
No known key found for this signature in database
GPG key ID: 579388D585F70417
4 changed files with 9 additions and 7 deletions

View file

@ -9,7 +9,7 @@ import (
// GetTargetFromDNS searches for CNAME or TXT entries on the request domain ending with MainDomainSuffix.
// If everything is fine, it returns the target data.
func GetTargetFromDNS(domain, mainDomainSuffix string, dnsLookupCache cache.SetGetKey) (targetOwner, targetRepo, targetBranch string) {
func GetTargetFromDNS(domain, mainDomainSuffix, firstDefaultBranch string, dnsLookupCache cache.SetGetKey) (targetOwner, targetRepo, targetBranch string) {
// Get CNAME or TXT
var cname string
var err error
@ -46,10 +46,10 @@ func GetTargetFromDNS(domain, mainDomainSuffix string, dnsLookupCache cache.SetG
targetBranch = cnameParts[len(cnameParts)-3]
}
if targetRepo == "" {
targetRepo = "pages"
targetRepo = firstDefaultBranch
}
if targetBranch == "" && targetRepo != "pages" {
targetBranch = "pages"
if targetBranch == "" && targetRepo != firstDefaultBranch {
targetBranch = firstDefaultBranch
}
// if targetBranch is still empty, the caller must find the default branch
return