Welcome to mirror list, hosted at ThFree Co, Russian Federation.

utils.go « operations « service « gitaly « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2052c9b3d97b4678e77df1afaf9f78bb2d237477 (plain)
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
package operations

import (
	"fmt"
	"time"

	"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
	"google.golang.org/protobuf/types/known/timestamppb"
)

type cherryPickOrRevertRequest interface {
	GetUser() *gitalypb.User
	GetCommit() *gitalypb.GitCommit
	GetBranchName() []byte
	GetMessage() []byte
}

func validateCherryPickOrRevertRequest(req cherryPickOrRevertRequest) error {
	if req.GetUser() == nil {
		return fmt.Errorf("empty User")
	}

	if req.GetCommit() == nil {
		return fmt.Errorf("empty Commit")
	}

	if len(req.GetBranchName()) == 0 {
		return fmt.Errorf("empty BranchName")
	}

	if len(req.GetMessage()) == 0 {
		return fmt.Errorf("empty Message")
	}

	return nil
}

type userTimestampProto interface {
	GetUser() *gitalypb.User
	GetTimestamp() *timestamppb.Timestamp
}

func dateFromProto(p userTimestampProto) (time.Time, error) {
	date := time.Now()

	if timestamp := p.GetTimestamp(); timestamp != nil {
		date = timestamp.AsTime()
	}

	if user := p.GetUser(); user != nil {
		location, err := time.LoadLocation(user.GetTimezone())
		if err != nil {
			return time.Time{}, err
		}
		date = date.In(location)
	}

	return date, nil
}