@ -31,8 +31,6 @@ import (
"code.gitea.io/gitea/services/gitdiff"
"code.gitea.io/gitea/services/gitdiff"
pull_service "code.gitea.io/gitea/services/pull"
pull_service "code.gitea.io/gitea/services/pull"
repo_service "code.gitea.io/gitea/services/repository"
repo_service "code.gitea.io/gitea/services/repository"
"github.com/unknwon/com"
)
)
const (
const (
@ -732,7 +730,7 @@ func UpdatePullRequest(ctx *context.Context) {
// ToDo: add check if maintainers are allowed to change branch ... (need migration & co)
// ToDo: add check if maintainers are allowed to change branch ... (need migration & co)
if ! allowedUpdate {
if ! allowedUpdate {
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.update_not_allowed" ) )
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.update_not_allowed" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( issue . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( issue . Index ) )
return
return
}
}
@ -752,18 +750,18 @@ func UpdatePullRequest(ctx *context.Context) {
return
return
}
}
ctx . Flash . Error ( flashError )
ctx . Flash . Error ( flashError )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( issue . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( issue . Index ) )
return
return
}
}
ctx . Flash . Error ( err . Error ( ) )
ctx . Flash . Error ( err . Error ( ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( issue . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( issue . Index ) )
return
return
}
}
time . Sleep ( 1 * time . Second )
time . Sleep ( 1 * time . Second )
ctx . Flash . Success ( ctx . Tr ( "repo.pulls.update_branch_success" ) )
ctx . Flash . Success ( ctx . Tr ( "repo.pulls.update_branch_success" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( issue . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( issue . Index ) )
}
}
// MergePullRequest response for merging pull request
// MergePullRequest response for merging pull request
@ -775,11 +773,11 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
if issue . IsClosed {
if issue . IsClosed {
if issue . IsPull {
if issue . IsPull {
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.is_closed" ) )
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.is_closed" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( issue . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( issue . Index ) )
return
return
}
}
ctx . Flash . Error ( ctx . Tr ( "repo.issues.closed_title" ) )
ctx . Flash . Error ( ctx . Tr ( "repo.issues.closed_title" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/issues/" + com . ToStr ( issue . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/issues/" + fmt . Sprint ( issue . Index ) )
return
return
}
}
@ -792,25 +790,25 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
}
}
if ! allowedMerge {
if ! allowedMerge {
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.update_not_allowed" ) )
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.update_not_allowed" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( issue . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( issue . Index ) )
return
return
}
}
if ! pr . CanAutoMerge ( ) {
if ! pr . CanAutoMerge ( ) {
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.no_merge_not_ready" ) )
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.no_merge_not_ready" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( issue . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( issue . Index ) )
return
return
}
}
if pr . HasMerged {
if pr . HasMerged {
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.has_merged" ) )
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.has_merged" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( issue . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( issue . Index ) )
return
return
}
}
if pr . IsWorkInProgress ( ) {
if pr . IsWorkInProgress ( ) {
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.no_merge_wip" ) )
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.no_merge_wip" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pr . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pr . Index ) )
return
return
}
}
@ -824,14 +822,14 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
return
return
} else if ! isRepoAdmin {
} else if ! isRepoAdmin {
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.no_merge_not_ready" ) )
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.no_merge_not_ready" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pr . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pr . Index ) )
return
return
}
}
}
}
if ctx . HasError ( ) {
if ctx . HasError ( ) {
ctx . Flash . Error ( ctx . Data [ "ErrorMsg" ] . ( string ) )
ctx . Flash . Error ( ctx . Data [ "ErrorMsg" ] . ( string ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pr . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pr . Index ) )
return
return
}
}
@ -863,14 +861,14 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
if ! noDeps {
if ! noDeps {
ctx . Flash . Error ( ctx . Tr ( "repo.issues.dependency.pr_close_blocked" ) )
ctx . Flash . Error ( ctx . Tr ( "repo.issues.dependency.pr_close_blocked" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pr . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pr . Index ) )
return
return
}
}
if err = pull_service . Merge ( pr , ctx . User , ctx . Repo . GitRepo , models . MergeStyle ( form . Do ) , message ) ; err != nil {
if err = pull_service . Merge ( pr , ctx . User , ctx . Repo . GitRepo , models . MergeStyle ( form . Do ) , message ) ; err != nil {
if models . IsErrInvalidMergeStyle ( err ) {
if models . IsErrInvalidMergeStyle ( err ) {
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.invalid_merge_option" ) )
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.invalid_merge_option" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pr . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pr . Index ) )
return
return
} else if models . IsErrMergeConflicts ( err ) {
} else if models . IsErrMergeConflicts ( err ) {
conflictError := err . ( models . ErrMergeConflicts )
conflictError := err . ( models . ErrMergeConflicts )
@ -884,7 +882,7 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
return
return
}
}
ctx . Flash . Error ( flashError )
ctx . Flash . Error ( flashError )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pr . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pr . Index ) )
return
return
} else if models . IsErrRebaseConflicts ( err ) {
} else if models . IsErrRebaseConflicts ( err ) {
conflictError := err . ( models . ErrRebaseConflicts )
conflictError := err . ( models . ErrRebaseConflicts )
@ -898,17 +896,17 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
return
return
}
}
ctx . Flash . Error ( flashError )
ctx . Flash . Error ( flashError )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pr . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pr . Index ) )
return
return
} else if models . IsErrMergeUnrelatedHistories ( err ) {
} else if models . IsErrMergeUnrelatedHistories ( err ) {
log . Debug ( "MergeUnrelatedHistories error: %v" , err )
log . Debug ( "MergeUnrelatedHistories error: %v" , err )
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.unrelated_histories" ) )
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.unrelated_histories" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pr . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pr . Index ) )
return
return
} else if git . IsErrPushOutOfDate ( err ) {
} else if git . IsErrPushOutOfDate ( err ) {
log . Debug ( "MergePushOutOfDate error: %v" , err )
log . Debug ( "MergePushOutOfDate error: %v" , err )
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.merge_out_of_date" ) )
ctx . Flash . Error ( ctx . Tr ( "repo.pulls.merge_out_of_date" ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pr . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pr . Index ) )
return
return
} else if git . IsErrPushRejected ( err ) {
} else if git . IsErrPushRejected ( err ) {
log . Debug ( "MergePushRejected error: %v" , err )
log . Debug ( "MergePushRejected error: %v" , err )
@ -928,7 +926,7 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
}
}
ctx . Flash . Error ( flashError )
ctx . Flash . Error ( flashError )
}
}
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pr . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pr . Index ) )
return
return
}
}
ctx . ServerError ( "Merge" , err )
ctx . ServerError ( "Merge" , err )
@ -941,7 +939,7 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
}
}
log . Trace ( "Pull request merged: %d" , pr . ID )
log . Trace ( "Pull request merged: %d" , pr . ID )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pr . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pr . Index ) )
}
}
func stopTimerIfAvailable ( user * models . User , issue * models . Issue ) error {
func stopTimerIfAvailable ( user * models . User , issue * models . Issue ) error {
@ -1052,7 +1050,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
}
}
ctx . Flash . Error ( flashError )
ctx . Flash . Error ( flashError )
}
}
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pullIssue . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pullIssue . Index ) )
return
return
}
}
ctx . ServerError ( "NewPullRequest" , err )
ctx . ServerError ( "NewPullRequest" , err )
@ -1060,7 +1058,7 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
}
}
log . Trace ( "Pull request created: %d/%d" , repo . ID , pullIssue . ID )
log . Trace ( "Pull request created: %d/%d" , repo . ID , pullIssue . ID )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + com . ToStr ( pullIssue . Index ) )
ctx . Redirect ( ctx . Repo . RepoLink + "/pulls/" + fmt . Sprint ( pullIssue . Index ) )
}
}
// TriggerTask response for a trigger task request
// TriggerTask response for a trigger task request
@ -1159,7 +1157,7 @@ func CleanUpPullRequest(ctx *context.Context) {
defer func ( ) {
defer func ( ) {
ctx . JSON ( 200 , map [ string ] interface { } {
ctx . JSON ( 200 , map [ string ] interface { } {
"redirect" : pr . BaseRepo . Link ( ) + "/pulls/" + com . ToStr ( issue . Index ) ,
"redirect" : pr . BaseRepo . Link ( ) + "/pulls/" + fmt . Sprint ( issue . Index ) ,
} )
} )
} ( )
} ( )