Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Jul 11, 2021
1 parent 2f725cb commit abf849e
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions routers/api/v1/repo/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,33 @@ func GetCommitStatusesByRef(ctx *context.APIContext) {
// "400":
// "$ref": "#/responses/error"

filter := ctx.Params("ref")
if len(filter) == 0 {
ctx.Error(http.StatusBadRequest, "ref not given", nil)
filter := ResolveRefOrSha(ctx, ctx.Params("ref"))
if ctx.Written() {
return
}

for _, reftype := range []string{"heads", "tags"} { //Search branches and tags
refSHA, lastMethodName, err := searchRefCommitByType(ctx, reftype, filter)
getCommitStatuses(ctx, filter) //By default filter is maybe the raw SHA
}

// ResolveRefOrSha resolve ref to sha if exist
func ResolveRefOrSha(ctx *context.APIContext, ref string) string {
if len(ref) == 0 {
ctx.Error(http.StatusBadRequest, "ref not given", nil)
return ""
}

// Search branches and tags
for _, refType := range []string{"heads", "tags"} {
refSHA, lastMethodName, err := searchRefCommitByType(ctx, refType, ref)
if err != nil {
ctx.Error(http.StatusInternalServerError, lastMethodName, err)
return
return ""
}
if refSHA != "" {
filter = refSHA
break
return refSHA
}

}

getCommitStatuses(ctx, filter) //By default filter is maybe the raw SHA
return ref
}

func searchRefCommitByType(ctx *context.APIContext, refType, filter string) (string, string, error) {
Expand Down Expand Up @@ -272,11 +279,11 @@ func GetCombinedCommitStatusByRef(ctx *context.APIContext) {
// "400":
// "$ref": "#/responses/error"

sha := ctx.Params("ref")
if len(sha) == 0 {
ctx.Error(http.StatusBadRequest, "ref/sha not given", nil)
sha := ResolveRefOrSha(ctx, ctx.Params("ref"))
if ctx.Written() {
return
}

repo := ctx.Repo.Repository

statuses, err := models.GetLatestCommitStatus(repo.ID, sha, utils.GetListOptions(ctx))
Expand Down

0 comments on commit abf849e

Please sign in to comment.