@@ -171,26 +171,33 @@ func GetCommitStatusesByRef(ctx *context.APIContext) {
171
171
// "400":
172
172
// "$ref": "#/responses/error"
173
173
174
- filter := ctx .Params ("ref" )
175
- if len (filter ) == 0 {
176
- ctx .Error (http .StatusBadRequest , "ref not given" , nil )
174
+ filter := ResolveRefOrSha (ctx , ctx .Params ("ref" ))
175
+ if ctx .Written () {
177
176
return
178
177
}
179
178
180
- for _ , reftype := range []string {"heads" , "tags" } { //Search branches and tags
181
- refSHA , lastMethodName , err := searchRefCommitByType (ctx , reftype , filter )
179
+ getCommitStatuses (ctx , filter ) //By default filter is maybe the raw SHA
180
+ }
181
+
182
+ // ResolveRefOrSha resolve ref to sha if exist
183
+ func ResolveRefOrSha (ctx * context.APIContext , ref string ) string {
184
+ if len (ref ) == 0 {
185
+ ctx .Error (http .StatusBadRequest , "ref not given" , nil )
186
+ return ""
187
+ }
188
+
189
+ // Search branches and tags
190
+ for _ , refType := range []string {"heads" , "tags" } {
191
+ refSHA , lastMethodName , err := searchRefCommitByType (ctx , refType , ref )
182
192
if err != nil {
183
193
ctx .Error (http .StatusInternalServerError , lastMethodName , err )
184
- return
194
+ return ""
185
195
}
186
196
if refSHA != "" {
187
- filter = refSHA
188
- break
197
+ return refSHA
189
198
}
190
-
191
199
}
192
-
193
- getCommitStatuses (ctx , filter ) //By default filter is maybe the raw SHA
200
+ return ref
194
201
}
195
202
196
203
func searchRefCommitByType (ctx * context.APIContext , refType , filter string ) (string , string , error ) {
@@ -272,11 +279,11 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
272
279
// "400":
273
280
// "$ref": "#/responses/error"
274
281
275
- sha := ctx .Params ("ref" )
276
- if len (sha ) == 0 {
277
- ctx .Error (http .StatusBadRequest , "ref/sha not given" , nil )
282
+ sha := ResolveRefOrSha (ctx , ctx .Params ("ref" ))
283
+ if ctx .Written () {
278
284
return
279
285
}
286
+
280
287
repo := ctx .Repo .Repository
281
288
282
289
statuses , err := models .GetLatestCommitStatus (repo .ID , sha , utils .GetListOptions (ctx ))
0 commit comments