directives.go 987 Bytes
Newer Older
Mustafa Gezen's avatar
Mustafa Gezen committed
1
2
3
package directives

import (
4
5
	"encoding/json"
	srpmprocpb "git.rockylinux.org/release-engineering/public/srpmproc/pb"
Mustafa Gezen's avatar
Mustafa Gezen committed
6
	"github.com/go-git/go-git/v5"
7
8
	"log"
	"os"
Mustafa Gezen's avatar
Mustafa Gezen committed
9
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)
}

func Apply(cfg *srpmprocpb.Cfg, patchTree *git.Worktree, pushTree *git.Worktree) {
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
	var errs []string

	err := replace(cfg, patchTree, pushTree)
	if err != nil {
		errs = append(errs, err.Error())
	}

	err = del(cfg, patchTree, pushTree)
	if err != nil {
		errs = append(errs, err.Error())
	}

	err = add(cfg, patchTree, pushTree)
	if err != nil {
		errs = append(errs, err.Error())
	}

	err = patch(cfg, patchTree, pushTree)
	if err != nil {
		errs = append(errs, err.Error())
	}

	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
53
}