merge the code owner file list

This commit is contained in:
Lunny Xiao 2025-02-28 13:58:33 -08:00
parent f0dd070ef1
commit 172178c367
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 10 additions and 4 deletions

View File

@ -9,7 +9,6 @@ import (
"image" "image"
"io" "io"
"path" "path"
"slices"
"strings" "strings"
git_model "code.gitea.io/gitea/models/git" git_model "code.gitea.io/gitea/models/git"
@ -79,7 +78,7 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
if workFlowErr != nil { if workFlowErr != nil {
ctx.Data["FileError"] = ctx.Locale.Tr("actions.runs.invalid_workflow_helper", workFlowErr.Error()) 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 issue_service.IsCodeOwnerFile(ctx.Repo.TreePath) {
if data, err := blob.GetBlobContent(setting.UI.MaxDisplayFileSize); err == nil { if data, err := blob.GetBlobContent(setting.UI.MaxDisplayFileSize); err == nil {
_, warnings := issue_model.GetCodeOwnersFromContent(ctx, data) _, warnings := issue_model.GetCodeOwnersFromContent(ctx, data)
if len(warnings) > 0 { if len(warnings) > 0 {

View File

@ -6,6 +6,7 @@ package issue
import ( import (
"context" "context"
"fmt" "fmt"
"slices"
"time" "time"
issues_model "code.gitea.io/gitea/models/issues" issues_model "code.gitea.io/gitea/models/issues"
@ -40,6 +41,12 @@ type ReviewRequestNotifier struct {
ReviewTeam *org_model.Team ReviewTeam *org_model.Team
} }
var codeOwnerFiles = []string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"}
func IsCodeOwnerFile(f string) bool {
return slices.Contains(codeOwnerFiles, f)
}
func PullRequestCodeOwnersReview(ctx context.Context, pr *issues_model.PullRequest) ([]*ReviewRequestNotifier, error) { func PullRequestCodeOwnersReview(ctx context.Context, pr *issues_model.PullRequest) ([]*ReviewRequestNotifier, error) {
if err := pr.LoadIssue(ctx); err != nil { if err := pr.LoadIssue(ctx); err != nil {
return nil, err return nil, err
@ -71,8 +78,8 @@ func PullRequestCodeOwnersReview(ctx context.Context, pr *issues_model.PullReque
} }
var data string var data string
files := []string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"}
for _, file := range files { for _, file := range codeOwnerFiles {
if blob, err := commit.GetBlobByPath(file); err == nil { if blob, err := commit.GetBlobByPath(file); err == nil {
data, err = blob.GetBlobContent(setting.UI.MaxDisplayFileSize) data, err = blob.GetBlobContent(setting.UI.MaxDisplayFileSize)
if err == nil { if err == nil {