Skip to content

Commit 50c5cd1

Browse files
committed
fix
1 parent 035dd1e commit 50c5cd1

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed

services/issue/comments.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

services/pull/pull.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,6 @@ type TestPullRequestOptions struct {
374374
func AddTestPullRequestTask(opts TestPullRequestOptions) {
375375
log.Trace("AddTestPullRequestTask [head_repo_id: %d, head_branch: %s]: finding pull requests", opts.RepoID, opts.Branch)
376376
graceful.GetManager().RunWithShutdownContext(func(ctx context.Context) {
377-
// There is no sensible way to shut this down ":-("
378-
// If you don't let it run all the way then you will lose data
379-
380377
repo, err := repo_model.GetRepositoryByID(ctx, opts.RepoID)
381378
if err != nil {
382379
log.Error("GetRepositoryByID: %v", err)

services/repository/push.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,15 @@ func pushUpdateBranch(_ context.Context, repo *repo_model.Repository, pusher *us
310310
}
311311

312312
// only update branch can trigger pull request task because the pull request hasn't been created yet when creating a branch
313-
testPullRequestOpts := pull_service.TestPullRequestOptions{
313+
go pull_service.AddTestPullRequestTask(pull_service.TestPullRequestOptions{
314314
RepoID: repo.ID,
315315
Doer: pusher,
316316
Branch: branch,
317317
IsSync: true,
318318
IsForcePush: isForcePush,
319319
OldCommitID: opts.OldCommitID,
320320
NewCommitID: opts.NewCommitID,
321-
}
322-
go pull_service.AddTestPullRequestTask(testPullRequestOpts)
321+
})
323322

324323
if isForcePush {
325324
log.Trace("Push %s is a force push", opts.NewCommitID)

tests/integration/pull_comment_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func testPullCommentRebase(t *testing.T, u *url.URL, session *TestSession) {
6262
doGitPushTestRepositoryFail(dstPath, "base-repo", "local-branch/rebase:test-branch/rebase")(t)
6363
doGitPushTestRepository(dstPath, "--force", "base-repo", "local-branch/rebase:test-branch/rebase")(t)
6464

65+
// reload the pr
6566
prIssue := testWaitForPullRequestStatus(t, &issues_model.Issue{Title: testPRTitle}, issues_model.PullRequestStatusMergeable)
6667
comments, err := issues_model.FindComments(t.Context(), &issues_model.FindCommentsOptions{
6768
IssueID: prIssue.ID,

0 commit comments

Comments
 (0)