diff options
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/issue.go | 27 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 35 | ||||
-rw-r--r-- | routers/repo/issue.go | 48 | ||||
-rw-r--r-- | routers/routes/routes.go | 2 |
4 files changed, 98 insertions, 14 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index ce13d8a6ed..cc033554f3 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -163,12 +163,19 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) { // responses: // "201": // "$ref": "#/responses/Issue" + + var deadlineUnix util.TimeStamp + if form.Deadline != nil { + deadlineUnix = util.TimeStamp(form.Deadline.Unix()) + } + issue := &models.Issue{ - RepoID: ctx.Repo.Repository.ID, - Title: form.Title, - PosterID: ctx.User.ID, - Poster: ctx.User, - Content: form.Body, + RepoID: ctx.Repo.Repository.ID, + Title: form.Title, + PosterID: ctx.User.ID, + Poster: ctx.User, + Content: form.Body, + DeadlineUnix: deadlineUnix, } if ctx.Repo.IsWriter() { @@ -265,6 +272,16 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { issue.Content = *form.Body } + var deadlineUnix util.TimeStamp + if form.Deadline != nil && !form.Deadline.IsZero() { + deadlineUnix = util.TimeStamp(form.Deadline.Unix()) + } + + if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil { + ctx.Error(500, "UpdateIssueDeadline", err) + return + } + if ctx.Repo.IsWriter() && form.Assignee != nil && (issue.Assignee == nil || issue.Assignee.LowerName != strings.ToLower(*form.Assignee)) { if len(*form.Assignee) == 0 { diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 742c0bccf9..3ea4b8d327 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/util" api "code.gitea.io/sdk/gitea" ) @@ -236,16 +237,22 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption return } + var deadlineUnix util.TimeStamp + if form.Deadline != nil { + deadlineUnix = util.TimeStamp(form.Deadline.Unix()) + } + prIssue := &models.Issue{ - RepoID: repo.ID, - Index: repo.NextIssueIndex(), - Title: form.Title, - PosterID: ctx.User.ID, - Poster: ctx.User, - MilestoneID: milestoneID, - AssigneeID: assigneeID, - IsPull: true, - Content: form.Body, + RepoID: repo.ID, + Index: repo.NextIssueIndex(), + Title: form.Title, + PosterID: ctx.User.ID, + Poster: ctx.User, + MilestoneID: milestoneID, + AssigneeID: assigneeID, + IsPull: true, + Content: form.Body, + DeadlineUnix: deadlineUnix, } pr := &models.PullRequest{ HeadRepoID: headRepo.ID, @@ -328,6 +335,16 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) { issue.Content = form.Body } + var deadlineUnix util.TimeStamp + if form.Deadline != nil && !form.Deadline.IsZero() { + deadlineUnix = util.TimeStamp(form.Deadline.Unix()) + } + + if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil { + ctx.Error(500, "UpdateIssueDeadline", err) + return + } + if ctx.Repo.IsWriter() && len(form.Assignee) > 0 && (issue.Assignee == nil || issue.Assignee.LowerName != strings.ToLower(form.Assignee)) { if len(form.Assignee) == 0 { diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 51516b828c..c7aef25594 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -1467,3 +1467,51 @@ func ChangeCommentReaction(ctx *context.Context, form auth.ReactionForm) { "html": html, }) } + +// UpdateDeadline adds or updates a deadline +func UpdateDeadline(ctx *context.Context, form auth.DeadlineForm) { + issue := GetActionIssue(ctx) + if ctx.Written() { + return + } + + if ctx.HasError() { + ctx.ServerError("ChangeIssueDeadline", errors.New(ctx.GetErrMsg())) + return + } + + // Make unix of deadline string + deadline, err := time.ParseInLocation("2006-01-02", form.DateString, time.Local) + if err != nil { + ctx.Flash.Error(ctx.Tr("repo.issues.invalid_due_date_format")) + ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) + return + } + + if err = models.UpdateIssueDeadline(issue, util.TimeStamp(deadline.Unix()), ctx.User); err != nil { + ctx.Flash.Error(ctx.Tr("repo.issues.error_modifying_due_date")) + } + + ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) + return +} + +// RemoveDeadline removes a deadline +func RemoveDeadline(ctx *context.Context) { + issue := GetActionIssue(ctx) + if ctx.Written() { + return + } + + if ctx.HasError() { + ctx.ServerError("RemoveIssueDeadline", errors.New(ctx.GetErrMsg())) + return + } + + if err := models.UpdateIssueDeadline(issue, 0, ctx.User); err != nil { + ctx.Flash.Error(ctx.Tr("repo.issues.error_removing_due_date")) + } + + ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index)) + return +} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 47a0854e19..9618d25268 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -496,6 +496,8 @@ func RegisterRoutes(m *macaron.Macaron) { }) }) m.Post("/reactions/:action", bindIgnErr(auth.ReactionForm{}), repo.ChangeIssueReaction) + m.Post("/deadline/update", reqRepoWriter, bindIgnErr(auth.DeadlineForm{}), repo.UpdateDeadline) + m.Post("/deadline/delete", reqRepoWriter, repo.RemoveDeadline) }) m.Post("/labels", reqRepoWriter, repo.UpdateIssueLabel) |