Skip to content

Commit 15a1c2d

Browse files
authored
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`.
1 parent b116418 commit 15a1c2d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: routers/api/v1/repo/notes.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,18 @@ func getNote(ctx *context.APIContext, identifier string) {
5858
return
5959
}
6060

61+
commitSHA, err := ctx.Repo.GitRepo.ConvertToSHA1(identifier)
62+
if err != nil {
63+
if git.IsErrNotExist(err) {
64+
ctx.NotFound(err)
65+
} else {
66+
ctx.Error(http.StatusInternalServerError, "ConvertToSHA1", err)
67+
}
68+
return
69+
}
70+
6171
var note git.Note
62-
if err := git.GetNote(ctx, ctx.Repo.GitRepo, identifier, &note); err != nil {
72+
if err := git.GetNote(ctx, ctx.Repo.GitRepo, commitSHA.String(), &note); err != nil {
6373
if git.IsErrNotExist(err) {
6474
ctx.NotFound(identifier)
6575
return

0 commit comments

Comments
 (0)