Remove resolution of repo names against the Databricks Github account (#940)

## Changes
This functionality is not exercised (and will not be anytime soon).
Instead we use a map to have first party aliases for supported
templates.


1e46b9f88a/cmd/bundle/init.go (L21)

## Tests
Existing tests and manually, bundle init still works.
This commit is contained in:
shreyas-goenka 2023-11-01 14:02:06 +01:00 committed by GitHub
parent 1e46b9f88a
commit d70d7445c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 19 deletions

View File

@ -32,14 +32,14 @@ func TestAccGitClone(t *testing.T) {
assert.Contains(t, string(b), "ide") assert.Contains(t, string(b), "ide")
} }
func TestAccGitCloneWithOnlyRepoNameOnAlternateBranch(t *testing.T) { func TestAccGitCloneOnNonDefaultBranch(t *testing.T) {
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV")) t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
tmpDir := t.TempDir() tmpDir := t.TempDir()
ctx := context.Background() ctx := context.Background()
var err error var err error
err = git.Clone(ctx, "notebook-best-practices", "dais-2022", tmpDir) err = git.Clone(ctx, "https://github.com/databricks/notebook-best-practices", "dais-2022", tmpDir)
// assert on repo content // assert on repo content
assert.NoError(t, err) assert.NoError(t, err)
@ -47,7 +47,7 @@ func TestAccGitCloneWithOnlyRepoNameOnAlternateBranch(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, string(b), "Software engineering best practices for Databricks notebooks") assert.Contains(t, string(b), "Software engineering best practices for Databricks notebooks")
// assert current branch is main, ie default for the repo // assert current branch is dais-2022
b, err = os.ReadFile(filepath.Join(tmpDir, ".git/HEAD")) b, err = os.ReadFile(filepath.Join(tmpDir, ".git/HEAD"))
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, string(b), "dais-2022") assert.Contains(t, string(b), "dais-2022")

View File

@ -5,18 +5,11 @@ import (
"errors" "errors"
"fmt" "fmt"
"os/exec" "os/exec"
"regexp"
"strings" "strings"
"github.com/databricks/cli/libs/process" "github.com/databricks/cli/libs/process"
) )
// source: https://stackoverflow.com/questions/59081778/rules-for-special-characters-in-github-repository-name
var githubRepoRegex = regexp.MustCompile(`^[\w-\.]+$`)
const githubUrl = "https://github.com"
const databricksOrg = "databricks"
type cloneOptions struct { type cloneOptions struct {
// Branch or tag to clone // Branch or tag to clone
Reference string Reference string
@ -59,17 +52,9 @@ func (opts cloneOptions) clone(ctx context.Context) error {
} }
func Clone(ctx context.Context, url, reference, targetPath string) error { func Clone(ctx context.Context, url, reference, targetPath string) error {
// We assume only the repository name has been if input does not contain any
// `/` characters and the url is only made up of alphanumeric characters and
// ".", "_" and "-". This repository is resolved again databricks github account.
fullUrl := url
if githubRepoRegex.MatchString(url) {
fullUrl = strings.Join([]string{githubUrl, databricksOrg, url}, "/")
}
opts := cloneOptions{ opts := cloneOptions{
Reference: reference, Reference: reference,
RepositoryUrl: fullUrl, RepositoryUrl: url,
TargetPath: targetPath, TargetPath: targetPath,
Shallow: true, Shallow: true,
} }