Make sure scripts are valid when updating DB
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Elara 2022-12-01 11:08:20 -08:00
parent dd33a30c35
commit 8f9bdf69ad
1 changed files with 21 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import (
"github.com/go-git/go-billy/v5/osfs"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/format/diff"
"github.com/pelletier/go-toml/v2"
"go.arsenm.dev/logger/log"
"go.arsenm.dev/lure/distro"
@ -174,6 +175,11 @@ func processRepoChanges(ctx context.Context, repo types.Repo, r *git.Repository,
var actions []action
for _, fp := range patch.FilePatches() {
from, to := fp.Files()
if !isValid(from, to) {
continue
}
if to == nil {
actions = append(actions, action{
Type: actionDelete,
@ -274,6 +280,21 @@ func processRepoChanges(ctx context.Context, repo types.Repo, r *git.Repository,
return nil
}
// isValid makes sure the path of the file being updated is valid.
// It checks to make sure the file is not within a nested directory
// and that it is called lure.sh.
func isValid(from, to diff.File) bool {
var path string
if from != nil {
path = from.Path()
}
if to != nil {
path = to.Path()
}
return strings.Count(path, "/") == 1 && strings.HasSuffix(path, "lure.sh")
}
func processRepoFull(ctx context.Context, repo types.Repo, repoDir string, gdb *genji.DB) error {
glob := filepath.Join(repoDir, "/*/lure.sh")
matches, err := filepath.Glob(glob)