mirror of
https://github.com/go-gitea/gitea.git
synced 2026-01-17 01:20:37 +00:00
Move assign project when creating pull request to the same database transaction (#36244)
This commit is contained in:
@@ -1390,6 +1390,7 @@ func CompareAndPullRequestPost(ctx *context.Context) {
|
|||||||
AssigneeIDs: assigneeIDs,
|
AssigneeIDs: assigneeIDs,
|
||||||
Reviewers: validateRet.Reviewers,
|
Reviewers: validateRet.Reviewers,
|
||||||
TeamReviewers: validateRet.TeamReviewers,
|
TeamReviewers: validateRet.TeamReviewers,
|
||||||
|
ProjectID: projectID,
|
||||||
}
|
}
|
||||||
if err := pull_service.NewPullRequest(ctx, prOpts); err != nil {
|
if err := pull_service.NewPullRequest(ctx, prOpts); err != nil {
|
||||||
switch {
|
switch {
|
||||||
@@ -1441,15 +1442,6 @@ func CompareAndPullRequestPost(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if projectID > 0 && ctx.Repo.CanWrite(unit.TypeProjects) {
|
|
||||||
if err := issues_model.IssueAssignOrRemoveProject(ctx, pullIssue, ctx.Doer, projectID, 0); err != nil {
|
|
||||||
if !errors.Is(err, util.ErrPermissionDenied) {
|
|
||||||
ctx.ServerError("IssueAssignOrRemoveProject", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
|
log.Trace("Pull request created: %d/%d", repo.ID, pullIssue.ID)
|
||||||
ctx.JSONRedirect(pullIssue.Link())
|
ctx.JSONRedirect(pullIssue.Link())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -405,13 +405,6 @@ func (f *NewPackagistHookForm) Validate(req *http.Request, errs binding.Errors)
|
|||||||
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
|
||||||
}
|
}
|
||||||
|
|
||||||
// .___
|
|
||||||
// | | ______ ________ __ ____
|
|
||||||
// | |/ ___// ___/ | \_/ __ \
|
|
||||||
// | |\___ \ \___ \| | /\ ___/
|
|
||||||
// |___/____ >____ >____/ \___ >
|
|
||||||
// \/ \/ \/
|
|
||||||
|
|
||||||
// CreateIssueForm form for creating issue
|
// CreateIssueForm form for creating issue
|
||||||
type CreateIssueForm struct {
|
type CreateIssueForm struct {
|
||||||
Title string `binding:"Required;MaxSize(255)"`
|
Title string `binding:"Required;MaxSize(255)"`
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ type NewPullRequestOptions struct {
|
|||||||
AssigneeIDs []int64
|
AssigneeIDs []int64
|
||||||
Reviewers []*user_model.User
|
Reviewers []*user_model.User
|
||||||
TeamReviewers []*organization.Team
|
TeamReviewers []*organization.Team
|
||||||
|
ProjectID int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPullRequest creates new pull request with labels for repository.
|
// NewPullRequest creates new pull request with labels for repository.
|
||||||
@@ -67,11 +68,13 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
|
|||||||
|
|
||||||
// user should be a collaborator or a member of the organization for base repo
|
// user should be a collaborator or a member of the organization for base repo
|
||||||
canCreate := issue.Poster.IsAdmin || pr.Flow == issues_model.PullRequestFlowAGit
|
canCreate := issue.Poster.IsAdmin || pr.Flow == issues_model.PullRequestFlowAGit
|
||||||
|
canAssignProject := canCreate
|
||||||
if !canCreate {
|
if !canCreate {
|
||||||
canCreate, err := repo_model.IsOwnerMemberCollaborator(ctx, repo, issue.Poster.ID)
|
canCreate, err := repo_model.IsOwnerMemberCollaborator(ctx, repo, issue.Poster.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
canAssignProject = canCreate
|
||||||
|
|
||||||
if !canCreate {
|
if !canCreate {
|
||||||
// or user should have write permission in the head repo
|
// or user should have write permission in the head repo
|
||||||
@@ -85,6 +88,7 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
|
|||||||
if !perm.CanWrite(unit.TypeCode) {
|
if !perm.CanWrite(unit.TypeCode) {
|
||||||
return issues_model.ErrMustCollaborator
|
return issues_model.ErrMustCollaborator
|
||||||
}
|
}
|
||||||
|
canAssignProject = perm.CanWrite(unit.TypeProjects)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +121,12 @@ func NewPullRequest(ctx context.Context, opts *NewPullRequestOptions) error {
|
|||||||
assigneeCommentMap[assigneeID] = comment
|
assigneeCommentMap[assigneeID] = comment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.ProjectID > 0 && canAssignProject {
|
||||||
|
if err := issues_model.IssueAssignOrRemoveProject(ctx, issue, issue.Poster, opts.ProjectID, 0); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pr.Issue = issue
|
pr.Issue = issue
|
||||||
issue.PullRequest = pr
|
issue.PullRequest = pr
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user