Skip to content

Pull request updates will also trigger code owners review requests #33744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f0dd070
pull request updates will also trigger code owners review requests
lunny Feb 27, 2025
172178c
merge the code owner file list
lunny Feb 28, 2025
fb1fb03
Merge branch 'main' into lunny/add_reviewer_notifier_pr_sync
lunny Feb 28, 2025
b31d067
Only request code owner when syncing commits files ownered by the cod…
lunny Mar 2, 2025
dd1eb52
Use a structure as parameters for TestPullrequestTask
lunny Mar 7, 2025
5b0fb1e
Merge branch 'main' into lunny/add_reviewer_notifier_pr_sync
lunny Mar 8, 2025
449ed5b
Add test for PullRequestCodeOwnersReview and PullRequestCodeOwnersRev…
lunny Mar 11, 2025
64db717
Merge branch 'main' into lunny/add_reviewer_notifier_pr_sync
lunny Mar 11, 2025
6f79267
Update services/issue/pull.go
wxiaoguang Mar 12, 2025
f8b02f7
Add comment for IsSync
lunny Mar 13, 2025
480de54
Merge branch 'lunny/add_reviewer_notifier_pr_sync' of github.com:lunn…
lunny Mar 13, 2025
2aee564
Fix test
lunny Mar 13, 2025
afb2be2
Merge branch 'main' into lunny/add_reviewer_notifier_pr_sync
lunny Mar 13, 2025
4961418
improve the comment for IsSync
lunny Mar 13, 2025
47d3234
Merge branch 'main' into lunny/add_reviewer_notifier_pr_sync
lunny Mar 13, 2025
aa9dd18
Merge branch 'main' into lunny/add_reviewer_notifier_pr_sync
GiteaBot Mar 14, 2025
aaf7915
Merge branch 'main' into lunny/add_reviewer_notifier_pr_sync
GiteaBot Mar 14, 2025
10ce667
Merge branch 'main' into lunny/add_reviewer_notifier_pr_sync
GiteaBot Mar 14, 2025
a950281
Fix test
lunny Mar 14, 2025
f03bc81
Merge branch 'lunny/add_reviewer_notifier_pr_sync' of github.com:lunn…
lunny Mar 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions routers/web/repo/view_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"image"
"io"
"path"
"slices"
"strings"

git_model "code.gitea.io/gitea/models/git"
Expand Down Expand Up @@ -79,7 +78,7 @@ func prepareToRenderFile(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 issue_service.IsCodeOwnerFile(ctx.Repo.TreePath) {
if data, err := blob.GetBlobContent(setting.UI.MaxDisplayFileSize); err == nil {
_, warnings := issue_model.GetCodeOwnersFromContent(ctx, data)
if len(warnings) > 0 {
Expand Down
6 changes: 5 additions & 1 deletion services/issue/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ func ChangeTitle(ctx context.Context, issue *issues_model.Issue, doer *user_mode

var reviewNotifiers []*ReviewRequestNotifier
if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issues_model.HasWorkInProgressPrefix(title) {
if err := issue.LoadPullRequest(ctx); err != nil {
return err
}

var err error
reviewNotifiers, err = PullRequestCodeOwnersReview(ctx, issue, issue.PullRequest)
reviewNotifiers, err = PullRequestCodeOwnersReview(ctx, issue.PullRequest)
if err != nil {
log.Error("PullRequestCodeOwnersReview: %v", err)
}
Expand Down
18 changes: 13 additions & 5 deletions services/issue/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package issue
import (
"context"
"fmt"
"slices"
"time"

issues_model "code.gitea.io/gitea/models/issues"
Expand Down Expand Up @@ -40,17 +41,23 @@ type ReviewRequestNotifier struct {
ReviewTeam *org_model.Team
}

func PullRequestCodeOwnersReview(ctx context.Context, issue *issues_model.Issue, pr *issues_model.PullRequest) ([]*ReviewRequestNotifier, error) {
files := []string{"CODEOWNERS", "docs/CODEOWNERS", ".gitea/CODEOWNERS"}
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) {
if err := pr.LoadIssue(ctx); err != nil {
return nil, err
}
issue := pr.Issue
if pr.IsWorkInProgress(ctx) {
return nil, nil
}

if err := pr.LoadHeadRepo(ctx); err != nil {
return nil, err
}

if err := pr.LoadBaseRepo(ctx); err != nil {
return nil, err
}
Expand All @@ -71,7 +78,8 @@ func PullRequestCodeOwnersReview(ctx context.Context, issue *issues_model.Issue,
}

var data string
for _, file := range files {

for _, file := range codeOwnerFiles {
if blob, err := commit.GetBlobByPath(file); err == nil {
data, err = blob.GetBlobContent(setting.UI.MaxDisplayFileSize)
if err == nil {
Expand Down
11 changes: 10 additions & 1 deletion services/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
}

if !pr.IsWorkInProgress(ctx) {
reviewNotifiers, err = issue_service.PullRequestCodeOwnersReview(ctx, issue, pr)
reviewNotifiers, err = issue_service.PullRequestCodeOwnersReview(ctx, pr)
if err != nil {
return err
}
Expand Down Expand Up @@ -453,6 +453,15 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
}
}

if !pr.IsWorkInProgress(ctx) {
reviewNotifiers, err := issue_service.PullRequestCodeOwnersReview(ctx, pr)
if err != nil {
log.Error("PullRequestCodeOwnersReview: %v", err)
} else {
issue_service.ReviewRequestNotify(ctx, pr.Issue, doer, reviewNotifiers)
}
}

notify_service.PullRequestSynchronized(ctx, doer, pr)
}
}
Expand Down
Loading