mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-28 14:43:52 +03:00
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)
This commit is contained in:
parent
439c8fb246
commit
8b6747173a
5 changed files with 90 additions and 16 deletions
|
@ -163,6 +163,7 @@ type PullRequest struct {
|
||||||
Issue *Issue `xorm:"-"`
|
Issue *Issue `xorm:"-"`
|
||||||
Index int64
|
Index int64
|
||||||
RequestedReviewers []*user_model.User `xorm:"-"`
|
RequestedReviewers []*user_model.User `xorm:"-"`
|
||||||
|
RequestedReviewersTeams []*org_model.Team `xorm:"-"`
|
||||||
isRequestedReviewersLoaded bool `xorm:"-"`
|
isRequestedReviewersLoaded bool `xorm:"-"`
|
||||||
|
|
||||||
HeadRepoID int64 `xorm:"INDEX"`
|
HeadRepoID int64 `xorm:"INDEX"`
|
||||||
|
@ -303,8 +304,29 @@ func (pr *PullRequest) LoadRequestedReviewers(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
pr.isRequestedReviewersLoaded = true
|
pr.isRequestedReviewersLoaded = true
|
||||||
for _, review := range reviews {
|
for _, review := range reviews {
|
||||||
|
if review.ReviewerID != 0 {
|
||||||
pr.RequestedReviewers = append(pr.RequestedReviewers, review.Reviewer)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
organization_model "code.gitea.io/gitea/models/organization"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/container"
|
"code.gitea.io/gitea/modules/container"
|
||||||
"code.gitea.io/gitea/modules/optional"
|
"code.gitea.io/gitea/modules/optional"
|
||||||
|
@ -37,6 +38,34 @@ func (reviews ReviewList) LoadReviewers(ctx context.Context) error {
|
||||||
return nil
|
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 {
|
func (reviews ReviewList) LoadIssues(ctx context.Context) error {
|
||||||
issueIDs := container.FilterSlice(reviews, func(review *Review) (int64, bool) {
|
issueIDs := container.FilterSlice(reviews, func(review *Review) (int64, bool) {
|
||||||
return review.IssueID, true
|
return review.IssueID, true
|
||||||
|
|
|
@ -20,6 +20,7 @@ type PullRequest struct {
|
||||||
Assignee *User `json:"assignee"`
|
Assignee *User `json:"assignee"`
|
||||||
Assignees []*User `json:"assignees"`
|
Assignees []*User `json:"assignees"`
|
||||||
RequestedReviewers []*User `json:"requested_reviewers"`
|
RequestedReviewers []*User `json:"requested_reviewers"`
|
||||||
|
RequestedReviewersTeams []*Team `json:"requested_reviewers_teams"`
|
||||||
State StateType `json:"state"`
|
State StateType `json:"state"`
|
||||||
Draft bool `json:"draft"`
|
Draft bool `json:"draft"`
|
||||||
IsLocked bool `json:"is_locked"`
|
IsLocked bool `json:"is_locked"`
|
||||||
|
|
|
@ -106,10 +106,25 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
|
||||||
log.Error("LoadRequestedReviewers[%d]: %v", pr.ID, err)
|
log.Error("LoadRequestedReviewers[%d]: %v", pr.ID, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if err = pr.LoadRequestedReviewersTeams(ctx); err != nil {
|
||||||
|
log.Error("LoadRequestedReviewersTeams[%d]: %v", pr.ID, err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
for _, reviewer := range pr.RequestedReviewers {
|
for _, reviewer := range pr.RequestedReviewers {
|
||||||
apiPullRequest.RequestedReviewers = append(apiPullRequest.RequestedReviewers, ToUser(ctx, reviewer, nil))
|
apiPullRequest.RequestedReviewers = append(apiPullRequest.RequestedReviewers, ToUser(ctx, reviewer, nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, reviewerTeam := range pr.RequestedReviewersTeams {
|
||||||
|
convertedTeam, err := ToTeam(ctx, reviewerTeam, true)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("LoadRequestedReviewersTeams[%d]: %v", pr.ID, err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
apiPullRequest.RequestedReviewersTeams = append(apiPullRequest.RequestedReviewersTeams, convertedTeam)
|
||||||
|
}
|
||||||
|
|
||||||
if pr.Issue.ClosedUnix != 0 {
|
if pr.Issue.ClosedUnix != 0 {
|
||||||
apiPullRequest.Closed = pr.Issue.ClosedUnix.AsTimePtr()
|
apiPullRequest.Closed = pr.Issue.ClosedUnix.AsTimePtr()
|
||||||
}
|
}
|
||||||
|
|
7
templates/swagger/v1_json.tmpl
generated
7
templates/swagger/v1_json.tmpl
generated
|
@ -25088,6 +25088,13 @@
|
||||||
},
|
},
|
||||||
"x-go-name": "RequestedReviewers"
|
"x-go-name": "RequestedReviewers"
|
||||||
},
|
},
|
||||||
|
"requested_reviewers_teams": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Team"
|
||||||
|
},
|
||||||
|
"x-go-name": "RequestedReviewersTeams"
|
||||||
|
},
|
||||||
"review_comments": {
|
"review_comments": {
|
||||||
"description": "number of review comments made on the diff of a PR review (not including comments on commits or issues in a PR)",
|
"description": "number of review comments made on the diff of a PR review (not including comments on commits or issues in a PR)",
|
||||||
"type": "integer",
|
"type": "integer",
|
||||||
|
|
Loading…
Reference in a new issue