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.

a12f575737/modules/git/notes_nogogit.go (L18)

So we need to convert the query parameter to commit ID before calling
`GetNote`.
This commit is contained in:
Zettat123 2023-03-08 20:21:23 +08:00 committed by GitHub
parent b116418f05
commit 15a1c2d7ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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