Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdep: fix incorrect usage of strings TrimLeft #768

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tools/cdep/app/add_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func (a App) AddToConfig(path, branchName, commitHash string) (bool, error) {
if err != nil {
if v, ok := err.(*os.PathError); ok {
if v.Op != "open" {
return false, err
return false, fmt.Errorf("read file path error: %w", err)
}

return false, nil
}

return false, err
return false, fmt.Errorf("read file: %w", err)
}

if commitFreeze.Match(blob) && !commitRegAdd.Match(blob) {
Expand Down
26 changes: 13 additions & 13 deletions tools/cdep/app/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os/exec"
"path"
"regexp"
"strings"

"github.com/aws/aws-sdk-go/service/ecr"
"github.com/cuvva/cuvva-public-go/lib/cher"
Expand Down Expand Up @@ -39,7 +38,7 @@ func (a App) Update(ctx context.Context, req *parsers.Params, overruleChecks []s

repoPath, err := paths.GetConfigRepo()
if err != nil {
return err
return fmt.Errorf("path get config repo: %w", err)
}

log.Info("fetching config repo")
Expand All @@ -60,12 +59,12 @@ func (a App) Update(ctx context.Context, req *parsers.Params, overruleChecks []s

_, err = git.CheckRepo(configRepo)
if err != nil {
return err
return fmt.Errorf("config git check repo: %w", err)
}

ref, err := configRepo.Head()
if err != nil {
return err
return fmt.Errorf("config git head: %w", err)
}

defaultRef := fmt.Sprintf("refs/heads/%s", cdep.DefaultBranch)
Expand All @@ -82,13 +81,13 @@ func (a App) Update(ctx context.Context, req *parsers.Params, overruleChecks []s

wt, err := configRepo.Worktree()
if err != nil {
return err
return fmt.Errorf("config git work tree: %w", err)
}

err = git.CheckWorkingCopy(wt)
if err != nil {
if !slicecontains.String(overruleChecks, "working_copy_dirty") {
return err
return fmt.Errorf("config git check working copy: %w", err)
}

log.Warn("working_copy_dirty overruled")
Expand All @@ -100,7 +99,7 @@ func (a App) Update(ctx context.Context, req *parsers.Params, overruleChecks []s

envs, err := a.LoadEnvs(repoPath, req.System, req.Environment)
if err != nil {
return err
return fmt.Errorf("load envs: %w", err)
}

for env := range envs {
Expand All @@ -126,11 +125,12 @@ func (a App) Update(ctx context.Context, req *parsers.Params, overruleChecks []s

changed, err := a.AddToConfig(p, req.Branch, latestHash)
if err != nil {
return err
return fmt.Errorf("add to config: %w", err)
}

if changed {
shorthandPath := strings.TrimLeft(p, repoPath+"/")
filename := path.Base(p)
shorthandPath := path.Join(req.System, env, "service", filename)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug was here

updatedFiles = append(updatedFiles, shorthandPath)
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ func (a App) Update(ctx context.Context, req *parsers.Params, overruleChecks []s
commitMessage := fmt.Sprintf("cdep: %s", req.String("update"))

if err := a.PublishToSlack(ctx, req, commitMessage, updatedFiles, repoPath); err != nil {
return err
return fmt.Errorf("publish to slack: %w", err)
}

if a.DryRun {
Expand All @@ -177,20 +177,20 @@ func (a App) Update(ctx context.Context, req *parsers.Params, overruleChecks []s
log.Infof("adding %s to commit", p)
_, err := wt.Add(p)
if err != nil {
return err
return fmt.Errorf("config git add: %w", err)
}
}

_, err = wt.Commit(commitMessage, &gogit.CommitOptions{})
if err != nil {
return err
return fmt.Errorf("config git commit: %w", err)
}

log.Info("pushing commit to config repo")

if out, err := exec.CommandContext(ctx, "git", "-C", repoPath, "push", "origin", cdep.DefaultBranch).Output(); err != nil {
fmt.Println(string(out))
return err
return fmt.Errorf("config git push: %w", err)
}

return nil
Expand Down
Loading