|
@@ -51,7 +51,7 @@ var (
|
|
|
|
|
|
func MustEnableIssues(c *context.Context) {
|
|
|
if !c.Repo.Repository.EnableIssues {
|
|
|
- c.Handle(404, "MustEnableIssues", nil)
|
|
|
+ c.NotFound()
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -63,7 +63,7 @@ func MustEnableIssues(c *context.Context) {
|
|
|
|
|
|
func MustAllowPulls(c *context.Context) {
|
|
|
if !c.Repo.Repository.AllowsPulls() {
|
|
|
- c.Handle(404, "MustAllowPulls", nil)
|
|
|
+ c.NotFound()
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -77,7 +77,7 @@ func MustAllowPulls(c *context.Context) {
|
|
|
func RetrieveLabels(c *context.Context) {
|
|
|
labels, err := db.GetLabelsByRepoID(c.Repo.Repository.ID)
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "RetrieveLabels.GetLabels", err)
|
|
|
+ c.Error(err, "get labels by repository ID")
|
|
|
return
|
|
|
}
|
|
|
for _, l := range labels {
|
|
@@ -182,14 +182,14 @@ func issues(c *context.Context, isPullList bool) {
|
|
|
SortType: sortType,
|
|
|
})
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "Issues", err)
|
|
|
+ c.Error(err, "list issues")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// Get issue-user relations.
|
|
|
pairs, err := db.GetIssueUsers(repo.ID, posterID, isShowClosed)
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "GetIssueUsers", err)
|
|
|
+ c.Error(err, "get issue-user relations")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -213,14 +213,14 @@ func issues(c *context.Context, isPullList bool) {
|
|
|
// Get milestones.
|
|
|
c.Data["Milestones"], err = db.GetMilestonesByRepoID(repo.ID)
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "GetAllRepoMilestones", err)
|
|
|
+ c.Error(err, "get milestone by repository ID")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// Get assignees.
|
|
|
c.Data["Assignees"], err = repo.GetAssignees()
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "GetAssignees", err)
|
|
|
+ c.Error(err, "get assignees")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -241,7 +241,7 @@ func issues(c *context.Context, isPullList bool) {
|
|
|
c.Data["State"] = "open"
|
|
|
}
|
|
|
|
|
|
- c.HTML(200, ISSUES)
|
|
|
+ c.Success(ISSUES)
|
|
|
}
|
|
|
|
|
|
func Issues(c *context.Context) {
|
|
@@ -264,18 +264,18 @@ func RetrieveRepoMilestonesAndAssignees(c *context.Context, repo *db.Repository)
|
|
|
var err error
|
|
|
c.Data["OpenMilestones"], err = db.GetMilestones(repo.ID, -1, false)
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "GetMilestones", err)
|
|
|
+ c.Error(err, "get open milestones")
|
|
|
return
|
|
|
}
|
|
|
c.Data["ClosedMilestones"], err = db.GetMilestones(repo.ID, -1, true)
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "GetMilestones", err)
|
|
|
+ c.Error(err, "get closed milestones")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
c.Data["Assignees"], err = repo.GetAssignees()
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "GetAssignees", err)
|
|
|
+ c.Error(err, "get assignees")
|
|
|
return
|
|
|
}
|
|
|
}
|
|
@@ -287,7 +287,7 @@ func RetrieveRepoMetas(c *context.Context, repo *db.Repository) []*db.Label {
|
|
|
|
|
|
labels, err := db.GetLabelsByRepoID(repo.ID)
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "GetLabelsByRepoID", err)
|
|
|
+ c.Error(err, "get labels by repository ID")
|
|
|
return nil
|
|
|
}
|
|
|
c.Data["Labels"] = labels
|
|
@@ -345,7 +345,7 @@ func NewIssue(c *context.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- c.HTML(200, ISSUE_NEW)
|
|
|
+ c.Success(ISSUE_NEW)
|
|
|
}
|
|
|
|
|
|
func ValidateRepoMetas(c *context.Context, f form.NewIssue) ([]int64, int64, int64) {
|
|
@@ -382,7 +382,7 @@ func ValidateRepoMetas(c *context.Context, f form.NewIssue) ([]int64, int64, int
|
|
|
if milestoneID > 0 {
|
|
|
c.Data["Milestone"], err = repo.GetMilestoneByID(milestoneID)
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "GetMilestoneByID", err)
|
|
|
+ c.Error(err, "get milestone by ID")
|
|
|
return nil, 0, 0
|
|
|
}
|
|
|
c.Data["milestone_id"] = milestoneID
|
|
@@ -393,7 +393,7 @@ func ValidateRepoMetas(c *context.Context, f form.NewIssue) ([]int64, int64, int
|
|
|
if assigneeID > 0 {
|
|
|
c.Data["Assignee"], err = repo.GetAssigneeByID(assigneeID)
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "GetAssigneeByID", err)
|
|
|
+ c.Error(err, "get assignee by ID")
|
|
|
return nil, 0, 0
|
|
|
}
|
|
|
c.Data["assignee_id"] = assigneeID
|
|
@@ -415,7 +415,7 @@ func NewIssuePost(c *context.Context, f form.NewIssue) {
|
|
|
}
|
|
|
|
|
|
if c.HasError() {
|
|
|
- c.HTML(200, ISSUE_NEW)
|
|
|
+ c.Success(ISSUE_NEW)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -434,7 +434,7 @@ func NewIssuePost(c *context.Context, f form.NewIssue) {
|
|
|
Content: f.Content,
|
|
|
}
|
|
|
if err := db.NewIssue(c.Repo.Repository, issue, labelIDs, attachments); err != nil {
|
|
|
- c.Handle(500, "NewIssue", err)
|
|
|
+ c.Error(err, "new issue")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -445,7 +445,7 @@ func NewIssuePost(c *context.Context, f form.NewIssue) {
|
|
|
func uploadAttachment(c *context.Context, allowedTypes []string) {
|
|
|
file, header, err := c.Req.FormFile("file")
|
|
|
if err != nil {
|
|
|
- c.Error(500, fmt.Sprintf("FormFile: %v", err))
|
|
|
+ c.Error(err, "get file")
|
|
|
return
|
|
|
}
|
|
|
defer file.Close()
|
|
@@ -467,18 +467,18 @@ func uploadAttachment(c *context.Context, allowedTypes []string) {
|
|
|
}
|
|
|
|
|
|
if !allowed {
|
|
|
- c.Error(400, ErrFileTypeForbidden.Error())
|
|
|
+ c.PlainText(http.StatusBadRequest, ErrFileTypeForbidden.Error())
|
|
|
return
|
|
|
}
|
|
|
|
|
|
attach, err := db.NewAttachment(header.Filename, buf, file)
|
|
|
if err != nil {
|
|
|
- c.Error(500, fmt.Sprintf("NewAttachment: %v", err))
|
|
|
+ c.Error(err, "new attachment")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
log.Trace("New attachment uploaded: %s", attach.UUID)
|
|
|
- c.JSON(200, map[string]string{
|
|
|
+ c.JSONSuccess(map[string]string{
|
|
|
"uuid": attach.UUID,
|
|
|
})
|
|
|
}
|
|
@@ -505,7 +505,7 @@ func viewIssue(c *context.Context, isPullList bool) {
|
|
|
|
|
|
issue, err := db.GetIssueByIndex(c.Repo.Repository.ID, index)
|
|
|
if err != nil {
|
|
|
- c.NotFoundOrServerError("GetIssueByIndex", errors.IsIssueNotExist, err)
|
|
|
+ c.NotFoundOrError(err, "get issue by index")
|
|
|
return
|
|
|
}
|
|
|
c.Data["Title"] = issue.Title
|
|
@@ -559,7 +559,7 @@ func viewIssue(c *context.Context, isPullList bool) {
|
|
|
}
|
|
|
labels, err := db.GetLabelsByRepoID(repo.ID)
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "GetLabelsByRepoID", err)
|
|
|
+ c.Error(err, "get labels by repository ID")
|
|
|
return
|
|
|
}
|
|
|
hasSelected := false
|
|
@@ -583,7 +583,7 @@ func viewIssue(c *context.Context, isPullList bool) {
|
|
|
if c.IsLogged {
|
|
|
// Update issue-user.
|
|
|
if err = issue.ReadBy(c.User.ID); err != nil {
|
|
|
- c.Handle(500, "ReadBy", err)
|
|
|
+ c.Error(err, "mark read by")
|
|
|
return
|
|
|
}
|
|
|
}
|
|
@@ -638,8 +638,8 @@ func viewIssue(c *context.Context, isPullList bool) {
|
|
|
branchProtected := false
|
|
|
protectBranch, err := db.GetProtectBranchOfRepoByName(pull.BaseRepoID, pull.HeadBranch)
|
|
|
if err != nil {
|
|
|
- if !errors.IsErrBranchNotExist(err) {
|
|
|
- c.ServerError("GetProtectBranchOfRepoByName", err)
|
|
|
+ if !db.IsErrBranchNotExist(err) {
|
|
|
+ c.Error(err, "get protect branch of repository by name")
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
@@ -661,7 +661,7 @@ func viewIssue(c *context.Context, isPullList bool) {
|
|
|
c.Data["Issue"] = issue
|
|
|
c.Data["IsIssueOwner"] = c.Repo.IsWriter() || (c.IsLogged && issue.IsPoster(c.User.ID))
|
|
|
c.Data["SignInLink"] = conf.Server.Subpath + "/user/login?redirect_to=" + c.Data["Link"].(string)
|
|
|
- c.HTML(200, ISSUE_VIEW)
|
|
|
+ c.Success(ISSUE_VIEW)
|
|
|
}
|
|
|
|
|
|
func ViewIssue(c *context.Context) {
|
|
@@ -675,7 +675,7 @@ func ViewPull(c *context.Context) {
|
|
|
func getActionIssue(c *context.Context) *db.Issue {
|
|
|
issue, err := db.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
|
|
|
if err != nil {
|
|
|
- c.NotFoundOrServerError("GetIssueByIndex", errors.IsIssueNotExist, err)
|
|
|
+ c.NotFoundOrError(err, "get issue by index")
|
|
|
return nil
|
|
|
}
|
|
|
|
|
@@ -695,22 +695,22 @@ func UpdateIssueTitle(c *context.Context) {
|
|
|
}
|
|
|
|
|
|
if !c.IsLogged || (!issue.IsPoster(c.User.ID) && !c.Repo.IsWriter()) {
|
|
|
- c.Error(403)
|
|
|
+ c.Status(http.StatusForbidden)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
title := c.QueryTrim("title")
|
|
|
if len(title) == 0 {
|
|
|
- c.Error(204)
|
|
|
+ c.Status(http.StatusNoContent)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if err := issue.ChangeTitle(c.User, title); err != nil {
|
|
|
- c.Handle(500, "ChangeTitle", err)
|
|
|
+ c.Error(err, "change title")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- c.JSON(200, map[string]interface{}{
|
|
|
+ c.JSONSuccess(map[string]interface{}{
|
|
|
"title": issue.Title,
|
|
|
})
|
|
|
}
|
|
@@ -722,17 +722,17 @@ func UpdateIssueContent(c *context.Context) {
|
|
|
}
|
|
|
|
|
|
if !c.IsLogged || (c.User.ID != issue.PosterID && !c.Repo.IsWriter()) {
|
|
|
- c.Error(403)
|
|
|
+ c.Status(http.StatusForbidden)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
content := c.Query("content")
|
|
|
if err := issue.ChangeContent(c.User, content); err != nil {
|
|
|
- c.Handle(500, "ChangeContent", err)
|
|
|
+ c.Error(err, "change content")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- c.JSON(200, map[string]string{
|
|
|
+ c.JSONSuccess(map[string]string{
|
|
|
"content": string(markup.Markdown(issue.Content, c.Query("context"), c.Repo.Repository.ComposeMetas())),
|
|
|
})
|
|
|
}
|
|
@@ -745,35 +745,31 @@ func UpdateIssueLabel(c *context.Context) {
|
|
|
|
|
|
if c.Query("action") == "clear" {
|
|
|
if err := issue.ClearLabels(c.User); err != nil {
|
|
|
- c.Handle(500, "ClearLabels", err)
|
|
|
+ c.Error(err, "clear labels")
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
|
isAttach := c.Query("action") == "attach"
|
|
|
label, err := db.GetLabelOfRepoByID(c.Repo.Repository.ID, c.QueryInt64("id"))
|
|
|
if err != nil {
|
|
|
- if db.IsErrLabelNotExist(err) {
|
|
|
- c.Error(404, "GetLabelByID")
|
|
|
- } else {
|
|
|
- c.Handle(500, "GetLabelByID", err)
|
|
|
- }
|
|
|
+ c.NotFoundOrError(err, "get label by ID")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if isAttach && !issue.HasLabel(label.ID) {
|
|
|
if err = issue.AddLabel(c.User, label); err != nil {
|
|
|
- c.Handle(500, "AddLabel", err)
|
|
|
+ c.Error(err, "add label")
|
|
|
return
|
|
|
}
|
|
|
} else if !isAttach && issue.HasLabel(label.ID) {
|
|
|
if err = issue.RemoveLabel(c.User, label); err != nil {
|
|
|
- c.Handle(500, "RemoveLabel", err)
|
|
|
+ c.Error(err, "remove label")
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- c.JSON(200, map[string]interface{}{
|
|
|
+ c.JSONSuccess(map[string]interface{}{
|
|
|
"ok": true,
|
|
|
})
|
|
|
}
|
|
@@ -787,7 +783,7 @@ func UpdateIssueMilestone(c *context.Context) {
|
|
|
oldMilestoneID := issue.MilestoneID
|
|
|
milestoneID := c.QueryInt64("id")
|
|
|
if oldMilestoneID == milestoneID {
|
|
|
- c.JSON(200, map[string]interface{}{
|
|
|
+ c.JSONSuccess(map[string]interface{}{
|
|
|
"ok": true,
|
|
|
})
|
|
|
return
|
|
@@ -796,11 +792,11 @@ func UpdateIssueMilestone(c *context.Context) {
|
|
|
// Not check for invalid milestone id and give responsibility to owners.
|
|
|
issue.MilestoneID = milestoneID
|
|
|
if err := db.ChangeMilestoneAssign(c.User, issue, oldMilestoneID); err != nil {
|
|
|
- c.Handle(500, "ChangeMilestoneAssign", err)
|
|
|
+ c.Error(err, "change milestone assign")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- c.JSON(200, map[string]interface{}{
|
|
|
+ c.JSONSuccess(map[string]interface{}{
|
|
|
"ok": true,
|
|
|
})
|
|
|
}
|
|
@@ -813,18 +809,18 @@ func UpdateIssueAssignee(c *context.Context) {
|
|
|
|
|
|
assigneeID := c.QueryInt64("id")
|
|
|
if issue.AssigneeID == assigneeID {
|
|
|
- c.JSON(200, map[string]interface{}{
|
|
|
+ c.JSONSuccess(map[string]interface{}{
|
|
|
"ok": true,
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if err := issue.ChangeAssignee(c.User, assigneeID); err != nil {
|
|
|
- c.Handle(500, "ChangeAssignee", err)
|
|
|
+ c.Error(err, "change assignee")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- c.JSON(200, map[string]interface{}{
|
|
|
+ c.JSONSuccess(map[string]interface{}{
|
|
|
"ok": true,
|
|
|
})
|
|
|
}
|
|
@@ -862,7 +858,7 @@ func NewComment(c *context.Context, f form.CreateComment) {
|
|
|
pr, err = db.GetUnmergedPullRequest(pull.HeadRepoID, pull.BaseRepoID, pull.HeadBranch, pull.BaseBranch)
|
|
|
if err != nil {
|
|
|
if !db.IsErrPullRequestNotExist(err) {
|
|
|
- c.ServerError("GetUnmergedPullRequest", err)
|
|
|
+ c.Error(err, "get unmerged pull request")
|
|
|
return
|
|
|
}
|
|
|
}
|
|
@@ -870,7 +866,7 @@ func NewComment(c *context.Context, f form.CreateComment) {
|
|
|
// Regenerate patch and test conflict.
|
|
|
if pr == nil {
|
|
|
if err = issue.PullRequest.UpdatePatch(); err != nil {
|
|
|
- c.ServerError("UpdatePatch", err)
|
|
|
+ c.Error(err, "update patch")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -913,7 +909,7 @@ func NewComment(c *context.Context, f form.CreateComment) {
|
|
|
|
|
|
comment, err = db.CreateIssueComment(c.User, c.Repo.Repository, issue, f.Content, attachments)
|
|
|
if err != nil {
|
|
|
- c.ServerError("CreateIssueComment", err)
|
|
|
+ c.Error(err, "create issue comment")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -923,32 +919,32 @@ func NewComment(c *context.Context, f form.CreateComment) {
|
|
|
func UpdateCommentContent(c *context.Context) {
|
|
|
comment, err := db.GetCommentByID(c.ParamsInt64(":id"))
|
|
|
if err != nil {
|
|
|
- c.NotFoundOrServerError("GetCommentByID", db.IsErrCommentNotExist, err)
|
|
|
+ c.NotFoundOrError(err, "get comment by ID")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if c.UserID() != comment.PosterID && !c.Repo.IsAdmin() {
|
|
|
- c.Error(404)
|
|
|
+ c.NotFound()
|
|
|
return
|
|
|
} else if comment.Type != db.COMMENT_TYPE_COMMENT {
|
|
|
- c.Error(204)
|
|
|
+ c.Status(http.StatusNoContent)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
oldContent := comment.Content
|
|
|
comment.Content = c.Query("content")
|
|
|
if len(comment.Content) == 0 {
|
|
|
- c.JSON(200, map[string]interface{}{
|
|
|
+ c.JSONSuccess(map[string]interface{}{
|
|
|
"content": "",
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
if err = db.UpdateComment(c.User, comment, oldContent); err != nil {
|
|
|
- c.Handle(500, "UpdateComment", err)
|
|
|
+ c.Error(err, "update comment")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- c.JSON(200, map[string]string{
|
|
|
+ c.JSONSuccess(map[string]string{
|
|
|
"content": string(markup.Markdown(comment.Content, c.Query("context"), c.Repo.Repository.ComposeMetas())),
|
|
|
})
|
|
|
}
|
|
@@ -956,24 +952,24 @@ func UpdateCommentContent(c *context.Context) {
|
|
|
func DeleteComment(c *context.Context) {
|
|
|
comment, err := db.GetCommentByID(c.ParamsInt64(":id"))
|
|
|
if err != nil {
|
|
|
- c.NotFoundOrServerError("GetCommentByID", db.IsErrCommentNotExist, err)
|
|
|
+ c.NotFoundOrError(err, "get comment by ID")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if c.UserID() != comment.PosterID && !c.Repo.IsAdmin() {
|
|
|
- c.Error(404)
|
|
|
+ c.NotFound()
|
|
|
return
|
|
|
} else if comment.Type != db.COMMENT_TYPE_COMMENT {
|
|
|
- c.Error(204)
|
|
|
+ c.Status(http.StatusNoContent)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if err = db.DeleteCommentByID(c.User, comment.ID); err != nil {
|
|
|
- c.Handle(500, "DeleteCommentByID", err)
|
|
|
+ c.Error(err, "delete comment by ID")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- c.Status(200)
|
|
|
+ c.Status(http.StatusOK)
|
|
|
}
|
|
|
|
|
|
func Labels(c *context.Context) {
|
|
@@ -982,7 +978,7 @@ func Labels(c *context.Context) {
|
|
|
c.Data["PageIsLabels"] = true
|
|
|
c.Data["RequireMinicolors"] = true
|
|
|
c.Data["LabelTemplates"] = db.LabelTemplates
|
|
|
- c.HTML(200, LABELS)
|
|
|
+ c.Success(LABELS)
|
|
|
}
|
|
|
|
|
|
func InitializeLabels(c *context.Context, f form.InitializeLabels) {
|
|
@@ -1006,7 +1002,7 @@ func InitializeLabels(c *context.Context, f form.InitializeLabels) {
|
|
|
}
|
|
|
}
|
|
|
if err := db.NewLabels(labels...); err != nil {
|
|
|
- c.Handle(500, "NewLabels", err)
|
|
|
+ c.Error(err, "new labels")
|
|
|
return
|
|
|
}
|
|
|
c.RawRedirect(c.Repo.MakeURL("labels"))
|
|
@@ -1028,7 +1024,7 @@ func NewLabel(c *context.Context, f form.CreateLabel) {
|
|
|
Color: f.Color,
|
|
|
}
|
|
|
if err := db.NewLabels(l); err != nil {
|
|
|
- c.Handle(500, "NewLabel", err)
|
|
|
+ c.Error(err, "new labels")
|
|
|
return
|
|
|
}
|
|
|
c.RawRedirect(c.Repo.MakeURL("labels"))
|
|
@@ -1037,19 +1033,14 @@ func NewLabel(c *context.Context, f form.CreateLabel) {
|
|
|
func UpdateLabel(c *context.Context, f form.CreateLabel) {
|
|
|
l, err := db.GetLabelByID(f.ID)
|
|
|
if err != nil {
|
|
|
- switch {
|
|
|
- case db.IsErrLabelNotExist(err):
|
|
|
- c.Error(404)
|
|
|
- default:
|
|
|
- c.Handle(500, "UpdateLabel", err)
|
|
|
- }
|
|
|
+ c.NotFoundOrError(err, "get label by ID")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
l.Name = f.Title
|
|
|
l.Color = f.Color
|
|
|
if err := db.UpdateLabel(l); err != nil {
|
|
|
- c.Handle(500, "UpdateLabel", err)
|
|
|
+ c.Error(err, "update label")
|
|
|
return
|
|
|
}
|
|
|
c.RawRedirect(c.Repo.MakeURL("labels"))
|
|
@@ -1092,7 +1083,7 @@ func Milestones(c *context.Context) {
|
|
|
|
|
|
miles, err := db.GetMilestones(c.Repo.Repository.ID, page, isShowClosed)
|
|
|
if err != nil {
|
|
|
- c.Handle(500, "GetMilestones", err)
|
|
|
+ c.Error(err, "get milestones")
|
|
|
return
|
|
|
}
|
|
|
for _, m := range miles {
|
|
@@ -1112,7 +1103,7 @@ func Milestones(c *context.Context) {
|
|
|
}
|
|
|
|
|
|
c.Data["IsShowClosed"] = isShowClosed
|
|
|
- c.HTML(200, MILESTONE)
|
|
|
+ c.Success(MILESTONE)
|
|
|
}
|
|
|
|
|
|
func NewMilestone(c *context.Context) {
|
|
@@ -1121,7 +1112,7 @@ func NewMilestone(c *context.Context) {
|
|
|
c.Data["PageIsMilestones"] = true
|
|
|
c.Data["RequireDatetimepicker"] = true
|
|
|
c.Data["DateLang"] = conf.I18n.DateLang(c.Locale.Language())
|
|
|
- c.HTML(200, MILESTONE_NEW)
|
|
|
+ c.Success(MILESTONE_NEW)
|
|
|
}
|
|
|
|
|
|
func NewMilestonePost(c *context.Context, f form.CreateMilestone) {
|
|
@@ -1132,7 +1123,7 @@ func NewMilestonePost(c *context.Context, f form.CreateMilestone) {
|
|
|
c.Data["DateLang"] = conf.I18n.DateLang(c.Locale.Language())
|
|
|
|
|
|
if c.HasError() {
|
|
|
- c.HTML(200, MILESTONE_NEW)
|
|
|
+ c.Success(MILESTONE_NEW)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1152,7 +1143,7 @@ func NewMilestonePost(c *context.Context, f form.CreateMilestone) {
|
|
|
Content: f.Content,
|
|
|
Deadline: deadline,
|
|
|
}); err != nil {
|
|
|
- c.Handle(500, "NewMilestone", err)
|
|
|
+ c.Error(err, "new milestone")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1169,11 +1160,7 @@ func EditMilestone(c *context.Context) {
|
|
|
|
|
|
m, err := db.GetMilestoneByRepoID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
|
|
|
if err != nil {
|
|
|
- if db.IsErrMilestoneNotExist(err) {
|
|
|
- c.Handle(404, "", nil)
|
|
|
- } else {
|
|
|
- c.Handle(500, "GetMilestoneByRepoID", err)
|
|
|
- }
|
|
|
+ c.NotFoundOrError(err, "get milestone by repository ID")
|
|
|
return
|
|
|
}
|
|
|
c.Data["title"] = m.Name
|
|
@@ -1181,7 +1168,7 @@ func EditMilestone(c *context.Context) {
|
|
|
if len(m.DeadlineString) > 0 {
|
|
|
c.Data["deadline"] = m.DeadlineString
|
|
|
}
|
|
|
- c.HTML(200, MILESTONE_NEW)
|
|
|
+ c.Success(MILESTONE_NEW)
|
|
|
}
|
|
|
|
|
|
func EditMilestonePost(c *context.Context, f form.CreateMilestone) {
|
|
@@ -1192,7 +1179,7 @@ func EditMilestonePost(c *context.Context, f form.CreateMilestone) {
|
|
|
c.Data["DateLang"] = conf.I18n.DateLang(c.Locale.Language())
|
|
|
|
|
|
if c.HasError() {
|
|
|
- c.HTML(200, MILESTONE_NEW)
|
|
|
+ c.Success(MILESTONE_NEW)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1208,18 +1195,14 @@ func EditMilestonePost(c *context.Context, f form.CreateMilestone) {
|
|
|
|
|
|
m, err := db.GetMilestoneByRepoID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
|
|
|
if err != nil {
|
|
|
- if db.IsErrMilestoneNotExist(err) {
|
|
|
- c.Handle(404, "", nil)
|
|
|
- } else {
|
|
|
- c.Handle(500, "GetMilestoneByRepoID", err)
|
|
|
- }
|
|
|
+ c.NotFoundOrError(err, "get milestone by repository ID")
|
|
|
return
|
|
|
}
|
|
|
m.Name = f.Title
|
|
|
m.Content = f.Content
|
|
|
m.Deadline = deadline
|
|
|
if err = db.UpdateMilestone(m); err != nil {
|
|
|
- c.Handle(500, "UpdateMilestone", err)
|
|
|
+ c.Error(err, "update milestone")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1230,11 +1213,7 @@ func EditMilestonePost(c *context.Context, f form.CreateMilestone) {
|
|
|
func ChangeMilestonStatus(c *context.Context) {
|
|
|
m, err := db.GetMilestoneByRepoID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
|
|
|
if err != nil {
|
|
|
- if db.IsErrMilestoneNotExist(err) {
|
|
|
- c.Handle(404, "", err)
|
|
|
- } else {
|
|
|
- c.Handle(500, "GetMilestoneByRepoID", err)
|
|
|
- }
|
|
|
+ c.NotFoundOrError(err, "get milestone by repository ID")
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -1246,7 +1225,7 @@ func ChangeMilestonStatus(c *context.Context) {
|
|
|
case "open":
|
|
|
if m.IsClosed {
|
|
|
if err = db.ChangeMilestoneStatus(m, false); err != nil {
|
|
|
- c.Handle(500, "ChangeMilestoneStatus", err)
|
|
|
+ c.Error(err, "change milestone status to open")
|
|
|
return
|
|
|
}
|
|
|
}
|
|
@@ -1255,7 +1234,7 @@ func ChangeMilestonStatus(c *context.Context) {
|
|
|
if !m.IsClosed {
|
|
|
m.ClosedDate = time.Now()
|
|
|
if err = db.ChangeMilestoneStatus(m, true); err != nil {
|
|
|
- c.Handle(500, "ChangeMilestoneStatus", err)
|
|
|
+ c.Error(err, "change milestone status to closed")
|
|
|
return
|
|
|
}
|
|
|
}
|
|
@@ -1272,7 +1251,7 @@ func DeleteMilestone(c *context.Context) {
|
|
|
c.Flash.Success(c.Tr("repo.milestones.deletion_success"))
|
|
|
}
|
|
|
|
|
|
- c.JSON(200, map[string]interface{}{
|
|
|
+ c.JSONSuccess(map[string]interface{}{
|
|
|
"redirect": c.Repo.MakeURL("milestones"),
|
|
|
})
|
|
|
}
|