This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
/
repo_label.go
64 lines (52 loc) · 1.51 KB
/
repo_label.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
// Copyright 2018 The OpenPitrix Authors. All rights reserved.
// Use of this source code is governed by a Apache license
// that can be found in the LICENSE file.
package models
import (
"time"
"openpitrix.io/openpitrix/pkg/db"
"openpitrix.io/openpitrix/pkg/pb"
"openpitrix.io/openpitrix/pkg/util/idutil"
"openpitrix.io/openpitrix/pkg/util/pbutil"
)
func NewRepoLabelId() string {
return idutil.GetUuid("repol-")
}
type RepoLabel struct {
RepoLabelId string
RepoId string
LabelKey string
LabelValue string
CreateTime time.Time
}
var RepoLabelColumns = db.GetColumnsFromStruct(&RepoLabel{})
func NewRepoLabel(repoId, labelKey, labelValue string) *RepoLabel {
return &RepoLabel{
RepoLabelId: NewRepoLabelId(),
RepoId: repoId,
LabelKey: labelKey,
LabelValue: labelValue,
CreateTime: time.Now(),
}
}
func RepoLabelToPb(repoLabel *RepoLabel) *pb.RepoLabel {
return &pb.RepoLabel{
LabelKey: pbutil.ToProtoString(repoLabel.LabelKey),
LabelValue: pbutil.ToProtoString(repoLabel.LabelValue),
CreateTime: pbutil.ToProtoTimestamp(repoLabel.CreateTime),
}
}
func RepoLabelsToPbs(repoLabels []*RepoLabel) (pbRepoLabels []*pb.RepoLabel) {
for _, repoLabel := range repoLabels {
pbRepoLabels = append(pbRepoLabels, RepoLabelToPb(repoLabel))
}
return
}
func RepoLabelsMap(repoLabels []*RepoLabel) map[string][]*RepoLabel {
labelsMap := make(map[string][]*RepoLabel)
for _, l := range repoLabels {
repoId := l.RepoId
labelsMap[repoId] = append(labelsMap[repoId], l)
}
return labelsMap
}