Skip to content

Commit

Permalink
Fix panic when getting notes by ref (#23372) (#23377)
Browse files Browse the repository at this point in the history
Backport #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`.

Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
  • Loading branch information
3 people authored Mar 8, 2023
1 parent 2ba58fa commit 54c674c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion routers/api/v1/repo/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54c674c

Please sign in to comment.