Return the full rejection message and errors in flash errors (#13221)
Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
48a80096bb
commit
965861043a
9 changed files with 128 additions and 25 deletions
|
@ -355,7 +355,16 @@ func CreateBranch(ctx *context.Context, form auth.NewBranchForm) {
|
|||
if len(e.Message) == 0 {
|
||||
ctx.Flash.Error(ctx.Tr("repo.editor.push_rejected_no_message"))
|
||||
} else {
|
||||
ctx.Flash.Error(ctx.Tr("repo.editor.push_rejected", utils.SanitizeFlashErrorString(e.Message)))
|
||||
flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{
|
||||
"Message": ctx.Tr("repo.editor.push_rejected"),
|
||||
"Summary": ctx.Tr("repo.editor.push_rejected_summary"),
|
||||
"Details": utils.SanitizeFlashErrorString(e.Message),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("UpdatePullRequest.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.Flash.Error(flashError)
|
||||
}
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL())
|
||||
return
|
||||
|
|
|
@ -293,10 +293,28 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
|||
if len(errPushRej.Message) == 0 {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.push_rejected_no_message"), tplEditFile, &form)
|
||||
} else {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.push_rejected", utils.SanitizeFlashErrorString(errPushRej.Message)), tplEditFile, &form)
|
||||
flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{
|
||||
"Message": ctx.Tr("repo.editor.push_rejected"),
|
||||
"Summary": ctx.Tr("repo.editor.push_rejected_summary"),
|
||||
"Details": utils.SanitizeFlashErrorString(errPushRej.Message),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("editFilePost.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.RenderWithErr(flashError, tplEditFile, &form)
|
||||
}
|
||||
} else {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.fail_to_update_file", form.TreePath, utils.SanitizeFlashErrorString(err.Error())), tplEditFile, &form)
|
||||
flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{
|
||||
"Message": ctx.Tr("repo.editor.fail_to_update_file", form.TreePath),
|
||||
"Summary": ctx.Tr("repo.editor.fail_to_update_file_summary"),
|
||||
"Details": utils.SanitizeFlashErrorString(err.Error()),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("editFilePost.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.RenderWithErr(flashError, tplEditFile, &form)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -464,7 +482,16 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
|
|||
if len(errPushRej.Message) == 0 {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.push_rejected_no_message"), tplDeleteFile, &form)
|
||||
} else {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.push_rejected", utils.SanitizeFlashErrorString(errPushRej.Message)), tplDeleteFile, &form)
|
||||
flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{
|
||||
"Message": ctx.Tr("repo.editor.push_rejected"),
|
||||
"Summary": ctx.Tr("repo.editor.push_rejected_summary"),
|
||||
"Details": utils.SanitizeFlashErrorString(errPushRej.Message),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("DeleteFilePost.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.RenderWithErr(flashError, tplDeleteFile, &form)
|
||||
}
|
||||
} else {
|
||||
ctx.ServerError("DeleteRepoFile", err)
|
||||
|
@ -656,7 +683,16 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
|
|||
if len(errPushRej.Message) == 0 {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.push_rejected_no_message"), tplUploadFile, &form)
|
||||
} else {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.push_rejected", utils.SanitizeFlashErrorString(errPushRej.Message)), tplUploadFile, &form)
|
||||
flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{
|
||||
"Message": ctx.Tr("repo.editor.push_rejected"),
|
||||
"Summary": ctx.Tr("repo.editor.push_rejected_summary"),
|
||||
"Details": utils.SanitizeFlashErrorString(errPushRej.Message),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("UploadFilePost.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.RenderWithErr(flashError, tplUploadFile, &form)
|
||||
}
|
||||
} else {
|
||||
// os.ErrNotExist - upload file missing in the intervening time?!
|
||||
|
|
|
@ -723,7 +723,16 @@ func UpdatePullRequest(ctx *context.Context) {
|
|||
if err = pull_service.Update(issue.PullRequest, ctx.User, message); err != nil {
|
||||
if models.IsErrMergeConflicts(err) {
|
||||
conflictError := err.(models.ErrMergeConflicts)
|
||||
ctx.Flash.Error(ctx.Tr("repo.pulls.merge_conflict", utils.SanitizeFlashErrorString(conflictError.StdErr), utils.SanitizeFlashErrorString(conflictError.StdOut)))
|
||||
flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{
|
||||
"Message": ctx.Tr("repo.pulls.merge_conflict"),
|
||||
"Summary": ctx.Tr("repo.pulls.merge_conflict_summary"),
|
||||
"Details": utils.SanitizeFlashErrorString(conflictError.StdErr) + "<br>" + utils.SanitizeFlashErrorString(conflictError.StdOut),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("UpdatePullRequest.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.Flash.Error(flashError)
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(issue.Index))
|
||||
return
|
||||
}
|
||||
|
@ -846,12 +855,30 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
|
|||
return
|
||||
} else if models.IsErrMergeConflicts(err) {
|
||||
conflictError := err.(models.ErrMergeConflicts)
|
||||
ctx.Flash.Error(ctx.Tr("repo.pulls.merge_conflict", utils.SanitizeFlashErrorString(conflictError.StdErr), utils.SanitizeFlashErrorString(conflictError.StdOut)))
|
||||
flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{
|
||||
"Message": ctx.Tr("repo.editor.merge_conflict"),
|
||||
"Summary": ctx.Tr("repo.editor.merge_conflict_summary"),
|
||||
"Details": utils.SanitizeFlashErrorString(conflictError.StdErr) + "<br>" + utils.SanitizeFlashErrorString(conflictError.StdOut),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("MergePullRequest.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.Flash.Error(flashError)
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
|
||||
return
|
||||
} else if models.IsErrRebaseConflicts(err) {
|
||||
conflictError := err.(models.ErrRebaseConflicts)
|
||||
ctx.Flash.Error(ctx.Tr("repo.pulls.rebase_conflict", utils.SanitizeFlashErrorString(conflictError.CommitSHA), utils.SanitizeFlashErrorString(conflictError.StdErr), utils.SanitizeFlashErrorString(conflictError.StdOut)))
|
||||
flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{
|
||||
"Message": ctx.Tr("repo.editor.rebase_conflict", utils.SanitizeFlashErrorString(conflictError.CommitSHA)),
|
||||
"Summary": ctx.Tr("repo.editor.rebase_conflict_summary"),
|
||||
"Details": utils.SanitizeFlashErrorString(conflictError.StdErr) + "<br>" + utils.SanitizeFlashErrorString(conflictError.StdOut),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("MergePullRequest.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.Flash.Error(flashError)
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
|
||||
return
|
||||
} else if models.IsErrMergeUnrelatedHistories(err) {
|
||||
|
@ -871,7 +898,16 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
|
|||
if len(message) == 0 {
|
||||
ctx.Flash.Error(ctx.Tr("repo.pulls.push_rejected_no_message"))
|
||||
} else {
|
||||
ctx.Flash.Error(ctx.Tr("repo.pulls.push_rejected", utils.SanitizeFlashErrorString(pushrejErr.Message)))
|
||||
flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{
|
||||
"Message": ctx.Tr("repo.pulls.push_rejected"),
|
||||
"Summary": ctx.Tr("repo.pulls.push_rejected_summary"),
|
||||
"Details": utils.SanitizeFlashErrorString(pushrejErr.Message),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("MergePullRequest.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.Flash.Error(flashError)
|
||||
}
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pr.Index))
|
||||
return
|
||||
|
@ -986,7 +1022,16 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
|
|||
if len(message) == 0 {
|
||||
ctx.Flash.Error(ctx.Tr("repo.pulls.push_rejected_no_message"))
|
||||
} else {
|
||||
ctx.Flash.Error(ctx.Tr("repo.pulls.push_rejected", utils.SanitizeFlashErrorString(pushrejErr.Message)))
|
||||
flashError, err := ctx.HTMLString(string(tplAlertDetails), map[string]interface{}{
|
||||
"Message": ctx.Tr("repo.pulls.push_rejected"),
|
||||
"Summary": ctx.Tr("repo.pulls.push_rejected_summary"),
|
||||
"Details": utils.SanitizeFlashErrorString(pushrejErr.Message),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.ServerError("CompareAndPullRequest.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.Flash.Error(flashError)
|
||||
}
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/pulls/" + com.ToStr(pullIssue.Index))
|
||||
return
|
||||
|
|
|
@ -24,7 +24,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
tplCreate base.TplName = "repo/create"
|
||||
tplCreate base.TplName = "repo/create"
|
||||
tplAlertDetails base.TplName = "base/alert_details"
|
||||
)
|
||||
|
||||
// MustBeNotEmpty render when a repo is a empty git dir
|
||||
|
|
|
@ -41,12 +41,6 @@ func IsValidSlackChannel(channelName string) bool {
|
|||
|
||||
// SanitizeFlashErrorString will sanitize a flash error string
|
||||
func SanitizeFlashErrorString(x string) string {
|
||||
runes := []rune(x)
|
||||
|
||||
if len(runes) > 512 {
|
||||
x = "..." + string(runes[len(runes)-512:])
|
||||
}
|
||||
|
||||
return strings.ReplaceAll(html.EscapeString(x), "\n", "<br>")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue