This commit is contained in:
2022-09-18 00:10:30 +02:00
parent eef25c4c7a
commit 88430eb879
4 changed files with 98 additions and 17 deletions

View File

@@ -122,8 +122,6 @@ func (pr *ProcessRepos) processRepo(ctx context.Context, repoUrl string, action
return err
}
//pr.gitea.CreatePr(ctx, )
pr.logger.Debug("processing done", zap.String("path", area.Path), zap.String("repoUrl", repoUrl))
return nil
}
@@ -165,7 +163,7 @@ func (pr *ProcessRepos) clone(ctx context.Context, area *storage.Area, repoUrl s
}
func (pr *ProcessRepos) commit(ctx context.Context, area *storage.Area, repo *providers.GitRepo, repoUrl string) error {
_, err := pr.git.Add(ctx, area, repo)
wt, err := pr.git.Add(ctx, area, repo)
if err != nil {
return fmt.Errorf("could not add file: %w", err)
}
@@ -175,8 +173,18 @@ func (pr *ProcessRepos) commit(ctx context.Context, area *storage.Area, repo *pr
return fmt.Errorf("could not get diff: %w", err)
}
dryrun := true
dryrun := false
if !dryrun {
status, err := wt.Status()
if err != nil {
return err
}
if status.IsClean() {
pr.logger.Info("Returning early, as no modifications are detected")
return nil
}
err = pr.git.Push(ctx, repo)
if err != nil {
return fmt.Errorf("could not push to repo: %w", err)
@@ -195,7 +203,22 @@ func (pr *ProcessRepos) commit(ctx context.Context, area *storage.Area, repo *pr
path := strings.Split(url.Path, "/")
pr.logger.Debug("path string", zap.Strings("paths", path), zap.String("HEAD", head))
pr.gitea.CreatePr(ctx, url.Host, path[0], repoUrl, head, "", "kraken-apply")
org := path[0]
repoName := path[1]
semanticName, _, ok := strings.Cut(repoName, ".")
if !ok {
semanticName = repoName
}
originHead, err := pr.git.GetOriginHEADForRepo(ctx, repo)
if err != nil {
return err
}
err = pr.gitea.CreatePr(ctx, fmt.Sprintf("%s://%s", "https", url.Host), org, semanticName, head, originHead, "kraken-apply")
if err != nil {
return err
}
}
return nil
}