From e29a6d3ad0169bdb812045813af2f4ab680e69db Mon Sep 17 00:00:00 2001 From: David Svantesson Date: Wed, 30 Oct 2019 08:39:26 +0100 Subject: [PATCH 1/4] Handle deadline is zero (to remove deadline) --- routers/api/v1/repo/issue.go | 10 ++++++++-- routers/api/v1/repo/pull.go | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 426826653c109..238edd06127ef 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -327,9 +327,15 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { issue.Content = *form.Body } - // Update the deadline + // Update or remove the deadline, only if set and allowed if form.Deadline != nil && ctx.Repo.CanWrite(models.UnitTypeIssues) { - deadlineUnix := timeutil.TimeStamp(form.Deadline.Unix()) + var deadlineUnix timeutil.TimeStamp + if !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 0180aebf89ddd..5bee446254ff8 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" @@ -386,9 +387,15 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) { issue.Content = form.Body } - // Update Deadline + // Update or remove deadline if set if form.Deadline != nil { - deadlineUnix := timeutil.TimeStamp(form.Deadline.Unix()) + var deadlineUnix timeutil.TimeStamp + if !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 From f0f4db2f15f41b8613767dfbfdf1cb2e272d4dfa Mon Sep 17 00:00:00 2001 From: David Svantesson Date: Wed, 30 Oct 2019 22:32:45 +0100 Subject: [PATCH 2/4] Better API documentation for issue deadline. --- routers/api/v1/repo/issue.go | 2 +- routers/api/v1/repo/pull.go | 2 +- templates/swagger/v1_json.tmpl | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 238edd06127ef..e15b84c099839 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -269,7 +269,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) { func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { // swagger:operation PATCH /repos/{owner}/{repo}/issues/{index} issue issueEditIssue // --- - // summary: Edit an issue. If using deadline only the date will be taken into account, and time of day ignored. + // summary: Edit an issue. If using deadline only the date will be taken into account, and time of day ignored. Deadline can be removed by setting it to "0001-01-01T00:00:00Z". // consumes: // - application/json // produces: diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 5bee446254ff8..28bcfa4cd94d7 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -328,7 +328,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. Deadline can be removed by setting it to "0001-01-01T00:00:00Z". // consumes: // - application/json // produces: diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 5be36d23be94c..3901339614d07 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3099,7 +3099,7 @@ "tags": [ "issue" ], - "summary": "Edit an issue. If using deadline only the date will be taken into account, and time of day ignored.", + "summary": "Edit an issue. If using deadline only the date will be taken into account, and time of day ignored. Deadline can be removed by setting it to \"0001-01-01T00:00:00Z\".", "operationId": "issueEditIssue", "parameters": [ { @@ -4506,7 +4506,7 @@ "tags": [ "repository" ], - "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. Deadline can be removed by setting it to \"0001-01-01T00:00:00Z\".", "operationId": "repoEditPullRequest", "parameters": [ { From 51c3fe9f574ca1e08ea9e1d352d25792cf73baef Mon Sep 17 00:00:00 2001 From: David Svantesson Date: Sat, 2 Nov 2019 09:30:24 +0100 Subject: [PATCH 3/4] Add parameter to unset due date. --- modules/structs/issue.go | 3 ++- modules/structs/pull.go | 3 ++- routers/api/v1/repo/issue.go | 7 ++++--- routers/api/v1/repo/pull.go | 4 ++-- templates/swagger/v1_json.tmpl | 10 +++++++++- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/modules/structs/issue.go b/modules/structs/issue.go index bd39f9ea444b0..b27c757faa52d 100644 --- a/modules/structs/issue.go +++ b/modules/structs/issue.go @@ -99,7 +99,8 @@ type EditIssueOption struct { Milestone *int64 `json:"milestone"` State *string `json:"state"` // swagger:strfmt date-time - Deadline *time.Time `json:"due_date"` + Deadline *time.Time `json:"due_date"` + RemoveDeadline *bool `json:"unset_due_date"` } // EditDeadlineOption options for creating a deadline diff --git a/modules/structs/pull.go b/modules/structs/pull.go index 722d245afc49e..c4ec7d416a9b1 100644 --- a/modules/structs/pull.go +++ b/modules/structs/pull.go @@ -88,5 +88,6 @@ type EditPullRequestOption struct { Labels []int64 `json:"labels"` State *string `json:"state"` // swagger:strfmt date-time - Deadline *time.Time `json:"due_date"` + Deadline *time.Time `json:"due_date"` + RemoveDeadline *bool `json:"unset_due_date"` } diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index d95f04c597418..186e66cb8f8c6 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -400,7 +400,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) { func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { // swagger:operation PATCH /repos/{owner}/{repo}/issues/{index} issue issueEditIssue // --- - // summary: Edit an issue. If using deadline only the date will be taken into account, and time of day ignored. Deadline can be removed by setting it to "0001-01-01T00:00:00Z". + // summary: Edit an issue. If using deadline only the date will be taken into account, and time of day ignored. // consumes: // - application/json // produces: @@ -459,9 +459,10 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { } // Update or remove the deadline, only if set and allowed - if form.Deadline != nil && ctx.Repo.CanWrite(models.UnitTypeIssues) { + if (form.Deadline != nil || form.RemoveDeadline != nil) && ctx.Repo.CanWrite(models.UnitTypeIssues) { var deadlineUnix timeutil.TimeStamp - if !form.Deadline.IsZero() { + + 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()) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 46a6b8b569006..4cf16adb75931 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -387,9 +387,9 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) { } // Update or remove deadline if set - if form.Deadline != nil { + if form.Deadline != nil || form.RemoveDeadline != nil { var deadlineUnix timeutil.TimeStamp - if !form.Deadline.IsZero() { + 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()) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index cb19ac65ec98f..6991420d561bf 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -3149,7 +3149,7 @@ "tags": [ "issue" ], - "summary": "Edit an issue. If using deadline only the date will be taken into account, and time of day ignored. Deadline can be removed by setting it to \"0001-01-01T00:00:00Z\".", + "summary": "Edit an issue. If using deadline only the date will be taken into account, and time of day ignored.", "operationId": "issueEditIssue", "parameters": [ { @@ -8373,6 +8373,10 @@ "title": { "type": "string", "x-go-name": "Title" + }, + "unset_due_date": { + "type": "boolean", + "x-go-name": "RemoveDeadline" } }, "x-go-package": "code.gitea.io/gitea/modules/structs" @@ -8501,6 +8505,10 @@ "title": { "type": "string", "x-go-name": "Title" + }, + "unset_due_date": { + "type": "boolean", + "x-go-name": "RemoveDeadline" } }, "x-go-package": "code.gitea.io/gitea/modules/structs" From 056b79d308bc1e7b49225132a693aeb279f75104 Mon Sep 17 00:00:00 2001 From: David Svantesson Date: Sat, 2 Nov 2019 10:19:11 +0000 Subject: [PATCH 4/4] Update pull edit API comment --- go.mod | 2 -- routers/api/v1/repo/pull.go | 2 +- templates/swagger/v1_json.tmpl | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 7e920ac03208e..02f0c46f22e1c 100644 --- a/go.mod +++ b/go.mod @@ -69,8 +69,6 @@ require ( github.com/mattn/go-sqlite3 v1.11.0 github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75 github.com/microcosm-cc/bluemonday v0.0.0-20161012083705-f77f16ffc87a - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.1 // indirect github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae // indirect github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 4cf16adb75931..6d86105a15d13 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -327,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. If using deadline only the date will be taken into account, and time of day ignored. Deadline can be removed by setting it to "0001-01-01T00:00:00Z". + // 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: diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 6991420d561bf..9f0f8e89fe705 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -4556,7 +4556,7 @@ "tags": [ "repository" ], - "summary": "Update a pull request. If using deadline only the date will be taken into account, and time of day ignored. Deadline can be removed by setting it to \"0001-01-01T00:00:00Z\".", + "summary": "Update a pull request. If using deadline only the date will be taken into account, and time of day ignored.", "operationId": "repoEditPullRequest", "parameters": [ {