Files
Ant-Browser/backend/automation_script_import_labels.go
ant-black 70132417ad publish: 1.2.0 snapshot (f3d7ec5)
channel: master

version: 1.2.0

source-ref: D:\code\open_source\ant-chrome master

source-commit: f3d7ec5

merged-public-base: 3d264eb
2026-05-05 18:08:10 +08:00

43 lines
1.1 KiB
Go

package backend
import (
"strings"
"ant-chrome/backend/internal/automation"
)
func buildAutomationImportSourceLabel(source automation.ScriptSource) string {
switch strings.TrimSpace(source.Type) {
case "local-file":
return "本地文件 " + firstNonBlank(source.URI, source.Path)
case "local-dir":
return "本地目录 " + firstNonBlank(source.URI, source.Path)
case "remote-url":
return "远程地址 " + strings.TrimSpace(source.URI)
case "git":
return buildAutomationGitImportLabel(source.URI, source.Ref, source.Path)
default:
return firstNonBlank(source.URI, source.Path)
}
}
func buildAutomationGitImportLabel(repoURL string, ref string, scriptPath string) string {
label := "Git " + strings.TrimSpace(repoURL)
if strings.TrimSpace(ref) != "" {
label += " @ " + strings.TrimSpace(ref)
}
if strings.TrimSpace(scriptPath) != "" {
label += " : " + strings.TrimSpace(scriptPath)
}
return label
}
func firstNonBlank(values ...string) string {
for _, value := range values {
if trimmed := strings.TrimSpace(value); trimmed != "" {
return trimmed
}
}
return ""
}