Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix API deadline removal #8759

Merged
merged 8 commits into from
Nov 3, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/structs/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion modules/structs/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
13 changes: 10 additions & 3 deletions routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions routers/api/v1/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"strings"
"time"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
Expand Down Expand Up @@ -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. Deadline can be removed by setting it to "0001-01-01T00:00:00Z".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

// consumes:
// - application/json
// produces:
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4556,7 +4556,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\".",
davidsvantesson marked this conversation as resolved.
Show resolved Hide resolved
"operationId": "repoEditPullRequest",
"parameters": [
{
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down