summaryrefslogtreecommitdiffstats
path: root/models/issues
diff options
context:
space:
mode:
authorEdip Emre Bodur <38386056+emrebdr@users.noreply.github.com>2024-08-05 12:59:53 +0200
committerEarl Warren <contact@earl-warren.org>2024-08-13 06:51:49 +0200
commit8b6747173a6adac69c238c63088a9515e13f769e (patch)
treef0c0c3bd8b89a691ae1d9dea4a0ca8ac2d0bfd79 /models/issues
parentMerge pull request '[CHORE] Drop `go-git` support' (#4941) from gusted/drop-g... (diff)
downloadforgejo-8b6747173a6adac69c238c63088a9515e13f769e.tar.xz
forgejo-8b6747173a6adac69c238c63088a9515e13f769e.zip
Fix null requested_reviewer from API (#31773)
If the assign the pull request review to a team, it did not show the members of the team in the "requested_reviewers" field, so the field was null. As a solution, I added the team members to the array. fix #31764 (cherry picked from commit 94cca8846e7d62c8a295d70c8199d706dfa60e5c)
Diffstat (limited to 'models/issues')
-rw-r--r--models/issues/pull.go24
-rw-r--r--models/issues/review_list.go29
2 files changed, 52 insertions, 1 deletions
diff --git a/models/issues/pull.go b/models/issues/pull.go
index ef49a51045..a035cad649 100644
--- a/models/issues/pull.go
+++ b/models/issues/pull.go
@@ -163,6 +163,7 @@ type PullRequest struct {
Issue *Issue `xorm:"-"`
Index int64
RequestedReviewers []*user_model.User `xorm:"-"`
+ RequestedReviewersTeams []*org_model.Team `xorm:"-"`
isRequestedReviewersLoaded bool `xorm:"-"`
HeadRepoID int64 `xorm:"INDEX"`
@@ -303,7 +304,28 @@ func (pr *PullRequest) LoadRequestedReviewers(ctx context.Context) error {
}
pr.isRequestedReviewersLoaded = true
for _, review := range reviews {
- pr.RequestedReviewers = append(pr.RequestedReviewers, review.Reviewer)
+ if review.ReviewerID != 0 {
+ pr.RequestedReviewers = append(pr.RequestedReviewers, review.Reviewer)
+ }
+ }
+
+ return nil
+}
+
+// LoadRequestedReviewersTeams loads the requested reviewers teams.
+func (pr *PullRequest) LoadRequestedReviewersTeams(ctx context.Context) error {
+ reviews, err := GetReviewsByIssueID(ctx, pr.Issue.ID)
+ if err != nil {
+ return err
+ }
+ if err = reviews.LoadReviewersTeams(ctx); err != nil {
+ return err
+ }
+
+ for _, review := range reviews {
+ if review.ReviewerTeamID != 0 {
+ pr.RequestedReviewersTeams = append(pr.RequestedReviewersTeams, review.ReviewerTeam)
+ }
}
return nil
diff --git a/models/issues/review_list.go b/models/issues/review_list.go
index 7b8c3d319c..0ee28874ec 100644
--- a/models/issues/review_list.go
+++ b/models/issues/review_list.go
@@ -7,6 +7,7 @@ import (
"context"
"code.gitea.io/gitea/models/db"
+ organization_model "code.gitea.io/gitea/models/organization"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/optional"
@@ -37,6 +38,34 @@ func (reviews ReviewList) LoadReviewers(ctx context.Context) error {
return nil
}
+// LoadReviewersTeams loads reviewers teams
+func (reviews ReviewList) LoadReviewersTeams(ctx context.Context) error {
+ reviewersTeamsIDs := make([]int64, 0)
+ for _, review := range reviews {
+ if review.ReviewerTeamID != 0 {
+ reviewersTeamsIDs = append(reviewersTeamsIDs, review.ReviewerTeamID)
+ }
+ }
+
+ teamsMap := make(map[int64]*organization_model.Team, 0)
+ for _, teamID := range reviewersTeamsIDs {
+ team, err := organization_model.GetTeamByID(ctx, teamID)
+ if err != nil {
+ return err
+ }
+
+ teamsMap[teamID] = team
+ }
+
+ for _, review := range reviews {
+ if review.ReviewerTeamID != 0 {
+ review.ReviewerTeam = teamsMap[review.ReviewerTeamID]
+ }
+ }
+
+ return nil
+}
+
func (reviews ReviewList) LoadIssues(ctx context.Context) error {
issueIDs := container.FilterSlice(reviews, func(review *Review) (int64, bool) {
return review.IssueID, true