github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/lib/repository/helpers.go (about)

     1  package repositoryLib
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path"
     7  	"strings"
     8  
     9  	loginLib "github.com/taubyte/tau-cli/lib/login"
    10  	"github.com/taubyte/tau-cli/singletons/config"
    11  )
    12  
    13  func (info *Info) isCloned(repositoryPath string) bool {
    14  	_, err := os.Stat(repositoryPath)
    15  
    16  	return err == nil
    17  }
    18  
    19  // Get the repository path from info provided
    20  func (info *Info) path(project config.Project) (string, error) {
    21  	// Check to confirm full name is valid
    22  	if len(info.FullName) == 0 {
    23  		if len(info.ID) > 0 {
    24  			err := info.GetNameFromID()
    25  			if err != nil {
    26  				return "", err
    27  			}
    28  		} else {
    29  			return "", fmt.Errorf("repository fullname or ID not provided for type %s", info.Type)
    30  		}
    31  	}
    32  
    33  	// Confirm fullName is valid
    34  	splitName := strings.Split(info.FullName, "/")
    35  	if len(splitName) == 1 {
    36  		profile, err := loginLib.GetSelectedProfile()
    37  		if err != nil {
    38  			return "", err
    39  		}
    40  
    41  		// Create a full name with username and repo name
    42  		info.FullName = strings.Join([]string{profile.GitUsername, splitName[0]}, "/")
    43  	}
    44  
    45  	var loc string
    46  	switch info.Type {
    47  	case WebsiteRepositoryType:
    48  		loc = project.WebsiteLoc()
    49  	case LibraryRepositoryType:
    50  		loc = project.LibraryLoc()
    51  	}
    52  
    53  	return path.Join(loc, strings.Split(info.FullName, "/")[1]), nil
    54  }