Name a repository in the facts as owner/repository, without the forge's address
mesh/merge-gate error: builds build-agent, mesh-controller, route-proxy → ace, g14, novox, shanks; no bus step; the check could not run: a throwaway postgr…
mesh/repo-check error: the check could not run: a throwaway postgres:17-alpine could not be raised: docker run --label mesh.build=build-1791331512096605198…
mesh/delivery superseded: a newer head of the same pull request
mesh/merge-gate error: builds build-agent, mesh-controller, route-proxy → ace, g14, novox, shanks; no bus step; the check could not run: a throwaway postgr…
mesh/repo-check error: the check could not run: a throwaway postgres:17-alpine could not be raised: docker run --label mesh.build=build-1791331512096605198…
mesh/delivery superseded: a newer head of the same pull request
The snapshot promises no address, and every module's repository, reads and sources carried the URL the mesh clones from. A check matches repositories by owner and name, so nothing it reads is lost (novox/hq issue 288).
This commit is contained in:
@@ -406,11 +406,11 @@ func gatherFacts(ctx context.Context, open *stores, busVersion string) (snapshot
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return snapshot.Facts{}, err
|
return snapshot.Facts{}, err
|
||||||
}
|
}
|
||||||
mod := snapshot.Module{Name: e.Manifest.Module, Repository: e.Source.Repository, Path: e.Source.Path,
|
mod := snapshot.Module{Name: e.Manifest.Module, Repository: snapshot.RepositoryName(e.Source.Repository), Path: e.Source.Path,
|
||||||
Commit: e.Source.BuiltFrom, Provided: e.Provided, RollOut: current[e.Manifest.Module].RollOut,
|
Commit: e.Source.BuiltFrom, Provided: e.Provided, RollOut: current[e.Manifest.Module].RollOut,
|
||||||
Manifest: raw}
|
Manifest: raw}
|
||||||
for _, r := range read[e.Manifest.Module] {
|
for _, r := range read[e.Manifest.Module] {
|
||||||
mod.Reads = append(mod.Reads, r.Repository)
|
mod.Reads = append(mod.Reads, snapshot.RepositoryName(r.Repository))
|
||||||
}
|
}
|
||||||
f.Modules = append(f.Modules, mod)
|
f.Modules = append(f.Modules, mod)
|
||||||
if e.Provided || e.Source.Repository == "" {
|
if e.Provided || e.Source.Repository == "" {
|
||||||
@@ -426,7 +426,8 @@ func gatherFacts(ctx context.Context, open *stores, busVersion string) (snapshot
|
|||||||
if commit == "" {
|
if commit == "" {
|
||||||
commit = s.BuiltFrom
|
commit = s.BuiltFrom
|
||||||
}
|
}
|
||||||
f.Sources = append(f.Sources, snapshot.Source{Repository: repository, Commit: commit, Modules: count[repository]})
|
f.Sources = append(f.Sources, snapshot.Source{Repository: snapshot.RepositoryName(repository), Commit: commit,
|
||||||
|
Modules: count[repository]})
|
||||||
}
|
}
|
||||||
for _, e := range edges {
|
for _, e := range edges {
|
||||||
f.Edges = append(f.Edges, snapshot.Edge{From: e.From, To: e.To, Kind: e.Kind})
|
f.Edges = append(f.Edges, snapshot.Edge{From: e.From, To: e.To, Kind: e.Kind})
|
||||||
|
|||||||
@@ -172,3 +172,18 @@ func TestAWithheldPathStaysAPath(t *testing.T) {
|
|||||||
t.Errorf("a key became %q", got)
|
t.Errorf("a key became %q", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// **Issue 288**: a repository was kept as the URL it was cloned from, the forge's address with it.
|
||||||
|
func TestARepositoryIsNamedWithoutTheForge(t *testing.T) {
|
||||||
|
for in, want := range map[string]string{
|
||||||
|
"http://forge.internal:3000/owner/repo.git": "owner/repo",
|
||||||
|
"ssh://git@forge.internal:222/owner/repo": "owner/repo",
|
||||||
|
"git@forge.internal:owner/repo.git": "owner/repo",
|
||||||
|
"owner/repo": "owner/repo",
|
||||||
|
"": "",
|
||||||
|
} {
|
||||||
|
if got := RepositoryName(in); got != want {
|
||||||
|
t.Errorf("%q is named %q, not %q", in, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -321,3 +321,31 @@ func standIn(run string) string {
|
|||||||
}
|
}
|
||||||
return run
|
return run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RepositoryName is a repository as `owner/repository`, without the forge's address it was cloned from:
|
||||||
|
// http://forge.internal:3000/owner/repo.git → owner/repo (novox/hq issue 288). What a check matches a
|
||||||
|
// pull request's repository by is its owner and name, never the forge's address, so nothing is lost.
|
||||||
|
func RepositoryName(repository string) string {
|
||||||
|
r := strings.TrimSuffix(strings.TrimSuffix(strings.TrimSpace(repository), "/"), ".git")
|
||||||
|
if r == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if _, rest, found := strings.Cut(r, "://"); found {
|
||||||
|
r = rest
|
||||||
|
if _, path, found := strings.Cut(r, "/"); found {
|
||||||
|
r = path
|
||||||
|
} else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
} else if at := strings.Index(r, "@"); at >= 0 {
|
||||||
|
// scp-like: git@forge:owner/repo
|
||||||
|
if _, path, found := strings.Cut(r[at+1:], ":"); found {
|
||||||
|
r = path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parts := strings.Split(strings.Trim(r, "/"), "/")
|
||||||
|
if len(parts) >= 2 {
|
||||||
|
return parts[len(parts)-2] + "/" + parts[len(parts)-1]
|
||||||
|
}
|
||||||
|
return parts[len(parts)-1]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user