with commit

This commit is contained in:
2022-09-12 12:35:10 +02:00
parent f78d84dc8f
commit 0212ce9df4
2 changed files with 87 additions and 4 deletions

View File

@@ -2,6 +2,11 @@ package commands
import (
"context"
"fmt"
"io/fs"
"os"
"path"
"path/filepath"
"sync"
"time"
@@ -66,7 +71,7 @@ func (pr *ProcessRepos) Process(ctx context.Context, repositoryUrls []string) er
pr.logger.Debug("Cloning repo", zap.String("path", area.Path), zap.String("repoUrl", repoUrl))
cloneCtx, _ := context.WithTimeout(ctx, time.Second*5)
_, err = pr.git.Clone(cloneCtx, area, repoUrl)
repo, err := pr.git.Clone(cloneCtx, area, repoUrl)
if err != nil {
pr.logger.Error("could not clone repo", zap.Error(err))
errChan <- err
@@ -76,12 +81,39 @@ func (pr *ProcessRepos) Process(ctx context.Context, repositoryUrls []string) er
err = pr.action.Run(
ctx,
area,
func(ctx context.Context, area *storage.Area) (bool, error) {
func(_ context.Context, area *storage.Area) (bool, error) {
pr.logger.Debug("checking predicate", zap.String("area", area.Path))
return true, nil
contains := false
filepath.WalkDir(area.Path, func(path string, d fs.DirEntry, err error) error {
if d.Name() == "roadmap.md" {
contains = true
}
return nil
})
return contains, nil
},
func(ctx context.Context, area *storage.Area) error {
func(_ context.Context, area *storage.Area) error {
pr.logger.Debug("running action", zap.String("area", area.Path))
readme := path.Join(area.Path, "README.md")
file, err := os.Create(readme)
if err != nil {
return fmt.Errorf("could not create readme: %w", err)
}
_, err = file.WriteString("# Readme")
if err != nil {
return fmt.Errorf("could not write readme: %w", err)
}
_, err = pr.git.Add(ctx, area, repo)
if err != nil {
return fmt.Errorf("could not add file: %w", err)
}
_, err = pr.git.Commit(ctx, repo)
if err != nil {
return fmt.Errorf("could not get diff: %w", err)
}
return nil
}, false)