loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(api): encode empty requested reviewers as an empty array (#7355)

- Always initialize `RequestedReviewers` and `RequestedReviewersTeams`, this avoids the JSON encoder from encoding it to the zero value `null` and instead return a empty array.
- Resolves #4108
- Integration test added.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7355
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: ThomasBoom89 <thomasboom89@noreply.codeberg.org>
Co-committed-by: ThomasBoom89 <thomasboom89@noreply.codeberg.org>

authored by

ThomasBoom89
ThomasBoom89
and committed by
Gusted
6cac7702 85ae9d71

+61 -25
+27 -25
services/convert/pull.go
··· 66 66 } 67 67 68 68 apiPullRequest := &api.PullRequest{ 69 - ID: pr.ID, 70 - URL: pr.Issue.HTMLURL(), 71 - Index: pr.Index, 72 - Poster: apiIssue.Poster, 73 - Title: apiIssue.Title, 74 - Body: apiIssue.Body, 75 - Labels: apiIssue.Labels, 76 - Milestone: apiIssue.Milestone, 77 - Assignee: apiIssue.Assignee, 78 - Assignees: apiIssue.Assignees, 79 - State: apiIssue.State, 80 - Draft: pr.IsWorkInProgress(ctx), 81 - IsLocked: apiIssue.IsLocked, 82 - Comments: apiIssue.Comments, 83 - ReviewComments: pr.GetReviewCommentsCount(ctx), 84 - HTMLURL: pr.Issue.HTMLURL(), 85 - DiffURL: pr.Issue.DiffURL(), 86 - PatchURL: pr.Issue.PatchURL(), 87 - HasMerged: pr.HasMerged, 88 - MergeBase: pr.MergeBase, 89 - Mergeable: pr.Mergeable(ctx), 90 - Deadline: apiIssue.Deadline, 91 - Created: pr.Issue.CreatedUnix.AsTimePtr(), 92 - Updated: pr.Issue.UpdatedUnix.AsTimePtr(), 93 - PinOrder: apiIssue.PinOrder, 69 + ID: pr.ID, 70 + URL: pr.Issue.HTMLURL(), 71 + Index: pr.Index, 72 + Poster: apiIssue.Poster, 73 + Title: apiIssue.Title, 74 + Body: apiIssue.Body, 75 + Labels: apiIssue.Labels, 76 + Milestone: apiIssue.Milestone, 77 + Assignee: apiIssue.Assignee, 78 + Assignees: apiIssue.Assignees, 79 + State: apiIssue.State, 80 + Draft: pr.IsWorkInProgress(ctx), 81 + IsLocked: apiIssue.IsLocked, 82 + Comments: apiIssue.Comments, 83 + ReviewComments: pr.GetReviewCommentsCount(ctx), 84 + HTMLURL: pr.Issue.HTMLURL(), 85 + DiffURL: pr.Issue.DiffURL(), 86 + PatchURL: pr.Issue.PatchURL(), 87 + HasMerged: pr.HasMerged, 88 + MergeBase: pr.MergeBase, 89 + Mergeable: pr.Mergeable(ctx), 90 + Deadline: apiIssue.Deadline, 91 + Created: pr.Issue.CreatedUnix.AsTimePtr(), 92 + Updated: pr.Issue.UpdatedUnix.AsTimePtr(), 93 + PinOrder: apiIssue.PinOrder, 94 + RequestedReviewers: []*api.User{}, 95 + RequestedReviewersTeams: []*api.Team{}, 94 96 95 97 AllowMaintainerEdit: pr.AllowMaintainerEdit, 96 98
+34
tests/integration/api_repo_pulls_test.go
··· 1 + // Copyright 2021 The Gitea Authors. All rights reserved. 2 + // SPDX-License-Identifier: MIT 3 + 4 + package integration 5 + 6 + import ( 7 + "fmt" 8 + "net/http" 9 + "testing" 10 + 11 + repo_model "code.gitea.io/gitea/models/repo" 12 + "code.gitea.io/gitea/models/unittest" 13 + api "code.gitea.io/gitea/modules/structs" 14 + "code.gitea.io/gitea/tests" 15 + 16 + "github.com/stretchr/testify/assert" 17 + ) 18 + 19 + func TestAPIRepoPulls(t *testing.T) { 20 + defer tests.PrepareTestEnv(t)() 21 + 22 + // repo = user2/repo1 23 + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) 24 + 25 + // issue id without assigned review member or review team 26 + issueID := 5 27 + req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d", repo.OwnerName, repo.Name, issueID)) 28 + res := MakeRequest(t, req, http.StatusOK) 29 + var pr *api.PullRequest 30 + DecodeJSON(t, res, &pr) 31 + 32 + assert.NotNil(t, pr.RequestedReviewers) 33 + assert.NotNil(t, pr.RequestedReviewersTeams) 34 + }