directives.go 1.03 KB
Newer Older
Mustafa Gezen's avatar
Mustafa Gezen committed
1
2
3
package directives

import (
4
	"encoding/json"
5
	"git.rockylinux.org/release-engineering/public/srpmproc/internal/data"
6
	srpmprocpb "git.rockylinux.org/release-engineering/public/srpmproc/pb"
Mustafa Gezen's avatar
Mustafa Gezen committed
7
	"github.com/go-git/go-git/v5"
8
9
	"log"
	"os"
Mustafa Gezen's avatar
Mustafa Gezen committed
10
11
12
13
14
15
16
17
18
19
20
21
22
	"path/filepath"
	"strings"
)

func checkAddPrefix(file string) string {
	if strings.HasPrefix(file, "SOURCES/") ||
		strings.HasPrefix(file, "SPECS/") {
		return file
	}

	return filepath.Join("SOURCES", file)
}

23
func Apply(cfg *srpmprocpb.Cfg, pd *data.ProcessData, md *data.ModeData, patchTree *git.Worktree, pushTree *git.Worktree) {
24
25
	var errs []string

26
27
28
29
30
31
32
	directives := []func(*srpmprocpb.Cfg, *data.ProcessData, *data.ModeData, *git.Worktree, *git.Worktree) error{
		replace,
		del,
		add,
		patch,
		lookaside,
		specChange,
33
34
	}

35
36
37
38
39
	for _, directive := range directives {
		err := directive(cfg, pd, md, patchTree, pushTree)
		if err != nil {
			errs = append(errs, err.Error())
		}
40
41
42
43
44
45
46
47
48
49
	}

	if len(errs) > 0 {
		err := json.NewEncoder(os.Stdout).Encode(errs)
		if err != nil {
			log.Fatal(errs)
		}

		os.Exit(1)
	}
Mustafa Gezen's avatar
Mustafa Gezen committed
50
}