refactor(runner): centralize isSameInstance in urlutil.go
This commit is contained in:
parent
0329cfb837
commit
c5fd7e60cd
2 changed files with 23 additions and 16 deletions
|
|
@ -240,19 +240,3 @@ func newRemoteReusableWorkflowWithPlat(url, uses string) *remoteReusableWorkflow
|
|||
URL: url,
|
||||
}
|
||||
}
|
||||
|
||||
// isSameInstance checks if two URLs/hosts refer to the same instance.
|
||||
// Normalizes protocol prefixes, trailing slashes, and case.
|
||||
func isSameInstance(urlOrHost, instance string) bool {
|
||||
normalize := func(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
s = strings.TrimSuffix(s, "/")
|
||||
if strings.HasPrefix(s, "http://") || strings.HasPrefix(s, "https://") {
|
||||
if u, err := url.Parse(s); err == nil && u.Host != "" {
|
||||
return strings.ToLower(u.Host)
|
||||
}
|
||||
}
|
||||
return strings.ToLower(s)
|
||||
}
|
||||
return normalize(urlOrHost) == normalize(instance)
|
||||
}
|
||||
|
|
|
|||
23
act/runner/urlutil.go
Normal file
23
act/runner/urlutil.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package runner
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Normalizes protocol prefixes, trailing slashes, and case.
|
||||
func normalizeHost(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
s = strings.TrimSuffix(s, "/")
|
||||
if strings.HasPrefix(s, "http://") || strings.HasPrefix(s, "https://") {
|
||||
if u, err := url.Parse(s); err == nil && u.Host != "" {
|
||||
return strings.ToLower(u.Host)
|
||||
}
|
||||
}
|
||||
return strings.ToLower(s)
|
||||
}
|
||||
|
||||
// isSameInstance checks if two URLs/hosts refer to the same instance.
|
||||
func isSameInstance(urlOrHost, instance string) bool {
|
||||
return normalizeHost(urlOrHost) == normalizeHost(instance)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue