aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo
diff options
context:
space:
mode:
authorZettat123 <zettat123@gmail.com>2023-03-08 20:21:23 +0800
committerGitHub <noreply@github.com>2023-03-08 20:21:23 +0800
commit15a1c2d7efa2c835fb9bcff439446579f08c5e32 (patch)
tree27cfcad01133151fb162b3ba905d29cf105d5d51 /routers/api/v1/repo
parentb116418f05b822481bba3613873eef876da73814 (diff)
downloadgitea-15a1c2d7efa2c835fb9bcff439446579f08c5e32.tar.gz
gitea-15a1c2d7efa2c835fb9bcff439446579f08c5e32.zip
Fix panic when getting notes by ref (#23372)
Fix #23357 . Now the `/repos/{owner}/{repo}/git/notes/{sha}` API supports getting notes by a ref or sha (https://try.gitea.io/api/swagger#/repository/repoGetNote). But the `GetNote` func can only accept commit ID. https://github.com/go-gitea/gitea/blob/a12f5757372f751d25f9e5ca1f168f6920ded894/modules/git/notes_nogogit.go#L18 So we need to convert the query parameter to commit ID before calling `GetNote`.
Diffstat (limited to 'routers/api/v1/repo')
-rw-r--r--routers/api/v1/repo/notes.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/routers/api/v1/repo/notes.go b/routers/api/v1/repo/notes.go
index 2d1f3291f8..74969f2cad 100644
--- a/routers/api/v1/repo/notes.go
+++ b/routers/api/v1/repo/notes.go
@@ -58,8 +58,18 @@ func getNote(ctx *context.APIContext, identifier string) {
return
}
+ commitSHA, err := ctx.Repo.GitRepo.ConvertToSHA1(identifier)
+ if err != nil {
+ if git.IsErrNotExist(err) {
+ ctx.NotFound(err)
+ } else {
+ ctx.Error(http.StatusInternalServerError, "ConvertToSHA1", err)
+ }
+ return
+ }
+
var note git.Note
- if err := git.GetNote(ctx, ctx.Repo.GitRepo, identifier, &note); err != nil {
+ if err := git.GetNote(ctx, ctx.Repo.GitRepo, commitSHA.String(), &note); err != nil {
if git.IsErrNotExist(err) {
ctx.NotFound(identifier)
return