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") }