diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2024-03-25 15:51:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-25 15:51:23 +0800 |
commit | 475b6e839caa88994318f905f0965c3b418f876a (patch) | |
tree | dbda7a7ebe1e3c28fedfb68f3acbe6a3bb4a23cf /services/issue | |
parent | c6c4d66004c70b24abc8048b39b660b8361a0395 (diff) | |
download | gitea-475b6e839caa88994318f905f0965c3b418f876a.tar.gz gitea-475b6e839caa88994318f905f0965c3b418f876a.zip |
Fix Add/Remove WIP on pull request title failure (#29999)
Fix #29997
Diffstat (limited to 'services/issue')
-rw-r--r-- | services/issue/issue.go | 25 | ||||
-rw-r--r-- | services/issue/pull.go | 16 |
2 files changed, 20 insertions, 21 deletions
diff --git a/services/issue/issue.go b/services/issue/issue.go index 94b0ee6f69..c7fa9f3300 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -17,6 +17,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/container" "code.gitea.io/gitea/modules/git" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/storage" notify_service "code.gitea.io/gitea/services/notify" ) @@ -85,23 +86,17 @@ func ChangeTitle(ctx context.Context, issue *issues_model.Issue, doer *user_mode } } - var reviewNotifers []*ReviewRequestNotifier - - if err := db.WithTx(ctx, func(ctx context.Context) error { - if err := issues_model.ChangeIssueTitle(ctx, issue, doer, oldTitle); err != nil { - return err - } + if err := issues_model.ChangeIssueTitle(ctx, issue, doer, oldTitle); err != nil { + return err + } - if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issues_model.HasWorkInProgressPrefix(title) { - var err error - reviewNotifers, err = PullRequestCodeOwnersReview(ctx, issue, issue.PullRequest) - if err != nil { - return err - } + var reviewNotifers []*ReviewRequestNotifier + if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issues_model.HasWorkInProgressPrefix(title) { + var err error + reviewNotifers, err = PullRequestCodeOwnersReview(ctx, issue, issue.PullRequest) + if err != nil { + log.Error("PullRequestCodeOwnersReview: %v", err) } - return nil - }); err != nil { - return err } notify_service.IssueChangeTitle(ctx, doer, issue, oldTitle) diff --git a/services/issue/pull.go b/services/issue/pull.go index 8e85c11e9b..b7b63a7024 100644 --- a/services/issue/pull.go +++ b/services/issue/pull.go @@ -40,7 +40,7 @@ type ReviewRequestNotifier struct { ReviewTeam *org_model.Team } -func PullRequestCodeOwnersReview(ctx context.Context, pull *issues_model.Issue, pr *issues_model.PullRequest) ([]*ReviewRequestNotifier, error) { +func PullRequestCodeOwnersReview(ctx context.Context, issue *issues_model.Issue, pr *issues_model.PullRequest) ([]*ReviewRequestNotifier, error) { files := []string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"} if pr.IsWorkInProgress(ctx) { @@ -90,7 +90,7 @@ func PullRequestCodeOwnersReview(ctx context.Context, pull *issues_model.Issue, // https://github.com/go-gitea/gitea/issues/29763, we need to get the files changed // between the merge base and the head commit but not the base branch and the head commit - changedFiles, err := repo.GetFilesChangedBetween(mergeBase, pr.HeadCommitID) + changedFiles, err := repo.GetFilesChangedBetween(mergeBase, pr.GetGitRefName()) if err != nil { return nil, err } @@ -112,9 +112,13 @@ func PullRequestCodeOwnersReview(ctx context.Context, pull *issues_model.Issue, notifiers := make([]*ReviewRequestNotifier, 0, len(uniqUsers)+len(uniqTeams)) + if err := issue.LoadPoster(ctx); err != nil { + return nil, err + } + for _, u := range uniqUsers { - if u.ID != pull.Poster.ID { - comment, err := issues_model.AddReviewRequest(ctx, pull, u, pull.Poster) + if u.ID != issue.Poster.ID { + comment, err := issues_model.AddReviewRequest(ctx, issue, u, issue.Poster) if err != nil { log.Warn("Failed add assignee user: %s to PR review: %s#%d, error: %s", u.Name, pr.BaseRepo.Name, pr.ID, err) return nil, err @@ -122,12 +126,12 @@ func PullRequestCodeOwnersReview(ctx context.Context, pull *issues_model.Issue, notifiers = append(notifiers, &ReviewRequestNotifier{ Comment: comment, IsAdd: true, - Reviwer: pull.Poster, + Reviwer: u, }) } } for _, t := range uniqTeams { - comment, err := issues_model.AddTeamReviewRequest(ctx, pull, t, pull.Poster) + comment, err := issues_model.AddTeamReviewRequest(ctx, issue, t, issue.Poster) if err != nil { log.Warn("Failed add assignee team: %s to PR review: %s#%d, error: %s", t.Name, pr.BaseRepo.Name, pr.ID, err) return nil, err |