summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/status.go
diff options
context:
space:
mode:
authorAntoine GIRARD <sapk@users.noreply.github.com>2019-08-09 04:13:03 +0200
committerLunny Xiao <xiaolunwen@gmail.com>2019-08-09 10:13:03 +0800
commit2b6f45299d6e96b633a309d68055f9ae0699b8f2 (patch)
tree85ebd068cafb64fdd987b36541a9e743f0744f4c /routers/api/v1/repo/status.go
parentc534b7e211d3264bbbde9b95cd8d6e9e60ad4215 (diff)
downloadgitea-2b6f45299d6e96b633a309d68055f9ae0699b8f2.tar.gz
gitea-2b6f45299d6e96b633a309d68055f9ae0699b8f2.zip
api: fix multiple bugs with statuses endpoints (#7785)
* fix commit statuses api url * search refs before passing sha * adjust tests * directly search tags and branches names + remove un-needed check in NewCommitStatus * fix comment * de-duplicate code * test: use relative setting.AppURL * Update routers/api/v1/repo/status.go Co-Authored-By: Lauris BH <lauris@nix.lv> * remove return * Update routers/api/v1/repo/status.go Co-Authored-By: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'routers/api/v1/repo/status.go')
-rw-r--r--routers/api/v1/repo/status.go38
1 files changed, 33 insertions, 5 deletions
diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go
index e4afb599ee..b3d16e79bc 100644
--- a/routers/api/v1/repo/status.go
+++ b/routers/api/v1/repo/status.go
@@ -46,10 +46,7 @@ func NewCommitStatus(ctx *context.APIContext, form api.CreateStatusOption) {
// "$ref": "#/responses/StatusList"
sha := ctx.Params("sha")
if len(sha) == 0 {
- sha = ctx.Params("ref")
- }
- if len(sha) == 0 {
- ctx.Error(400, "ref/sha not given", nil)
+ ctx.Error(400, "sha not given", nil)
return
}
status := &models.CommitStatus{
@@ -155,7 +152,38 @@ func GetCommitStatusesByRef(ctx *context.APIContext) {
// responses:
// "200":
// "$ref": "#/responses/StatusList"
- getCommitStatuses(ctx, ctx.Params("ref"))
+
+ filter := ctx.Params("ref")
+ if len(filter) == 0 {
+ ctx.Error(400, "ref not given", nil)
+ return
+ }
+
+ for _, reftype := range []string{"heads", "tags"} { //Search branches and tags
+ refSHA, lastMethodName, err := searchRefCommitByType(ctx, reftype, filter)
+ if err != nil {
+ ctx.Error(500, lastMethodName, err)
+ return
+ }
+ if refSHA != "" {
+ filter = refSHA
+ break
+ }
+
+ }
+
+ getCommitStatuses(ctx, filter) //By default filter is maybe the raw SHA
+}
+
+func searchRefCommitByType(ctx *context.APIContext, refType, filter string) (string, string, error) {
+ refs, lastMethodName, err := getGitRefs(ctx, refType+"/"+filter) //Search by type
+ if err != nil {
+ return "", lastMethodName, err
+ }
+ if len(refs) > 0 {
+ return refs[0].Object.String(), "", nil //Return found SHA
+ }
+ return "", "", nil
}
func getCommitStatuses(ctx *context.APIContext, sha string) {