mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-24 19:23:53 +00:00
fix: add .forgejo/CODEOWNERS support (#8773)
Currently, the documentation mention that a CODEOWNERS file can be located in .forgejo for code owner PR review assignment, but this does not work. Add support for this location. Resolves #8746 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8773 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: John Moon <john.moon@vts-i.com> Co-committed-by: John Moon <john.moon@vts-i.com>
This commit is contained in:
parent
cc31b744d1
commit
0a444a374e
3 changed files with 159 additions and 142 deletions
|
@ -438,7 +438,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) {
|
|||
if workFlowErr != nil {
|
||||
ctx.Data["FileError"] = ctx.Locale.Tr("actions.runs.invalid_workflow_helper", workFlowErr.Error())
|
||||
}
|
||||
} else if slices.Contains([]string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"}, ctx.Repo.TreePath) {
|
||||
} else if slices.Contains([]string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS", ".forgejo/CODEOWNERS"}, ctx.Repo.TreePath) {
|
||||
if rc, size, err := blob.NewTruncatedReader(setting.UI.MaxDisplayFileSize); err == nil {
|
||||
_, warnings := issue_model.GetCodeOwnersFromReader(ctx, rc, size > setting.UI.MaxDisplayFileSize)
|
||||
if len(warnings) > 0 {
|
||||
|
|
|
@ -71,7 +71,7 @@ func PullRequestCodeOwnersReview(ctx context.Context, issue *issues_model.Issue,
|
|||
}
|
||||
|
||||
var rules []*issues_model.CodeOwnerRule
|
||||
for _, file := range []string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"} {
|
||||
for _, file := range []string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS", ".forgejo/CODEOWNERS"} {
|
||||
if blob, err := commit.GetBlobByPath(file); err == nil {
|
||||
rc, size, err := blob.NewTruncatedReader(setting.UI.MaxDisplayFileSize)
|
||||
if err == nil {
|
||||
|
|
|
@ -26,17 +26,16 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCodeOwner(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||
func CodeOwnerTestCommon(t *testing.T, u *url.URL, codeownerTest CodeownerTest) {
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
// Create the repo.
|
||||
repo, _, f := tests.CreateDeclarativeRepo(t, user2, "",
|
||||
repo, _, f := tests.CreateDeclarativeRepo(t, user2, codeownerTest.Name,
|
||||
[]unit_model.Type{unit_model.TypePullRequests}, nil,
|
||||
[]*files_service.ChangeRepoFile{
|
||||
{
|
||||
Operation: "create",
|
||||
TreePath: "CODEOWNERS",
|
||||
TreePath: codeownerTest.Path,
|
||||
ContentReader: strings.NewReader("README.md @user5\ntest-file @user4"),
|
||||
},
|
||||
},
|
||||
|
@ -84,11 +83,11 @@ func TestCodeOwner(t *testing.T) {
|
|||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
session := loginUser(t, "user1")
|
||||
testRepoFork(t, session, user2.Name, repo.Name, "user1", "repo1")
|
||||
testRepoFork(t, session, user2.Name, repo.Name, "user1", codeownerTest.Name)
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user1", Name: "repo1"})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user1", Name: codeownerTest.Name})
|
||||
|
||||
r := fmt.Sprintf("%suser1/repo1.git", u.String())
|
||||
r := fmt.Sprintf("%suser1/%s.git", u.String(), codeownerTest.Name)
|
||||
remoteURL, _ := url.Parse(r)
|
||||
remoteURL.User = url.UserPassword("user2", userPassword)
|
||||
doGitAddRemote(dstPath, "forked", remoteURL)(t)
|
||||
|
@ -142,7 +141,7 @@ func TestCodeOwner(t *testing.T) {
|
|||
|
||||
session := loginUser(t, "user1")
|
||||
|
||||
r := fmt.Sprintf("%suser1/repo1.git", u.String())
|
||||
r := fmt.Sprintf("%suser1/%s.git", u.String(), codeownerTest.Name)
|
||||
remoteURL, _ := url.Parse(r)
|
||||
remoteURL.User = url.UserPassword("user1", userPassword)
|
||||
doGitAddRemote(dstPath, "forked-2", remoteURL)(t)
|
||||
|
@ -150,8 +149,8 @@ func TestCodeOwner(t *testing.T) {
|
|||
err := git.NewCommand(git.DefaultContext, "push", "forked-2", "HEAD:branch").Run(&git.RunOpts{Dir: dstPath})
|
||||
require.NoError(t, err)
|
||||
|
||||
req := NewRequestWithValues(t, "POST", repo.FullName()+"/compare/main...user1/repo1:branch", map[string]string{
|
||||
"_csrf": GetCSRF(t, session, repo.FullName()+"/compare/main...user1/repo1:branch"),
|
||||
req := NewRequestWithValues(t, "POST", repo.FullName()+"/compare/main...user1/"+codeownerTest.Name+":branch", map[string]string{
|
||||
"_csrf": GetCSRF(t, session, repo.FullName()+"/compare/main...user1/"+codeownerTest.Name+":branch"),
|
||||
"title": "pull request",
|
||||
})
|
||||
session.MakeRequest(t, req, http.StatusOK)
|
||||
|
@ -196,5 +195,23 @@ func TestCodeOwner(t *testing.T) {
|
|||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{BaseRepoID: repo.ID, HeadBranch: "user2/codeowner-private"})
|
||||
unittest.AssertExistsIf(t, false, &issues_model.Review{IssueID: pr.IssueID, Type: issues_model.ReviewTypeRequest, ReviewerID: 5})
|
||||
})
|
||||
}
|
||||
|
||||
type CodeownerTest struct {
|
||||
Name string
|
||||
Path string
|
||||
}
|
||||
|
||||
func TestCodeOwner(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
||||
tests := []CodeownerTest{
|
||||
{Name: "root", Path: "CODEOWNERS"},
|
||||
{Name: "docs", Path: "docs/CODEOWNERS"},
|
||||
{Name: "gitea", Path: ".gitea/CODEOWNERS"},
|
||||
{Name: "forgejo", Path: ".forgejo/CODEOWNERS"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
CodeOwnerTestCommon(t, u, test)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue