refactor(repo): extract mirrorCloneURL helper · Entire

refactor(repo): extract mirrorCloneURL helper

5270dbf→main·

toothbrush·2w ago·3 files·+18 added/-3 removed

De-duplicate the entire:///gh// synthesis shared by mirrorRow and repo clone, and build it from entireCloneURLScheme rather than a bare literal.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Sessions

6121cc05be7eView transcript

[?
Add Entire Repo Clone CommandClaude Code·1 step](/content/gh/entireio/cli/session/e77355db-5c1c-4286-94f0-431cf4b77954#timeline-6121cc05be7e/index.html)

Changes

3

30 unmodified lines

31
32
33
34
34
35
36
37
2 unmodified lines

40
41
42
43
44
45
46
47
48
49
50
51
52
53
97 unmodified lines

151
152
153
146
154
155
156
157

30 unmodified lines

// entireCloneURLScheme is the scheme of a full mirror clone URL, which
// git-remote-entire resolves directly. Such a URL already names the cluster, so
// `entire clone` passes it through to `git clone` untouched.
// `repo clone` passes it through to `git clone` untouched.
const entireCloneURLScheme = "entire://"

// isEntireCloneURL reports whether ref is a full entire:// clone URL (vs. the
2 unmodified lines

return strings.HasPrefix(strings.TrimSpace(ref), entireCloneURLScheme)
}

// mirrorCloneURL synthesizes the entire:// clone URL for a GitHub mirror from
// its cluster host and owner/repo — the form `git clone` accepts, which the
// mirror list API doesn't return. Shared by the mirror table view (mirrorRow)
// and `repo clone` so the wire format lives in one place.
func mirrorCloneURL(host, owner, repo string) string {
    return fmt.Sprintf("%s%s/gh/%s/%s", entireCloneURLScheme, host, owner, repo)
}

// parseMirrorCloneRef turns a clone ref like `/gh/entirehq/entire-api` into the
// API provider ("github") and the lowercased owner/repo. The `gh` token is the
// path provider used in entire:// clone URLs; it maps to the "github" upstream
97 unmodified lines

if err := validateClusterHost(chosen.ClusterHost); err != nil {
            return fmt.Errorf("mirror has an invalid cluster host %q: %w", chosen.ClusterHost, err)
        }
        cloneURL := fmt.Sprintf("entire://%s/gh/%s/%s", chosen.ClusterHost, owner, repo)
        cloneURL := mirrorCloneURL(chosen.ClusterHost, owner, repo)
        return runGitClone(cmd.Context(), cmd, cloneURL, targetDir)
    },
}

Mcmd/entire/cli/repo_clone.go+10/-2

65 unmodified lines

66
67
68
69
70
71
72
73
74
75
76
77
78

65 unmodified lines

}

func TestMirrorCloneURL(t *testing.T) {
    t.Parallel()
    require.Equal(t,
        "entire://aws-us-east-2.entire.io/gh/entirehq/entire-api",
        mirrorCloneURL("aws-us-east-2.entire.io", "entirehq", "entire-api"))
}

func TestMirrorCellLabel(t *testing.T) {
    t.Parallel()
    tests := []struct {