This commit is contained in:
@@ -10,20 +10,23 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
files_service "code.gitea.io/gitea/services/repository/files"
|
||||
"code.gitea.io/gitea/tests"
|
||||
"gitea.dev/models/db"
|
||||
issues_model "gitea.dev/models/issues"
|
||||
repo_model "gitea.dev/models/repo"
|
||||
"gitea.dev/models/unittest"
|
||||
user_model "gitea.dev/models/user"
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/gitrepo"
|
||||
"gitea.dev/modules/test"
|
||||
issue_service "gitea.dev/services/issue"
|
||||
repo_service "gitea.dev/services/repository"
|
||||
files_service "gitea.dev/services/repository/files"
|
||||
"gitea.dev/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPullView_ReviewerMissed(t *testing.T) {
|
||||
@@ -95,6 +98,14 @@ func TestPullView_CodeOwner(t *testing.T) {
|
||||
unittest.AssertExistsAndLoadBean(t, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 5})
|
||||
assert.NoError(t, pr.LoadIssue(t.Context()))
|
||||
|
||||
// capture the current PR head ref so we can wait for the async
|
||||
// refs/pull/N/head sync triggered by the next push to complete
|
||||
baseGitRepo, err := gitrepo.OpenRepository(t.Context(), repo)
|
||||
require.NoError(t, err)
|
||||
defer baseGitRepo.Close()
|
||||
headRefBefore, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
require.NoError(t, err)
|
||||
|
||||
// update the file on the pr branch
|
||||
_, err = files_service.ChangeRepoFiles(t.Context(), repo, user2, &files_service.ChangeRepoFilesOptions{
|
||||
OldBranch: "codeowner-basebranch",
|
||||
@@ -108,9 +119,17 @@ func TestPullView_CodeOwner(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
// refs/pull/N/head is refreshed asynchronously by the push hook; wait for
|
||||
// it before evaluating code owners, otherwise the changed-file set may not
|
||||
// yet include user8-file.md and the review request would be missed
|
||||
require.Eventually(t, func() bool {
|
||||
headRefAfter, err := baseGitRepo.GetRefCommitID(pr.GetGitHeadRefName())
|
||||
return err == nil && headRefAfter != headRefBefore
|
||||
}, 30*time.Second, 100*time.Millisecond)
|
||||
|
||||
reviewNotifiers, err := issue_service.PullRequestCodeOwnersReview(t.Context(), pr)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, reviewNotifiers, 1)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, reviewNotifiers, 1)
|
||||
assert.EqualValues(t, 8, reviewNotifiers[0].Reviewer.ID)
|
||||
|
||||
err = issue_service.ChangeTitle(t.Context(), pr.Issue, user2, "[WIP] Test Pull Request")
|
||||
@@ -264,13 +283,13 @@ func testSubmitReview(t *testing.T, session *TestSession, owner, repo, pullNumbe
|
||||
"type": reviewType,
|
||||
}
|
||||
|
||||
submitURL := path.Join(owner, repo, "pulls", pullNumber, "files", "reviews", "submit")
|
||||
submitURL := "/" + path.Join(owner, repo, "pulls", pullNumber, "files", "reviews", "submit")
|
||||
req := NewRequestWithValues(t, "POST", submitURL, options)
|
||||
return session.MakeRequest(t, req, expectedSubmitStatus)
|
||||
}
|
||||
|
||||
func testIssueClose(t *testing.T, session *TestSession, owner, repo, issueNumber string) *httptest.ResponseRecorder {
|
||||
closeURL := path.Join(owner, repo, "issues", issueNumber, "comments")
|
||||
closeURL := "/" + path.Join(owner, repo, "issues", issueNumber, "comments")
|
||||
|
||||
options := map[string]string{
|
||||
"status": "close",
|
||||
|
||||
Reference in New Issue
Block a user