- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 6.2k
 
Add reviewers selection to new pull request form #26596
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
Changes from all commits
12df5bd
              f1a361f
              412a0d0
              2e86853
              d4bdab0
              d4a987e
              ec32e69
              fb674ba
              23bea17
              7fedc09
              bd006c8
              efb4d30
              62d8403
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| 
          
            
          
           | 
    @@ -16,6 +16,8 @@ import ( | |||
| "code.gitea.io/gitea/models/db" | ||||
| git_model "code.gitea.io/gitea/models/git" | ||||
| issues_model "code.gitea.io/gitea/models/issues" | ||||
| "code.gitea.io/gitea/models/organization" | ||||
| access_model "code.gitea.io/gitea/models/perm/access" | ||||
| repo_model "code.gitea.io/gitea/models/repo" | ||||
| user_model "code.gitea.io/gitea/models/user" | ||||
| "code.gitea.io/gitea/modules/base" | ||||
| 
        
          
        
         | 
    @@ -37,7 +39,7 @@ import ( | |||
| var pullWorkingPool = sync.NewExclusivePool() | ||||
| 
     | 
||||
| // NewPullRequest creates new pull request with labels for repository. | ||||
| func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *issues_model.Issue, labelIDs []int64, uuids []string, pr *issues_model.PullRequest, assigneeIDs []int64) error { | ||||
| func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *issues_model.Issue, labelIDs []int64, uuids []string, pr *issues_model.PullRequest, assigneeIDs, reviewerIDs []int64) error { | ||||
| prCtx, cancel, err := createTemporaryRepoForPR(ctx, pr) | ||||
| if err != nil { | ||||
| if !git_model.IsErrBranchNotExist(err) { | ||||
| 
          
            
          
           | 
    @@ -80,6 +82,42 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss | |||
| assigneeCommentMap[assigneeID] = comment | ||||
| } | ||||
| 
     | 
||||
| for _, reviewerID := range reviewerIDs { | ||||
| // negative reviewIDs represent team requests | ||||
| if reviewerID < 0 { | ||||
| team, err := organization.GetTeamByID(ctx, -reviewerID) | ||||
| if err != nil { | ||||
| return err | ||||
| } | ||||
| err = issue_service.IsValidTeamReviewRequest(ctx, team, issue.Poster, true, issue) | ||||
| if err != nil { | ||||
| return err | ||||
| } | ||||
| _, err = issue_service.TeamReviewRequest(ctx, issue, issue.Poster, team, true) | ||||
| if err != nil { | ||||
| return err | ||||
| } | ||||
| continue | ||||
| } | ||||
| 
     | 
||||
| reviewer, err := user_model.GetUserByID(ctx, reviewerID) | ||||
| if err != nil { | ||||
| return err | ||||
| } | ||||
| permDoer, err := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster) | ||||
| if err != nil { | ||||
| return err | ||||
| } | ||||
| err = issue_service.IsValidReviewRequest(ctx, reviewer, issue.Poster, true, issue, &permDoer) | ||||
| if err != nil { | ||||
| return err | ||||
| } | ||||
| _, err = issue_service.ReviewRequest(ctx, issue, issue.Poster, reviewer, true) | ||||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also creates the review request notification. So the user will receive the "review requested" notification before the "pull request created" notification. If you look at the assignee code, they are first added without sending a notification. The notification is sent later on: Line 198 in 62d8403 
 Due to this, it also seems like the UI notification cannot be created. I'm seeing this in the logs: 
 I suspect this is because the notifier runs in a different transaction and does not "see" the newly created PR yet?  | 
||||
| if err != nil { | ||||
| return err | ||||
| } | ||||
| } | ||||
| 
     | 
||||
| pr.Issue = issue | ||||
| issue.PullRequest = pr | ||||
| 
     | 
||||
| 
          
            
          
           | 
    ||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this can be moved into RetrieveRepoMetas, where similar code exists for populating
ctx.Data["Assignees"]?