@@ -67,7 +67,7 @@ func (label *Label) APIFormat() *api.Label {
67
67
return & api.Label {
68
68
ID : label .ID ,
69
69
Name : label .Name ,
70
- Color : label .Color ,
70
+ Color : strings . TrimLeft ( label .Color , "#" ) ,
71
71
}
72
72
}
73
73
@@ -102,6 +102,27 @@ func NewLabels(labels ...*Label) error {
102
102
return err
103
103
}
104
104
105
+ // getLabelInRepoByName returns a label by Name in given repository.
106
+ // If pass repoID as 0, then ORM will ignore limitation of repository
107
+ // and can return arbitrary label with any valid ID.
108
+ func getLabelInRepoByName (e Engine , repoID int64 , labelName string ) (* Label , error ) {
109
+ if len (labelName ) <= 0 {
110
+ return nil , ErrLabelNotExist {0 , repoID }
111
+ }
112
+
113
+ l := & Label {
114
+ Name : labelName ,
115
+ RepoID : repoID ,
116
+ }
117
+ has , err := x .Get (l )
118
+ if err != nil {
119
+ return nil , err
120
+ } else if ! has {
121
+ return nil , ErrLabelNotExist {0 , l .RepoID }
122
+ }
123
+ return l , nil
124
+ }
125
+
105
126
// getLabelInRepoByID returns a label by ID in given repository.
106
127
// If pass repoID as 0, then ORM will ignore limitation of repository
107
128
// and can return arbitrary label with any valid ID.
@@ -128,6 +149,11 @@ func GetLabelByID(id int64) (*Label, error) {
128
149
return getLabelInRepoByID (x , 0 , id )
129
150
}
130
151
152
+ // GetLabelInRepoByID returns a label by ID in given repository.
153
+ func GetLabelInRepoByName (repoID int64 , labelName string ) (* Label , error ) {
154
+ return getLabelInRepoByName (x , repoID , labelName )
155
+ }
156
+
131
157
// GetLabelInRepoByID returns a label by ID in given repository.
132
158
func GetLabelInRepoByID (repoID , labelID int64 ) (* Label , error ) {
133
159
return getLabelInRepoByID (x , repoID , labelID )
0 commit comments