2019-05-06 20:09:31 +08:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2022-09-03 03:18:23 +08:00
|
|
|
package integration
|
2019-05-06 20:09:31 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2024-03-15 13:13:09 +08:00
|
|
|
"net/url"
|
|
|
|
"strings"
|
2019-05-06 20:09:31 +08:00
|
|
|
"testing"
|
2022-09-03 03:18:23 +08:00
|
|
|
|
2024-03-15 13:13:09 +08:00
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
issues_model "code.gitea.io/gitea/models/issues"
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
|
|
"code.gitea.io/gitea/modules/git"
|
|
|
|
repo_service "code.gitea.io/gitea/services/repository"
|
|
|
|
files_service "code.gitea.io/gitea/services/repository/files"
|
2022-09-03 03:18:23 +08:00
|
|
|
"code.gitea.io/gitea/tests"
|
2024-03-15 13:13:09 +08:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-05-06 20:09:31 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPullView_ReviewerMissed(t *testing.T) {
|
2022-09-03 03:18:23 +08:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2019-05-06 20:09:31 +08:00
|
|
|
session := loginUser(t, "user1")
|
|
|
|
|
|
|
|
req := NewRequest(t, "GET", "/pulls")
|
|
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
req = NewRequest(t, "GET", "/user2/repo1/pulls/3")
|
|
|
|
session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
}
|
2024-03-15 13:13:09 +08:00
|
|
|
|
|
|
|
func TestPullView_CodeOwner(t *testing.T) {
|
|
|
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
|
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
|
|
|
|
|
|
// Create the repo.
|
|
|
|
repo, err := repo_service.CreateRepositoryDirectly(db.DefaultContext, user2, user2, repo_service.CreateRepoOptions{
|
|
|
|
Name: "test_codeowner",
|
|
|
|
Readme: "Default",
|
|
|
|
AutoInit: true,
|
|
|
|
ObjectFormatName: git.Sha1ObjectFormat.Name(),
|
|
|
|
DefaultBranch: "master",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// add CODEOWNERS to default branch
|
|
|
|
_, err = files_service.ChangeRepoFiles(db.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{
|
|
|
|
OldBranch: repo.DefaultBranch,
|
|
|
|
Files: []*files_service.ChangeRepoFile{
|
|
|
|
{
|
|
|
|
Operation: "create",
|
|
|
|
TreePath: "CODEOWNERS",
|
|
|
|
ContentReader: strings.NewReader("README.md @user5\n"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("First Pull Request", func(t *testing.T) {
|
|
|
|
// create a new branch to prepare for pull request
|
|
|
|
_, err = files_service.ChangeRepoFiles(db.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{
|
|
|
|
NewBranch: "codeowner-basebranch",
|
|
|
|
Files: []*files_service.ChangeRepoFile{
|
|
|
|
{
|
|
|
|
Operation: "update",
|
|
|
|
TreePath: "README.md",
|
|
|
|
ContentReader: strings.NewReader("# This is a new project\n"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Create a pull request.
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
testPullCreate(t, session, "user2", "test_codeowner", false, repo.DefaultBranch, "codeowner-basebranch", "Test Pull Request")
|
|
|
|
|
|
|
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadBranch: "codeowner-basebranch"})
|
|
|
|
unittest.AssertExistsIf(t, true, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 5})
|
|
|
|
})
|
|
|
|
|
|
|
|
// change the default branch CODEOWNERS file to change README.md's codeowner
|
|
|
|
_, err = files_service.ChangeRepoFiles(db.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{
|
|
|
|
Files: []*files_service.ChangeRepoFile{
|
|
|
|
{
|
|
|
|
Operation: "update",
|
|
|
|
TreePath: "CODEOWNERS",
|
|
|
|
ContentReader: strings.NewReader("README.md @user8\n"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("Second Pull Request", func(t *testing.T) {
|
|
|
|
// create a new branch to prepare for pull request
|
|
|
|
_, err = files_service.ChangeRepoFiles(db.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{
|
|
|
|
NewBranch: "codeowner-basebranch2",
|
|
|
|
Files: []*files_service.ChangeRepoFile{
|
|
|
|
{
|
|
|
|
Operation: "update",
|
|
|
|
TreePath: "README.md",
|
|
|
|
ContentReader: strings.NewReader("# This is a new project2\n"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// Create a pull request.
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
testPullCreate(t, session, "user2", "test_codeowner", false, repo.DefaultBranch, "codeowner-basebranch2", "Test Pull Request2")
|
|
|
|
|
|
|
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadBranch: "codeowner-basebranch2"})
|
|
|
|
unittest.AssertExistsIf(t, true, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 8})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Forked Repo Pull Request", func(t *testing.T) {
|
|
|
|
user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
|
|
|
|
forkedRepo, err := repo_service.ForkRepository(db.DefaultContext, user2, user5, repo_service.ForkRepoOptions{
|
|
|
|
BaseRepo: repo,
|
|
|
|
Name: "test_codeowner_fork",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// create a new branch to prepare for pull request
|
|
|
|
_, err = files_service.ChangeRepoFiles(db.DefaultContext, forkedRepo, user5, &files_service.ChangeRepoFilesOptions{
|
|
|
|
NewBranch: "codeowner-basebranch-forked",
|
|
|
|
Files: []*files_service.ChangeRepoFile{
|
|
|
|
{
|
|
|
|
Operation: "update",
|
|
|
|
TreePath: "README.md",
|
|
|
|
ContentReader: strings.NewReader("# This is a new forked project\n"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
session := loginUser(t, "user5")
|
|
|
|
testPullCreate(t, session, "user5", "test_codeowner_fork", false, forkedRepo.DefaultBranch, "codeowner-basebranch-forked", "Test Pull Request2")
|
|
|
|
|
|
|
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadBranch: "codeowner-basebranch-forked"})
|
|
|
|
unittest.AssertExistsIf(t, false, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 8})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|