@@ -15,6 +15,7 @@ import (
1515 user_model "code.gitea.io/gitea/models/user"
1616 "code.gitea.io/gitea/modules/gitrepo"
1717 "code.gitea.io/gitea/modules/json"
18+ "code.gitea.io/gitea/modules/log"
1819 "code.gitea.io/gitea/modules/timeutil"
1920 git_service "code.gitea.io/gitea/services/git"
2021 notify_service "code.gitea.io/gitea/services/notify"
@@ -151,15 +152,15 @@ func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_m
151152}
152153
153154// LoadCommentPushCommits Load push commits
154- func LoadCommentPushCommits (ctx context.Context , c * issues_model.Comment ) ( err error ) {
155+ func LoadCommentPushCommits (ctx context.Context , c * issues_model.Comment ) error {
155156 if c .Content == "" || c .Commits != nil || c .Type != issues_model .CommentTypePullRequestPush {
156157 return nil
157158 }
158159
159160 var data issues_model.PushActionContent
160- err = json .Unmarshal ([]byte (c .Content ), & data )
161- if err != nil {
162- return err
161+ if err : = json .Unmarshal ([]byte (c .Content ), & data ); err != nil {
162+ log . Debug ( "Unmarshal: %v" , err ) // no need to show 500 error to end user when the JSON is broken
163+ return nil
163164 }
164165
165166 c .IsForcePush = data .IsForcePush
@@ -168,9 +169,15 @@ func LoadCommentPushCommits(ctx context.Context, c *issues_model.Comment) (err e
168169 if len (data .CommitIDs ) != 2 {
169170 return nil
170171 }
171- c .OldCommit = data .CommitIDs [0 ]
172- c .NewCommit = data .CommitIDs [1 ]
172+ c .OldCommit , c .NewCommit = data .CommitIDs [0 ], data .CommitIDs [1 ]
173173 } else {
174+ if err := c .LoadIssue (ctx ); err != nil {
175+ return err
176+ }
177+ if err := c .Issue .LoadRepo (ctx ); err != nil {
178+ return err
179+ }
180+
174181 gitRepo , closer , err := gitrepo .RepositoryFromContextOrOpen (ctx , c .Issue .Repo )
175182 if err != nil {
176183 return err
@@ -179,10 +186,11 @@ func LoadCommentPushCommits(ctx context.Context, c *issues_model.Comment) (err e
179186
180187 c .Commits , err = git_service .ConvertFromGitCommit (ctx , gitRepo .GetCommitsFromIDs (data .CommitIDs ), c .Issue .Repo )
181188 if err != nil {
182- return err
189+ log .Debug ("ConvertFromGitCommit: %v" , err ) // no need to show 500 error to end user when the commit does not exist
190+ } else {
191+ c .CommitsNum = int64 (len (c .Commits ))
183192 }
184- c .CommitsNum = int64 (len (c .Commits ))
185193 }
186194
187- return err
195+ return nil
188196}
0 commit comments