Skip to content

Commit

Permalink
fix: clean up after pr is created
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Nov 14, 2023
1 parent fbd57f2 commit d21f3e3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/controller/fix_redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (c *Controller) fixRedirect(ctx context.Context, logE *logrus.Entry, pkg *P
return false, fmt.Errorf("update registry.yaml: %w", err)
}
defer func() {
if err := c.exec(ctx, "git", "checkout", "--", "registry.yaml"); err != nil {
if err := c.clean(ctx, redirect.NewPackageName); err != nil {
if e == nil {
e = err
}
Expand All @@ -48,6 +48,19 @@ func (c *Controller) fixRedirect(ctx context.Context, logE *logrus.Entry, pkg *P
return true, nil
}

func (c *Controller) clean(ctx context.Context, pkgName string) error {
if err := c.exec(ctx, "git", "checkout", "--", "."); err != nil {
return err
}
if err := c.fs.Remove(filepath.Join("pkgs", filepath.FromSlash(pkgName), "pkg.yaml")); err != nil {
return fmt.Errorf("remove new pkg.yaml: %w", err)
}
if err := c.fs.Remove(filepath.Join("pkgs", filepath.FromSlash(pkgName), "registry.yaml")); err != nil {
return fmt.Errorf("remove new registry.yaml: %w", err)
}
return nil
}

func (c *Controller) createFixRedirectPR(ctx context.Context, pkgName string, cfg *Config, redirect *checkrepo.Redirect) error {
paramTemplates := &ParamTemplates{
PackageName: pkgName,
Expand Down

0 comments on commit d21f3e3

Please sign in to comment.