Skip to content

Commit

Permalink
s/GitRepositoryInfo/RepositoryInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
denik committed Dec 4, 2024
1 parent 2d3ee18 commit a689396
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions internal/git_fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ import (
const examplesRepoUrl = "https://github.com/databricks/bundle-examples"
const examplesRepoProvider = "gitHub"

func assertFullGitInfo(t *testing.T, expectedRoot string, info git.GitRepositoryInfo) {
func assertFullGitInfo(t *testing.T, expectedRoot string, info git.RepositoryInfo) {
assert.Equal(t, "main", info.CurrentBranch)
assert.NotEmpty(t, info.LatestCommit)
assert.Equal(t, examplesRepoUrl, info.OriginURL)
assert.Equal(t, expectedRoot, info.WorktreeRoot)
}

func assertEmptyGitInfo(t *testing.T, info git.GitRepositoryInfo) {
func assertEmptyGitInfo(t *testing.T, info git.RepositoryInfo) {
assertSparseGitInfo(t, "", info)
}

func assertSparseGitInfo(t *testing.T, expectedRoot string, info git.GitRepositoryInfo) {
func assertSparseGitInfo(t *testing.T, expectedRoot string, info git.RepositoryInfo) {
assert.Equal(t, "", info.CurrentBranch)
assert.Equal(t, "", info.LatestCommit)
assert.Equal(t, "", info.OriginURL)
Expand Down
18 changes: 9 additions & 9 deletions libs/git/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/databricks/databricks-sdk-go/client"
)

type GitRepositoryInfo struct {
type RepositoryInfo struct {
// Various metadata about the repo. Each could be "" if it could not be read. No error is returned for such case.
OriginURL string
LatestCommit string
Expand All @@ -39,22 +39,22 @@ type response struct {
}

// Fetch repository information either by quering .git or by fetching it from API (for dabs-in-workspace case).
// - In case we could not find git repository, all string fields of GitRepositoryInfo will be "" and err will be nil.
// - In case we could not find git repository, all string fields of RepositoryInfo will be "" and err will be nil.
// - If there were any errors when trying to determine git root (e.g. API call returned an error or there were permission issues
// reading the file system), all strings fields of GitRepositoryInfo will be "" and err will be non-nil.
// reading the file system), all strings fields of RepositoryInfo will be "" and err will be non-nil.
// - If we could determine git worktree root but there were errors when reading metadata (origin, branch, commit), those errors
// will be logged as warnings, GitRepositoryInfo is guaranteed to have non-empty WorktreeRoot and other fields on best effort basis.
// will be logged as warnings, RepositoryInfo is guaranteed to have non-empty WorktreeRoot and other fields on best effort basis.
// - In successful case, all fields are set to proper git repository metadata.
func FetchRepositoryInfo(ctx context.Context, path string, w *databricks.WorkspaceClient) (GitRepositoryInfo, error) {
func FetchRepositoryInfo(ctx context.Context, path string, w *databricks.WorkspaceClient) (RepositoryInfo, error) {
if strings.HasPrefix(path, "/Workspace/") && dbr.RunsOnRuntime(ctx) {
return fetchRepositoryInfoAPI(ctx, path, w)
} else {
return fetchRepositoryInfoDotGit(ctx, path)
}
}

func fetchRepositoryInfoAPI(ctx context.Context, path string, w *databricks.WorkspaceClient) (GitRepositoryInfo, error) {
result := GitRepositoryInfo{}
func fetchRepositoryInfoAPI(ctx context.Context, path string, w *databricks.WorkspaceClient) (RepositoryInfo, error) {
result := RepositoryInfo{}

apiClient, err := client.New(w.Config)
if err != nil {
Expand Down Expand Up @@ -102,8 +102,8 @@ func ensureWorkspacePrefix(p string) string {
return p
}

func fetchRepositoryInfoDotGit(ctx context.Context, path string) (GitRepositoryInfo, error) {
result := GitRepositoryInfo{}
func fetchRepositoryInfoDotGit(ctx context.Context, path string) (RepositoryInfo, error) {
result := RepositoryInfo{}

rootDir, err := findLeafInTree(path, GitDirectoryName)
if rootDir == "" {
Expand Down

0 comments on commit a689396

Please sign in to comment.