generated from kyma-project/template-repository
/
commitchanges.go
51 lines (42 loc) · 1.1 KB
/
commitchanges.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
package git
import (
"github.com/kyma-project/serverless/tests/serverless/internal/executor"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
const (
filePath = "handler.js"
oldValue = "GITOPS 1"
newValue = "GITOPS 2"
)
type commitChanges struct {
name string
gitClient Client
log *logrus.Entry
}
var _ executor.Step = commitChanges{}
func NewCommitChanges(log *logrus.Entry, stepName, repoURL string) executor.Step {
return commitChanges{
name: stepName,
gitClient: NewGitClient(repoURL),
log: log.WithField(executor.LogStepKey, stepName),
}
}
func (c commitChanges) Name() string {
return c.name
}
func (c commitChanges) Run() error {
err := c.gitClient.ReplaceInRemoteFile(filePath, oldValue, newValue)
return errors.Wrap(err, "while replacing file content in git repository")
}
func (c commitChanges) OnError() error {
out, err := c.gitClient.PullRemote(filePath)
if err != nil {
return errors.Wrap(err, "while pulling from remote repository")
}
c.log.Infof("Code from git repository: %s", out)
return nil
}
func (c commitChanges) Cleanup() error {
return nil
}