fixup to get working code
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"io"
|
||||
stdslog "log/slog"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
@@ -231,12 +232,20 @@ func main() {
|
||||
cfg.Branches = append(cfg.Branches, branchName)
|
||||
}
|
||||
|
||||
if cfg.Source.Repository == "" {
|
||||
reposiotry, err := getCurrentRepository(ctx)
|
||||
if cfg.Source.Owner == "" {
|
||||
owner, err := getOwnerRepository(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(ctx, "failed to get current repository", err)
|
||||
}
|
||||
cfg.Source.Repository = reposiotry
|
||||
cfg.Source.Owner = owner
|
||||
}
|
||||
|
||||
if cfg.Source.Repository == "" {
|
||||
repository, err := getCurrentRepository(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(ctx, "failed to get current repository", err)
|
||||
}
|
||||
cfg.Source.Repository = repository
|
||||
}
|
||||
|
||||
gitSource := source.NewSourceControl(*cfg, log)
|
||||
@@ -357,7 +366,44 @@ func getCurrentRepository(ctx context.Context) (string, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
return v.URLs[0], nil
|
||||
u, err := url.Parse(v.URLs[0])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
return filepath.Base(u.Path), nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("failed to get remotes")
|
||||
}
|
||||
|
||||
func getOwnerRepository(ctx context.Context) (string, error) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
p := filepath.Clean(wd)
|
||||
|
||||
repo, err := git.PlainOpen(p)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
cfg, err := repo.Config()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for k, v := range cfg.Remotes {
|
||||
if k != "origin" {
|
||||
continue
|
||||
}
|
||||
|
||||
u, err := url.Parse(v.URLs[0])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
return filepath.Base(filepath.Dir(u.Path)), nil
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("failed to get remotes")
|
||||
@@ -425,9 +471,6 @@ func getRepoMgmt(ctx context.Context, log logger.Logger, cfg *configcli.Config)
|
||||
}
|
||||
|
||||
log.Info(ctx, "try to configure scm for "+cfg.Source.APIURL)
|
||||
if cfg.Source.Owner == "" {
|
||||
cfg.Source.Owner = n.Machine(cfg.Source.APIURL).Get("login")
|
||||
}
|
||||
if cfg.Source.Username == "" {
|
||||
cfg.Source.Username = n.Machine(cfg.Source.APIURL).Get("login")
|
||||
}
|
||||
|
Reference in New Issue
Block a user