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
This commit is contained in:
		
							parent
							
								
									dce22efbee
								
							
						
					
					
						commit
						7971b05d2b
					
				
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							| @ -69,8 +69,6 @@ require ( | |||||||
| 	github.com/mattn/go-sqlite3 v1.11.0 | 	github.com/mattn/go-sqlite3 v1.11.0 | ||||||
| 	github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75 | 	github.com/mcuadros/go-version v0.0.0-20190308113854-92cdf37c5b75 | ||||||
| 	github.com/microcosm-cc/bluemonday v0.0.0-20161012083705-f77f16ffc87a | 	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/mschoch/smat v0.0.0-20160514031455-90eadee771ae // indirect | ||||||
| 	github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc | 	github.com/msteinert/pam v0.0.0-20151204160544-02ccfbfaf0cc | ||||||
| 	github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 | 	github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 | ||||||
|  | |||||||
| @ -100,6 +100,7 @@ type EditIssueOption struct { | |||||||
| 	State     *string  `json:"state"` | 	State     *string  `json:"state"` | ||||||
| 	// swagger:strfmt date-time | 	// 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 | // EditDeadlineOption options for creating a deadline | ||||||
|  | |||||||
| @ -89,4 +89,5 @@ type EditPullRequestOption struct { | |||||||
| 	State     *string  `json:"state"` | 	State     *string  `json:"state"` | ||||||
| 	// swagger:strfmt date-time | 	// swagger:strfmt date-time | ||||||
| 	Deadline       *time.Time `json:"due_date"` | 	Deadline       *time.Time `json:"due_date"` | ||||||
|  | 	RemoveDeadline *bool      `json:"unset_due_date"` | ||||||
| } | } | ||||||
|  | |||||||
| @ -458,9 +458,16 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { | |||||||
| 		issue.Content = *form.Body | 		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) { | 	if (form.Deadline != nil || form.RemoveDeadline != nil) && ctx.Repo.CanWrite(models.UnitTypeIssues) { | ||||||
| 		deadlineUnix := timeutil.TimeStamp(form.Deadline.Unix()) | 		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 { | 		if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil { | ||||||
| 			ctx.Error(500, "UpdateIssueDeadline", err) | 			ctx.Error(500, "UpdateIssueDeadline", err) | ||||||
| 			return | 			return | ||||||
|  | |||||||
| @ -8,6 +8,7 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"strings" | 	"strings" | ||||||
|  | 	"time" | ||||||
| 
 | 
 | ||||||
| 	"code.gitea.io/gitea/models" | 	"code.gitea.io/gitea/models" | ||||||
| 	"code.gitea.io/gitea/modules/auth" | 	"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) { | func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) { | ||||||
| 	// swagger:operation PATCH /repos/{owner}/{repo}/pulls/{index} repository repoEditPullRequest | 	// 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: | 	// consumes: | ||||||
| 	// - application/json | 	// - application/json | ||||||
| 	// produces: | 	// produces: | ||||||
| @ -385,9 +386,15 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) { | |||||||
| 		issue.Content = form.Body | 		issue.Content = form.Body | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Update Deadline | 	// Update or remove deadline if set | ||||||
| 	if form.Deadline != nil { | 	if form.Deadline != nil || form.RemoveDeadline != nil { | ||||||
| 		deadlineUnix := timeutil.TimeStamp(form.Deadline.Unix()) | 		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 { | 		if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil { | ||||||
| 			ctx.Error(500, "UpdateIssueDeadline", err) | 			ctx.Error(500, "UpdateIssueDeadline", err) | ||||||
| 			return | 			return | ||||||
|  | |||||||
| @ -4715,7 +4715,7 @@ | |||||||
|         "tags": [ |         "tags": [ | ||||||
|           "repository" |           "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", |         "operationId": "repoEditPullRequest", | ||||||
|         "parameters": [ |         "parameters": [ | ||||||
|           { |           { | ||||||
| @ -8532,6 +8532,10 @@ | |||||||
|         "title": { |         "title": { | ||||||
|           "type": "string", |           "type": "string", | ||||||
|           "x-go-name": "Title" |           "x-go-name": "Title" | ||||||
|  |         }, | ||||||
|  |         "unset_due_date": { | ||||||
|  |           "type": "boolean", | ||||||
|  |           "x-go-name": "RemoveDeadline" | ||||||
|         } |         } | ||||||
|       }, |       }, | ||||||
|       "x-go-package": "code.gitea.io/gitea/modules/structs" |       "x-go-package": "code.gitea.io/gitea/modules/structs" | ||||||
| @ -8660,6 +8664,10 @@ | |||||||
|         "title": { |         "title": { | ||||||
|           "type": "string", |           "type": "string", | ||||||
|           "x-go-name": "Title" |           "x-go-name": "Title" | ||||||
|  |         }, | ||||||
|  |         "unset_due_date": { | ||||||
|  |           "type": "boolean", | ||||||
|  |           "x-go-name": "RemoveDeadline" | ||||||
|         } |         } | ||||||
|       }, |       }, | ||||||
|       "x-go-package": "code.gitea.io/gitea/modules/structs" |       "x-go-package": "code.gitea.io/gitea/modules/structs" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user