Files
mesh-sdk/go/delivery/trunk.go
T
jschoubben 84a7643723
mesh/repo-check head 84a764372337 merged into trunk 8360a3bba2b4 — pass: its merge-check.sh passed, each part in its toolchain: merge-check.sh (typescript)…
mesh/merge-gate head 84a764372337 merged into trunk 8360a3bba2b4 — pass: group fix/1281-trunk-builds-by-repository composed: every machine composes with th…
mesh/delivery delivered
mesh/delivery-group group fix/1281-trunk-builds-by-repository delivered: every member is delivered
Add the repository-identity and trunk-build tests both delivery readers need (issue 1281)
A build record names its repository by clone URL and a plan-asked build carries no ref; the indexer and view compared both naively.
2026-10-19 22:39:25 +02:00

33 lines
1.5 KiB
Go

package delivery
import "strings"
// RepositoryName is the repository as the forge names it, "owner/name", from either spelling the mesh holds: the name
// itself, or the clone URL a build record carries ("http://host:port/owner/name.git", with or without ".git" or a
// trailing slash). A string of fewer than two path segments is returned as it is, trimmed (issue 1281).
func RepositoryName(s string) string {
s = strings.TrimSpace(s)
s = strings.TrimRight(s, "/")
s = strings.TrimSuffix(s, ".git")
s = strings.TrimRight(s, "/")
parts := strings.FieldsFunc(s, func(r rune) bool { return r == '/' || r == ':' })
if len(parts) < 2 {
return s
}
return parts[len(parts)-2] + "/" + parts[len(parts)-1]
}
// SameRepository is whether two spellings name one repository: the same owner and name, whichever way each is written
// (RepositoryName), compared without regard to case as the forge does. An empty spelling names none (issue 1281).
func SameRepository(a, b string) bool {
a, b = RepositoryName(a), RepositoryName(b)
return a != "" && strings.EqualFold(a, b)
}
// IsTrunkBuild is whether the record is a successful build of the trunk that recorded its source inputs: state built, and
// ref "main" or none. A build a delivery plan asked after a merge, or rebuild or build --behind, follows the branch
// without naming it, so it carries no ref; a build of any other branch or of a commit names it (issue 1281).
func (r BuildRecord) IsTrunkBuild() bool {
return r.State == "built" && r.SourceInputs != nil && (r.Ref == "" || r.Ref == "main")
}