Skip to content

Commit 54c674c

Browse files
GiteaBotZettat123techknowlogick
authored
Fix panic when getting notes by ref (#23372) (#23377)
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 <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 2ba58fa commit 54c674c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

routers/api/v1/repo/notes.go

Lines changed: 11 additions & 1 deletion
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)