-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmagicfuncs.go
83 lines (74 loc) · 2.06 KB
/
magicfuncs.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package git
import (
"context"
"github.com/pkg/errors"
"projectforge.dev/projectforge/app/project"
"projectforge.dev/projectforge/app/util"
)
type magicArgs struct {
Ctx context.Context //nolint:containedctx
Prj *project.Project
DryRun bool
Dirty int
Ahead int
Behind int
Branch string
Message string
Result *Result
Logger util.Logger
}
func (s *Service) magicCommit(a *magicArgs, add func(string, ...any)) error {
add("committing [%s] with message [%s]", util.StringPlural(a.Dirty, "file"), a.Message)
if !a.DryRun {
x, err := s.Commit(a.Ctx, a.Prj, a.Message, a.Logger)
if err != nil {
return errors.Wrap(err, "unable to commit")
}
a.Result.Data = x.Data.Merge(a.Result.Data)
}
return nil
}
func (s *Service) magicPull(a *magicArgs, add func(string, ...any)) error {
add("pulling [%s] from [%s]", util.StringPlural(a.Behind, "commit"), a.Branch)
if !a.DryRun {
x, err := s.Pull(a.Ctx, a.Prj, a.Logger)
if err != nil {
return errors.Wrap(err, "unable to pull")
}
a.Result.Data = x.Data.Merge(a.Result.Data)
}
return nil
}
func (s *Service) magicPush(a *magicArgs, count int, add func(string, ...any)) error {
add("pushing [%s] to [%s]", util.StringPlural(count, "commit"), a.Branch)
if !a.DryRun {
x, err := s.Push(a.Ctx, a.Prj, a.Logger)
if err != nil {
return errors.Wrap(err, "unable to push")
}
a.Result.Data = x.Data.Merge(a.Result.Data)
}
return nil
}
func (s *Service) magicStash(a *magicArgs, add func(string, ...any)) error {
add("stashing [%s]", util.StringPlural(a.Dirty, "file"))
if !a.DryRun {
_, err := s.gitStash(a.Ctx, a.Prj, a.Logger)
if err != nil {
return errors.Wrap(err, "unable to apply stash")
}
a.Result.Data["stash"] = "applied"
}
return nil
}
func (s *Service) magicStashPop(a *magicArgs, add func(string, ...any)) error {
add("restoring [%s] from stash", util.StringPlural(a.Dirty, "file"))
if !a.DryRun {
_, err := s.gitStashPop(a.Ctx, a.Prj, a.Logger)
if err != nil {
return errors.Wrap(err, "unable to pop stash")
}
a.Result.Data["stash"] = "popped"
}
return nil
}