diff options
author | David Svantesson <davidsvantesson@gmail.com> | 2019-11-03 15:46:32 +0100 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-11-03 22:46:32 +0800 |
commit | 7971b05d2b96e45a4ee3954a39a7db9b9bbb807f (patch) | |
tree | f46d38c064c5372e6d3b813568096bef402421fb /routers | |
parent | dce22efbee6a04b8c19348dac831cd88b18ac07c (diff) | |
download | gitea-7971b05d2b96e45a4ee3954a39a7db9b9bbb807f.tar.gz gitea-7971b05d2b96e45a4ee3954a39a7db9b9bbb807f.zip |
Fix API deadline removal (#8759)
* Handle deadline is zero (to remove deadline)
* Better API documentation for issue deadline.
* Add parameter to unset due date.
* Update pull edit API comment
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/issue.go | 13 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 15 |
2 files changed, 21 insertions, 7 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 1534c45df0..186e66cb8f 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -458,9 +458,16 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { issue.Content = *form.Body } - // Update the deadline - if form.Deadline != nil && ctx.Repo.CanWrite(models.UnitTypeIssues) { - deadlineUnix := timeutil.TimeStamp(form.Deadline.Unix()) + // Update or remove the deadline, only if set and allowed + if (form.Deadline != nil || form.RemoveDeadline != nil) && ctx.Repo.CanWrite(models.UnitTypeIssues) { + var deadlineUnix timeutil.TimeStamp + + if (form.RemoveDeadline == nil || !*form.RemoveDeadline) && !form.Deadline.IsZero() { + deadline := time.Date(form.Deadline.Year(), form.Deadline.Month(), form.Deadline.Day(), + 23, 59, 59, 0, form.Deadline.Location()) + deadlineUnix = timeutil.TimeStamp(deadline.Unix()) + } + if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil { ctx.Error(500, "UpdateIssueDeadline", err) return diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 9264c00cec..6d86105a15 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -8,6 +8,7 @@ import ( "fmt" "net/http" "strings" + "time" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" @@ -326,7 +327,7 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) { // swagger:operation PATCH /repos/{owner}/{repo}/pulls/{index} repository repoEditPullRequest // --- - // summary: Update a pull request + // summary: Update a pull request. If using deadline only the date will be taken into account, and time of day ignored. // consumes: // - application/json // produces: @@ -385,9 +386,15 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) { issue.Content = form.Body } - // Update Deadline - if form.Deadline != nil { - deadlineUnix := timeutil.TimeStamp(form.Deadline.Unix()) + // Update or remove deadline if set + if form.Deadline != nil || form.RemoveDeadline != nil { + var deadlineUnix timeutil.TimeStamp + if (form.RemoveDeadline == nil || !*form.RemoveDeadline) && !form.Deadline.IsZero() { + deadline := time.Date(form.Deadline.Year(), form.Deadline.Month(), form.Deadline.Day(), + 23, 59, 59, 0, form.Deadline.Location()) + deadlineUnix = timeutil.TimeStamp(deadline.Unix()) + } + if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil { ctx.Error(500, "UpdateIssueDeadline", err) return |