]> source.dussan.org Git - gitea.git/commitdiff
Fix API deadline removal (#8759)
authorDavid Svantesson <davidsvantesson@gmail.com>
Sun, 3 Nov 2019 14:46:32 +0000 (15:46 +0100)
committerLunny Xiao <xiaolunwen@gmail.com>
Sun, 3 Nov 2019 14:46:32 +0000 (22:46 +0800)
* Handle deadline is zero (to remove deadline)

* Better API documentation for issue deadline.

* Add parameter to unset due date.

* Update pull edit API comment

go.mod
modules/structs/issue.go
modules/structs/pull.go
routers/api/v1/repo/issue.go
routers/api/v1/repo/pull.go
templates/swagger/v1_json.tmpl

diff --git a/go.mod b/go.mod
index 7e920ac03208e6e2c7dfdd942fccea1c5bb810e1..02f0c46f22e1c3bae82dde14c2ba2702fef3f587 100644 (file)
--- 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
index bd39f9ea444b07b29c181db37066d77f23fa9e52..b27c757faa52d657da16731607e658d9a0c1a066 100644 (file)
@@ -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
index 722d245afc49e17f05253f1d62d7c3e52935000a..c4ec7d416a9b14e54e3f89d14b527c9881f8e600 100644 (file)
@@ -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"`
 }
index 1534c45df0a0fa45d444672430f04f2df233b1da..186e66cb8f8c6cfbe38d3f8e3cdbbd147b400ab7 100644 (file)
@@ -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
index 9264c00cec614ddd45b0155350dcbb08dca53435..6d86105a15d131c0c03356d4be780fcc2fa82bdf 100644 (file)
@@ -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
index 41e5353ea73b0b6d9cdefd5694e8bf9824787e4b..17b8eab6c5e2834f764b39a2596103338d5965a9 100644 (file)
         "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.",
         "operationId": "repoEditPullRequest",
         "parameters": [
           {
         "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"
         "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"