diff options
author | kolaente <konrad@kola-entertainments.de> | 2018-05-01 21:05:28 +0200 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2018-05-01 22:05:28 +0300 |
commit | 1a97030017cd09b75f6c8d484e075f4eced1e001 (patch) | |
tree | 78fd666ad8693a91377807e77698ec44ddec7c58 /models | |
parent | 85d14cc229263c5788cac9370ac60e9582f9de6c (diff) | |
download | gitea-1a97030017cd09b75f6c8d484e075f4eced1e001.tar.gz gitea-1a97030017cd09b75f6c8d484e075f4eced1e001.zip |
Issue due date (#3794)
* Started adding deadline to ui
* Implemented basic issue due date managing
* Improved UI for due date managing
* Added at least write access to the repo in order to modify issue due dates
* Ui improvements
* Added issue comments creation when adding/modifying/removing a due date
* Show due date in issue list
* Added api support for issue due dates
* Fixed lint suggestions
* Added deadline to sdk
* Updated css
* Added support for adding/modifiying deadlines for pull requests via api
* Fixed comments not created when updating or removing a deadline
* update sdk (will do properly once go-gitea/go-sdk#103 is merged)
* enhanced updateIssueDeadline
* Removed unnessecary Issue.DeadlineString
* UI improvements
* Small improvments to comment creation
+ ui & validation improvements
* Check if an issue is overdue is now a seperate function
* Updated go-sdk with govendor as it was merged
* Simplified isOverdue method
* removed unessecary deadline to 0 set
* Update swagger definitions
* Added missing return
* Added an explanary comment
* Improved updateIssueDeadline method so it'll only update `deadline_unix`
* Small changes and improvements
* no need to explicitly load the issue when updating a deadline, just use whats already there
* small optimisations
* Added check if a deadline was modified before updating it
* Moved comment creating logic into its own function
* Code cleanup for creating deadline comment
* locale improvement
* When modifying a deadline, the old deadline is saved with the comment
* small improvments to xorm session handling when updating an issue deadline
+ style nitpicks
* style nitpicks
* Moved checking for if the user has write acces to middleware
Diffstat (limited to 'models')
-rw-r--r-- | models/issue.go | 42 | ||||
-rw-r--r-- | models/issue_comment.go | 34 | ||||
-rw-r--r-- | models/pull.go | 1 |
3 files changed, 74 insertions, 3 deletions
diff --git a/models/issue.go b/models/issue.go index 190b387530..7f83d59842 100644 --- a/models/issue.go +++ b/models/issue.go @@ -47,9 +47,10 @@ type Issue struct { Ref string DeadlineUnix util.TimeStamp `xorm:"INDEX"` - CreatedUnix util.TimeStamp `xorm:"INDEX created"` - UpdatedUnix util.TimeStamp `xorm:"INDEX updated"` - ClosedUnix util.TimeStamp `xorm:"INDEX"` + + CreatedUnix util.TimeStamp `xorm:"INDEX created"` + UpdatedUnix util.TimeStamp `xorm:"INDEX updated"` + ClosedUnix util.TimeStamp `xorm:"INDEX"` Attachments []*Attachment `xorm:"-"` Comments []*Comment `xorm:"-"` @@ -79,6 +80,11 @@ func (issue *Issue) loadTotalTimes(e Engine) (err error) { return nil } +// IsOverdue checks if the issue is overdue +func (issue *Issue) IsOverdue() bool { + return util.TimeStampNow() >= issue.DeadlineUnix +} + func (issue *Issue) loadRepo(e Engine) (err error) { if issue.Repo == nil { issue.Repo, err = getRepositoryByID(e, issue.RepoID) @@ -348,6 +354,9 @@ func (issue *Issue) APIFormat() *api.Issue { apiIssue.PullRequest.Merged = issue.PullRequest.MergedUnix.AsTimePtr() } } + if issue.DeadlineUnix != 0 { + apiIssue.Deadline = issue.DeadlineUnix.AsTimePtr() + } return apiIssue } @@ -1522,3 +1531,30 @@ func updateIssue(e Engine, issue *Issue) error { func UpdateIssue(issue *Issue) error { return updateIssue(x, issue) } + +// UpdateIssueDeadline updates an issue deadline and adds comments. Setting a deadline to 0 means deleting it. +func UpdateIssueDeadline(issue *Issue, deadlineUnix util.TimeStamp, doer *User) (err error) { + + // if the deadline hasn't changed do nothing + if issue.DeadlineUnix == deadlineUnix { + return nil + } + + sess := x.NewSession() + defer sess.Close() + if err := sess.Begin(); err != nil { + return err + } + + // Update the deadline + if err = updateIssueCols(sess, &Issue{ID: issue.ID, DeadlineUnix: deadlineUnix}, "deadline_unix"); err != nil { + return err + } + + // Make the comment + if _, err = createDeadlineComment(sess, doer, issue, deadlineUnix); err != nil { + return fmt.Errorf("createRemovedDueDateComment: %v", err) + } + + return sess.Commit() +} diff --git a/models/issue_comment.go b/models/issue_comment.go index ea83c356ee..aedb124863 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -60,6 +60,12 @@ const ( CommentTypeAddTimeManual // Cancel a stopwatch for time tracking CommentTypeCancelTracking + // Added a due date + CommentTypeAddedDeadline + // Modified the due date + CommentTypeModifiedDeadline + // Removed a due date + CommentTypeRemovedDeadline ) // CommentTag defines comment tag type @@ -485,6 +491,34 @@ func createAssigneeComment(e *xorm.Session, doer *User, repo *Repository, issue }) } +func createDeadlineComment(e *xorm.Session, doer *User, issue *Issue, newDeadlineUnix util.TimeStamp) (*Comment, error) { + + var content string + var commentType CommentType + + // newDeadline = 0 means deleting + if newDeadlineUnix == 0 { + commentType = CommentTypeRemovedDeadline + content = issue.DeadlineUnix.Format("2006-01-02") + } else if issue.DeadlineUnix == 0 { + // Check if the new date was added or modified + // If the actual deadline is 0 => deadline added + commentType = CommentTypeAddedDeadline + content = newDeadlineUnix.Format("2006-01-02") + } else { // Otherwise modified + commentType = CommentTypeModifiedDeadline + content = newDeadlineUnix.Format("2006-01-02") + "|" + issue.DeadlineUnix.Format("2006-01-02") + } + + return createComment(e, &CreateCommentOptions{ + Type: commentType, + Doer: doer, + Repo: issue.Repo, + Issue: issue, + Content: content, + }) +} + func createChangeTitleComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, oldTitle, newTitle string) (*Comment, error) { return createComment(e, &CreateCommentOptions{ Type: CommentTypeChangeTitle, diff --git a/models/pull.go b/models/pull.go index 6862d11a1d..5f4a6e2054 100644 --- a/models/pull.go +++ b/models/pull.go @@ -207,6 +207,7 @@ func (pr *PullRequest) APIFormat() *api.PullRequest { Base: apiBaseBranchInfo, Head: apiHeadBranchInfo, MergeBase: pr.MergeBase, + Deadline: apiIssue.Deadline, Created: pr.Issue.CreatedUnix.AsTimePtr(), Updated: pr.Issue.UpdatedUnix.AsTimePtr(), } |