@@ -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,33 +152,31 @@ 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 
166- 
167- 	if  err  :=  c .LoadIssue (ctx ); err  !=  nil  {
168- 		return  err 
169- 	}
170- 	if  err  :=  c .Issue .LoadRepo (ctx ); err  !=  nil  {
171- 		return  err 
172- 	}
173- 
174167	if  c .IsForcePush  {
175168		if  len (data .CommitIDs ) !=  2  {
176169			return  nil 
177170		}
178- 		c .OldCommit  =  data .CommitIDs [0 ]
179- 		c .NewCommit  =  data .CommitIDs [1 ]
171+ 		c .OldCommit , c .NewCommit  =  data .CommitIDs [0 ], data .CommitIDs [1 ]
180172	} else  {
173+ 		if  err  :=  c .LoadIssue (ctx ); err  !=  nil  {
174+ 			return  err 
175+ 		}
176+ 		if  err  :=  c .Issue .LoadRepo (ctx ); err  !=  nil  {
177+ 			return  err 
178+ 		}
179+ 
181180		gitRepo , closer , err  :=  gitrepo .RepositoryFromContextOrOpen (ctx , c .Issue .Repo )
182181		if  err  !=  nil  {
183182			return  err 
@@ -186,10 +185,11 @@ func LoadCommentPushCommits(ctx context.Context, c *issues_model.Comment) (err e
186185
187186		c .Commits , err  =  git_service .ConvertFromGitCommit (ctx , gitRepo .GetCommitsFromIDs (data .CommitIDs ), c .Issue .Repo )
188187		if  err  !=  nil  {
189- 			return  err 
188+ 			log .Debug ("GetCommitsFromIDs: %v" , err ) // no need to show 500 error to end user when the commit does not exist 
189+ 		} else  {
190+ 			c .CommitsNum  =  int64 (len (c .Commits ))
190191		}
191- 		c .CommitsNum  =  int64 (len (c .Commits ))
192192	}
193193
194- 	return  err 
194+ 	return  nil 
195195}
0 commit comments