diff --git a/services/convert/pull.go b/services/convert/pull.go index 7bee2b4c44..0cb4070595 100644 --- a/services/convert/pull.go +++ b/services/convert/pull.go @@ -66,31 +66,33 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u } apiPullRequest := &api.PullRequest{ - ID: pr.ID, - URL: pr.Issue.HTMLURL(), - Index: pr.Index, - Poster: apiIssue.Poster, - Title: apiIssue.Title, - Body: apiIssue.Body, - Labels: apiIssue.Labels, - Milestone: apiIssue.Milestone, - Assignee: apiIssue.Assignee, - Assignees: apiIssue.Assignees, - State: apiIssue.State, - Draft: pr.IsWorkInProgress(ctx), - IsLocked: apiIssue.IsLocked, - Comments: apiIssue.Comments, - ReviewComments: pr.GetReviewCommentsCount(ctx), - HTMLURL: pr.Issue.HTMLURL(), - DiffURL: pr.Issue.DiffURL(), - PatchURL: pr.Issue.PatchURL(), - HasMerged: pr.HasMerged, - MergeBase: pr.MergeBase, - Mergeable: pr.Mergeable(ctx), - Deadline: apiIssue.Deadline, - Created: pr.Issue.CreatedUnix.AsTimePtr(), - Updated: pr.Issue.UpdatedUnix.AsTimePtr(), - PinOrder: apiIssue.PinOrder, + ID: pr.ID, + URL: pr.Issue.HTMLURL(), + Index: pr.Index, + Poster: apiIssue.Poster, + Title: apiIssue.Title, + Body: apiIssue.Body, + Labels: apiIssue.Labels, + Milestone: apiIssue.Milestone, + Assignee: apiIssue.Assignee, + Assignees: apiIssue.Assignees, + State: apiIssue.State, + Draft: pr.IsWorkInProgress(ctx), + IsLocked: apiIssue.IsLocked, + Comments: apiIssue.Comments, + ReviewComments: pr.GetReviewCommentsCount(ctx), + HTMLURL: pr.Issue.HTMLURL(), + DiffURL: pr.Issue.DiffURL(), + PatchURL: pr.Issue.PatchURL(), + HasMerged: pr.HasMerged, + MergeBase: pr.MergeBase, + Mergeable: pr.Mergeable(ctx), + Deadline: apiIssue.Deadline, + Created: pr.Issue.CreatedUnix.AsTimePtr(), + Updated: pr.Issue.UpdatedUnix.AsTimePtr(), + PinOrder: apiIssue.PinOrder, + RequestedReviewers: []*api.User{}, + RequestedReviewersTeams: []*api.Team{}, AllowMaintainerEdit: pr.AllowMaintainerEdit, diff --git a/tests/integration/api_repo_pulls_test.go b/tests/integration/api_repo_pulls_test.go new file mode 100644 index 0000000000..aec492e65f --- /dev/null +++ b/tests/integration/api_repo_pulls_test.go @@ -0,0 +1,34 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package integration + +import ( + "fmt" + "net/http" + "testing" + + repo_model "forgejo.org/models/repo" + "forgejo.org/models/unittest" + api "forgejo.org/modules/structs" + "forgejo.org/tests" + + "github.com/stretchr/testify/assert" +) + +func TestAPIRepoPulls(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + // repo = user2/repo1 + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) + + // issue id without assigned review member or review team + issueID := 5 + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d", repo.OwnerName, repo.Name, issueID)) + res := MakeRequest(t, req, http.StatusOK) + var pr *api.PullRequest + DecodeJSON(t, res, &pr) + + assert.NotNil(t, pr.RequestedReviewers) + assert.NotNil(t, pr.RequestedReviewersTeams) +}