-
Notifications
You must be signed in to change notification settings - Fork 4
/
magicargs.go
36 lines (27 loc) · 1013 Bytes
/
magicargs.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
package git
import (
"context"
"github.com/pkg/errors"
"projectforge.dev/projectforge/app/project"
"projectforge.dev/projectforge/app/util"
)
func (s *Service) magicArgsFor(ctx context.Context, prj *project.Project, message string, dryRun bool, logger util.Logger) (*magicArgs, error) {
statRet, err := s.Status(ctx, prj, logger)
if err != nil {
return nil, errors.Wrapf(err, "unable to get status for project [%s]", prj.Key)
}
branch := statRet.DataString("branch")
data := util.ValueMap{"branch": branch, "magic": true, "commitMessage": message}
dirty := statRet.DataStringArray("dirty")
dirtyCount := len(dirty)
if len(dirty) > 0 {
data["dirtyCount"] = dirtyCount
}
ahead := statRet.DataInt("commitsAhead")
behind := statRet.DataInt("commitsBehind")
ret := NewResult(prj, "no changes needed", data)
return &magicArgs{
Ctx: ctx, Prj: prj, DryRun: dryRun, Dirty: dirtyCount, Ahead: ahead, Behind: behind,
Branch: branch, Message: message, Result: ret, Logger: logger,
}, nil
}