Skip to content

Commit 7971b05

Browse files
davidsvantessonlunny
authored andcommitted
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
1 parent dce22ef commit 7971b05

File tree

6 files changed

+34
-12
lines changed

6 files changed

+34
-12
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ require (
6969
github.com/mattn/go-sqlite3 v1.11.0
7070
github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75
7171
github.com/microcosm-cc/bluemonday v0.0.0-20161012083705-f77f16ffc87a
72-
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
73-
github.com/modern-go/reflect2 v1.0.1 // indirect
7472
github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae // indirect
7573
github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc
7674
github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5

modules/structs/issue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ type EditIssueOption struct {
9999
Milestone *int64 `json:"milestone"`
100100
State *string `json:"state"`
101101
// swagger:strfmt date-time
102-
Deadline *time.Time `json:"due_date"`
102+
Deadline *time.Time `json:"due_date"`
103+
RemoveDeadline *bool `json:"unset_due_date"`
103104
}
104105

105106
// EditDeadlineOption options for creating a deadline

modules/structs/pull.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,6 @@ type EditPullRequestOption struct {
8888
Labels []int64 `json:"labels"`
8989
State *string `json:"state"`
9090
// swagger:strfmt date-time
91-
Deadline *time.Time `json:"due_date"`
91+
Deadline *time.Time `json:"due_date"`
92+
RemoveDeadline *bool `json:"unset_due_date"`
9293
}

routers/api/v1/repo/issue.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,16 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
458458
issue.Content = *form.Body
459459
}
460460

461-
// Update the deadline
462-
if form.Deadline != nil && ctx.Repo.CanWrite(models.UnitTypeIssues) {
463-
deadlineUnix := timeutil.TimeStamp(form.Deadline.Unix())
461+
// Update or remove the deadline, only if set and allowed
462+
if (form.Deadline != nil || form.RemoveDeadline != nil) && ctx.Repo.CanWrite(models.UnitTypeIssues) {
463+
var deadlineUnix timeutil.TimeStamp
464+
465+
if (form.RemoveDeadline == nil || !*form.RemoveDeadline) && !form.Deadline.IsZero() {
466+
deadline := time.Date(form.Deadline.Year(), form.Deadline.Month(), form.Deadline.Day(),
467+
23, 59, 59, 0, form.Deadline.Location())
468+
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
469+
}
470+
464471
if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
465472
ctx.Error(500, "UpdateIssueDeadline", err)
466473
return

routers/api/v1/repo/pull.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"net/http"
1010
"strings"
11+
"time"
1112

1213
"code.gitea.io/gitea/models"
1314
"code.gitea.io/gitea/modules/auth"
@@ -326,7 +327,7 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption
326327
func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
327328
// swagger:operation PATCH /repos/{owner}/{repo}/pulls/{index} repository repoEditPullRequest
328329
// ---
329-
// summary: Update a pull request
330+
// summary: Update a pull request. If using deadline only the date will be taken into account, and time of day ignored.
330331
// consumes:
331332
// - application/json
332333
// produces:
@@ -385,9 +386,15 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
385386
issue.Content = form.Body
386387
}
387388

388-
// Update Deadline
389-
if form.Deadline != nil {
390-
deadlineUnix := timeutil.TimeStamp(form.Deadline.Unix())
389+
// Update or remove deadline if set
390+
if form.Deadline != nil || form.RemoveDeadline != nil {
391+
var deadlineUnix timeutil.TimeStamp
392+
if (form.RemoveDeadline == nil || !*form.RemoveDeadline) && !form.Deadline.IsZero() {
393+
deadline := time.Date(form.Deadline.Year(), form.Deadline.Month(), form.Deadline.Day(),
394+
23, 59, 59, 0, form.Deadline.Location())
395+
deadlineUnix = timeutil.TimeStamp(deadline.Unix())
396+
}
397+
391398
if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil {
392399
ctx.Error(500, "UpdateIssueDeadline", err)
393400
return

templates/swagger/v1_json.tmpl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4715,7 +4715,7 @@
47154715
"tags": [
47164716
"repository"
47174717
],
4718-
"summary": "Update a pull request",
4718+
"summary": "Update a pull request. If using deadline only the date will be taken into account, and time of day ignored.",
47194719
"operationId": "repoEditPullRequest",
47204720
"parameters": [
47214721
{
@@ -8532,6 +8532,10 @@
85328532
"title": {
85338533
"type": "string",
85348534
"x-go-name": "Title"
8535+
},
8536+
"unset_due_date": {
8537+
"type": "boolean",
8538+
"x-go-name": "RemoveDeadline"
85358539
}
85368540
},
85378541
"x-go-package": "code.gitea.io/gitea/modules/structs"
@@ -8660,6 +8664,10 @@
86608664
"title": {
86618665
"type": "string",
86628666
"x-go-name": "Title"
8667+
},
8668+
"unset_due_date": {
8669+
"type": "boolean",
8670+
"x-go-name": "RemoveDeadline"
86638671
}
86648672
},
86658673
"x-go-package": "code.gitea.io/gitea/modules/structs"

0 commit comments

Comments
 (0)