From ecfcd45835117f558bfc44580873b485fc649844 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Wed, 8 Mar 2023 16:28:19 +0800 Subject: [PATCH 1/2] convert ref to commit id before get note in api --- routers/api/v1/repo/notes.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/routers/api/v1/repo/notes.go b/routers/api/v1/repo/notes.go index 2d1f3291f8b9c..f5a1cbaae6d77 100644 --- a/routers/api/v1/repo/notes.go +++ b/routers/api/v1/repo/notes.go @@ -58,8 +58,14 @@ func getNote(ctx *context.APIContext, identifier string) { return } + commitSHA, err := ctx.Repo.GitRepo.ConvertToSHA1(identifier) + if err != nil { + ctx.NotFound(err) + return + } + var note git.Note - if err := git.GetNote(ctx, ctx.Repo.GitRepo, identifier, ¬e); err != nil { + if err := git.GetNote(ctx, ctx.Repo.GitRepo, commitSHA.String(), ¬e); err != nil { if git.IsErrNotExist(err) { ctx.NotFound(identifier) return From 7e1b899c98e56f7454f5d18385d0c8a7263f82f9 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Wed, 8 Mar 2023 17:33:45 +0800 Subject: [PATCH 2/2] fix return error --- routers/api/v1/repo/notes.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/routers/api/v1/repo/notes.go b/routers/api/v1/repo/notes.go index f5a1cbaae6d77..74969f2cad7c8 100644 --- a/routers/api/v1/repo/notes.go +++ b/routers/api/v1/repo/notes.go @@ -60,7 +60,11 @@ func getNote(ctx *context.APIContext, identifier string) { commitSHA, err := ctx.Repo.GitRepo.ConvertToSHA1(identifier) if err != nil { - ctx.NotFound(err) + if git.IsErrNotExist(err) { + ctx.NotFound(err) + } else { + ctx.Error(http.StatusInternalServerError, "ConvertToSHA1", err) + } return }