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

Issue due date #3794

Merged
merged 54 commits into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
406cd5a
Started adding deadline to ui
kolaente Mar 22, 2018
859cd47
Implemented basic issue due date managing
kolaente Mar 23, 2018
02415f7
Improved UI for due date managing
kolaente Mar 23, 2018
bfef995
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Mar 25, 2018
74c9e07
Added at least write access to the repo in order to modify issue due …
kolaente Mar 25, 2018
aeb3db9
Ui improvements
kolaente Mar 25, 2018
211b2ed
Added issue comments creation when adding/modifying/removing a due date
kolaente Mar 25, 2018
82d7bf0
Show due date in issue list
kolaente Apr 14, 2018
13a12c3
merge with master
kolaente Apr 14, 2018
c1ada01
Added api support for issue due dates
kolaente Apr 14, 2018
6663012
Fixed lint suggestions
kolaente Apr 14, 2018
f4baf19
Added deadline to sdk
kolaente Apr 14, 2018
06d9649
Updated css
kolaente Apr 14, 2018
3bf2227
Added support for adding/modifiying deadlines for pull requests via api
kolaente Apr 14, 2018
60bbb23
Fixed comments not created when updating or removing a deadline
kolaente Apr 14, 2018
192f31e
update sdk (will do properly once go-gitea/go-sdk#103 is merged)
kolaente Apr 14, 2018
f766101
enhanced updateIssueDeadline
kolaente Apr 15, 2018
a1b79fe
Removed unnessecary Issue.DeadlineString
kolaente Apr 15, 2018
e659699
UI improvements
kolaente Apr 15, 2018
bdec65a
Small improvments to comment creation
kolaente Apr 16, 2018
38e1180
merge with gitea-master
kolaente Apr 16, 2018
51d3e4f
merge with gitea-master
kolaente Apr 16, 2018
5c93fe0
Check if an issue is overdue is now a seperate function
kolaente Apr 17, 2018
7292c30
Updated go-sdk with govendor as it was merged
kolaente Apr 17, 2018
6fb31d6
fmt
kolaente Apr 17, 2018
3ae5b7a
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Apr 17, 2018
0b18607
Simplified isOverdue method
kolaente Apr 18, 2018
2efba88
removed unessecary deadline to 0 set
kolaente Apr 18, 2018
d8ba5ab
Merge with gitea-master
kolaente Apr 20, 2018
674d2ed
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Apr 21, 2018
b8760ba
Update swagger definitions
kolaente Apr 21, 2018
c88a59d
Added missing return
kolaente Apr 22, 2018
7c0e537
Added an explanary comment
kolaente Apr 23, 2018
30a2c70
Improved updateIssueDeadline method so it'll only update `deadline_unix`
kolaente Apr 23, 2018
bf2d849
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Apr 23, 2018
30dbda4
Small changes and improvements
kolaente Apr 27, 2018
b9f193a
Added check if a deadline was modified before updating it
kolaente Apr 27, 2018
3c8216f
Moved comment creating logic into its own function
kolaente Apr 27, 2018
fb7463f
Code cleanup for creating deadline comment
kolaente Apr 27, 2018
1c47d90
locale improvement
kolaente Apr 27, 2018
81c93d6
When modifying a deadline, the old deadline is saved with the comment
kolaente Apr 27, 2018
d02d09c
fmt
kolaente Apr 27, 2018
253d48f
Merge branch 'master' into issue-due-date
lunny Apr 29, 2018
c17c95b
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Apr 29, 2018
d7f4798
small improvments to xorm session handling when updating an issue dea…
kolaente Apr 29, 2018
f35fec0
small improvments to xorm session handling when updating an issue dea…
kolaente Apr 29, 2018
1412580
style nitpicks
kolaente Apr 29, 2018
fe68965
Moved checking for if the user has write acces to middleware
kolaente Apr 29, 2018
65e841d
Merge branch 'master' of https://github.com/go-gitea/gitea into issue…
kolaente Apr 29, 2018
311dc73
Merge with gitea-master
kolaente May 1, 2018
8d3fff2
Merge with gitea-master
kolaente May 1, 2018
3f570d4
renamed remove deadline url
kolaente May 1, 2018
a7a9529
Deleting a deadline is now possible via get
kolaente May 1, 2018
d49dd2f
Reverted deleting a deadline back to using a post request
kolaente May 1, 2018
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
60 changes: 56 additions & 4 deletions models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ type Issue struct {
NumComments int
Ref string

DeadlineUnix util.TimeStamp `xorm:"INDEX"`
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
ClosedUnix util.TimeStamp `xorm:"INDEX"`
DeadlineUnix util.TimeStamp `xorm:"INDEX"`
DeadlineString string `xorm:"-"`
Copy link
Member

Choose a reason for hiding this comment

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

It seems this field is unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it is needed to show the deadline in templates.

Copy link
Member

Choose a reason for hiding this comment

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

You could use something like .DeadlineUnix.FormatShort.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I didn't know that function exists.

On another note, what do you think about putting date formats in the corresponding locale files meaning we could have different date formats for every locale?

IsOverDue bool `xorm:"-"`

CreatedUnix util.TimeStamp `xorm:"INDEX created"`
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
ClosedUnix util.TimeStamp `xorm:"INDEX"`

Attachments []*Attachment `xorm:"-"`
Comments []*Comment `xorm:"-"`
Expand All @@ -69,6 +72,14 @@ func init() {
issueTasksDonePat = regexp.MustCompile(issueTasksDoneRegexpStr)
}

// AfterLoad formats the unix deadline into a human-readable format
func (issue *Issue) AfterLoad() {
issue.DeadlineString = issue.DeadlineUnix.Format("2006-01-02")
if util.TimeStampNow() >= issue.DeadlineUnix {
Copy link
Member

Choose a reason for hiding this comment

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

how about return util.TimeStampNow() >= issue.DeadlineUnix

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

issue.IsOverDue = true
Copy link
Member

Choose a reason for hiding this comment

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

why not just change IsOverDue as a method of Issue?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, I've changed it.

}
}

func (issue *Issue) loadRepo(e Engine) (err error) {
if issue.Repo == nil {
issue.Repo, err = getRepositoryByID(e, issue.RepoID)
Expand Down Expand Up @@ -324,6 +335,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
}
Expand Down Expand Up @@ -1498,3 +1512,41 @@ func updateIssue(e Engine, issue *Issue) error {
func UpdateIssue(issue *Issue) error {
return updateIssue(x, issue)
}

// UpdateIssueDeadline does what it says
Copy link
Member

Choose a reason for hiding this comment

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

Please correct comment...

Copy link
Member Author

Choose a reason for hiding this comment

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

How? Do you want me to write something like UpdateIssueDeadline updates an issue deadline?

Copy link
Member

Choose a reason for hiding this comment

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

That's better. And does it really update only deadline? I think it updates all given fields right now.

Copy link
Member

Choose a reason for hiding this comment

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

It also creates comments. I am not sure if it is good. Maybe better to add comments directly in udate/remove deadline function?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's better. And does it really update only deadline? I think it updates all given fields right now.

Well, it updates all fields to its old value + issueDeadline to the new value. Although I think xorm does some magic here and only updates the fields which did not change.

It also creates comments. I am not sure if it is good. Maybe better to add comments directly in udate/remove deadline function?

This is the function which updates/removes the deadline...

Copy link
Member

@Morlinest Morlinest Apr 23, 2018

Choose a reason for hiding this comment

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

So the only diff between this function and updateIssue is that this func creates comments. Function doesn't know what are the fields of issue, who and why set it to given values, only caller knows it (function doesn't know context about when it is called, I can call it from anywhere). If I look at implementation, more meaningful explanation is "UpdateIssueDeadline creates deadline comment and updates issue".

I don't think Xorm is so magical. As I know, it can ignore default values, but doesn't know what is updated. But you can check it by turning on sql logging so we can be sure about that.

Sry, I should be more concrete about "update/remove" functions. I meant UpdateDeadline and RemoveDeadline. But as there is not xorm.Session it can not be called from there directly.

Edit: OK, you updated it in meanwhile so this comment is not 100% relevant now :)

func UpdateIssueDeadline(issue *Issue, doer *User) (err error) {
Copy link
Member

Choose a reason for hiding this comment

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

You can change this to func UpdateIssueDeadline(issue *Issue, DeadlineUnix util.TimeStamp, doer *User) error {. Then you can remove actualIssue.

Copy link
Member Author

Choose a reason for hiding this comment

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

But wouldn't that mean to get the actual deadline before calling the function?

Copy link
Member

Choose a reason for hiding this comment

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

It looks like issue is already loaded, so no reason to do it again. Just don't rewrite it before calling this function and add DeadlineUnix as second parameter.

IMO only issue deadline should be updated, not everything.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like this?

	var deadline util.TimeStamp
	if form.Deadline != nil && !form.Deadline.IsZero() {
		deadline  = util.TimeStamp(form.Deadline.Unix())
	}
	if err := models.UpdateIssueDeadline(issue, deadline, ctx.User); err != nil {
		ctx.Error(500, "UpdateIssueDeadline", err)
	}

Copy link
Member Author

Choose a reason for hiding this comment

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

But I'd still need to check if the issue deadline hasn't changed meanwhile.

Copy link
Member

Choose a reason for hiding this comment

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

func UpdateIssueDeadline(issue *Issue, repo *Repository, deadlineUnix util.TimeStamp, doer *User) error

Maybe check if new deadline is different than old deadline? So we don't create comments nor update issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I haven't thought of that.


// Check if the new date was added or modified
var actualIssue Issue
if _, err := x.ID(issue.ID).Get(&actualIssue); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

  1. Do you really need to load whole issue?
  2. You should load it only if needed (above L1535)

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. No, technically I only need DeadlineUnix, but I don't think this has a huge impact if I either load the full issue or only DeadlineUnix. Is that even possible with xorm?
  2. I'd need it in both cases (L1535 & L1529)

Copy link
Member

Choose a reason for hiding this comment

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

  1. It should be possible.
  2. You are right, i missed that one line.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed it to only get and update deadline_unix.

return fmt.Errorf("getActualIssue: %v", err)
}

sess := x.NewSession()
Copy link
Member

Choose a reason for hiding this comment

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

Now, do we really need this session? What you want to achieve here?

From xorm readme:

Multiple operations in one go routine, no transation here but resue session memory

Copy link
Member Author

Choose a reason for hiding this comment

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

I need that session to create the comment.

defer sess.Close()
Copy link
Member

Choose a reason for hiding this comment

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

defer sess.Close() should be after sess := x.NewSession() and before sess.Begin()

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, fixed.


if err = issue.loadRepo(sess); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Not needed.

return fmt.Errorf("loadRepo: %v", err)
}

// Make the comment
if issue.DeadlineUnix == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

We can move this if/else to createDeadlineComments to be consistent (no other create*Comment function takes CommentType as argument)
createDeadlineComment(sess, doer, repo, issue, issue.DeadlineUnix, deadlineUnix)

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

if _, err = createRemovedDeadlineComment(sess, doer, issue.Repo, issue, actualIssue.DeadlineUnix); err != nil {
return fmt.Errorf("createRemovedDueDateComment: %v", err)
}
} else {
// Check if the new date was added or modified
// If the actual deadline is 0 => deadline added
if actualIssue.DeadlineUnix == 0 {
if _, err = createAddedDeadlineComment(sess, doer, issue.Repo, issue, issue.DeadlineUnix); err != nil {
return fmt.Errorf("createRemovedDueDateComment: %v", err)
}
} else { // Otherwise modified
if _, err = createModifiedDeadlineComment(sess, doer, issue.Repo, issue, issue.DeadlineUnix); err != nil {
return fmt.Errorf("createRemovedDueDateComment: %v", err)
}
}
}

return UpdateIssue(issue)
Copy link
Member

Choose a reason for hiding this comment

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

this should be err = updateIssue(sess, issue) and need sess.Commit()

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

}
45 changes: 45 additions & 0 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -485,6 +491,45 @@ func createAssigneeComment(e *xorm.Session, doer *User, repo *Repository, issue
})
}

func createAddedDeadlineComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, dateUnix util.TimeStamp) (*Comment, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that you could pack all of these create...DeadlineComment functions into one function with an additional parameter type (please also check if the type is a valid deadline type).

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, good idea!

// Make string from unix date
date := dateUnix.Format("2006-01-02")

return createComment(e, &CreateCommentOptions{
Type: CommentTypeAddedDeadline,
Doer: doer,
Repo: repo,
Issue: issue,
Content: date,
})
}

func createModifiedDeadlineComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, dateUnix util.TimeStamp) (*Comment, error) {
// Make string from unix date
date := dateUnix.Format("2006-01-02")

return createComment(e, &CreateCommentOptions{
Type: CommentTypeModifiedDeadline,
Doer: doer,
Repo: repo,
Issue: issue,
Content: date,
})
}

func createRemovedDeadlineComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, dateUnix util.TimeStamp) (*Comment, error) {
// Make string from unix date
date := dateUnix.Format("2006-01-02")

return createComment(e, &CreateCommentOptions{
Type: CommentTypeRemovedDeadline,
Doer: doer,
Repo: repo,
Issue: issue,
Content: date,
})
}

func createChangeTitleComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, oldTitle, newTitle string) (*Comment, error) {
return createComment(e, &CreateCommentOptions{
Type: CommentTypeChangeTitle,
Expand Down
1 change: 1 addition & 0 deletions models/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down
10 changes: 10 additions & 0 deletions modules/auth/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,13 @@ func (f *AddTimeManuallyForm) Validate(ctx *macaron.Context, errs binding.Errors
type SaveTopicForm struct {
Topics []string `binding:"topics;Required;"`
}

// DeadlineForm hold the validation rules for deadlines
type DeadlineForm struct {
DateString string `form:"date" binding:"Required;MaxSize(10)"`
Copy link
Member

Choose a reason for hiding this comment

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

Replace MaxSize with Size since a yyyy-mm-dd date has always 10 characters.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I didn't know Size exists.

}

// Validate validates the fields
func (f *DeadlineForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
return validate(errs, ctx.Data, f, ctx.Locale)
}
13 changes: 13 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,19 @@ issues.add_time_sum_to_small = No time was entered
issues.cancel_tracking = Cancel
issues.cancel_tracking_history = `cancelled time tracking %s`
issues.time_spent_total = Total time spent
issues.due_date = Due date
issues.invalid_due_date_format = "Due date format is invalid, must be 'yyyy-mm-dd'."
issues.error_modifying_due_date = "An error occured while modifying the due date."
issues.error_removing_due_date = "An error occured while remvoing the due date."
issues.due_date_form = "Due date, format yyyy-mm-dd"
Copy link
Member

Choose a reason for hiding this comment

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

I think that

format yyyy-mm-dd

could be confusing for users from non-english countries (like Germany) because modern browsers use for the UI the local date format (in Germany: dd.mm.yyyy) and as value yyyy-mm-dd. (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#Value)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but that value is used as a placeholder for the input. If the browser supports input type date, the browser does what you described thus not showing the placeholder at all (because there's already something inside that field).

Some screenshots with an empty input:

Firefox:
bildschirmfoto von 2018-04-16 18-42-51

Chromium:
bildschirmfoto von 2018-04-16 18-43-22

The format doesnt really seem to be an issue here.

Also, currently the date is not localized anywhere, so if we'd start doing that here we should do it everywhere which is totally out of scope for this pr.

Copy link
Member

Choose a reason for hiding this comment

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

If the placeholder isn't shown at all it could be removed to reduce translation effort.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is shown when the browser doesn't support the <input type="date"/> tag, so I'd leave that.

issues.due_date_form_add = "Add due date"
issues.due_date_form_update = "Update due date"
issues.due_date_form_remove = "Remove due date"
issues.due_date_not_writer = "You need to have at least write access to this repository in order to update the due date for this issue."
issues.due_date_not_set = "No due date set."
issues.due_date_added = "added the due date %s %s"
issues.due_date_modified = "modified the due date to %s %s"
issues.due_date_remove = "removed the due date %s %s"

pulls.desc = Pulls management your code review and merge requests
pulls.new = New Pull Request
Expand Down
2 changes: 1 addition & 1 deletion public/css/index.css

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2193,4 +2193,15 @@ function initTopicbar() {
},
},
});
}
}
function toggleDuedateForm() {
$('#add_deadline_form').fadeToggle(150);
}

function deleteDueDate(url) {
$.post(url, {
'_csrf': csrf,
},function( data ) {
window.location.reload();
});
}
3 changes: 3 additions & 0 deletions public/less/_repository.less
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,9 @@
margin-top: -5px;
margin-right: 5px;
}
.overdue{
color: red;
}
}
}
}
Expand Down
57 changes: 57 additions & 0 deletions public/swagger.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -4325,6 +4325,32 @@
}
}
},
"/topics/search": {
"get": {
"produces": [
"application/json"
],
"tags": [
"repository"
],
"summary": "search topics via keyword",
"operationId": "topicSearch",
"parameters": [
{
"type": "integer",
"description": "id of the repo to get",
"name": "keyword",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"$ref": "#/responses/Repository"
}
}
}
},
"/user": {
"get": {
"produces": [
Expand Down Expand Up @@ -5521,6 +5547,12 @@
"type": "boolean",
"x-go-name": "Closed"
},
"due_date": {
"description": "deadline",
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
},
"labels": {
"description": "list of label ids",
"type": "array",
Expand Down Expand Up @@ -5657,6 +5689,11 @@
"type": "string",
"x-go-name": "Body"
},
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
},
"head": {
"type": "string",
"x-go-name": "Head"
Expand Down Expand Up @@ -5962,6 +5999,11 @@
"type": "string",
"x-go-name": "Body"
},
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
},
"milestone": {
"type": "integer",
"format": "int64",
Expand Down Expand Up @@ -6052,6 +6094,11 @@
"type": "string",
"x-go-name": "Body"
},
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
},
"labels": {
"type": "array",
"items": {
Expand Down Expand Up @@ -6315,6 +6362,11 @@
"format": "date-time",
"x-go-name": "Created"
},
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
},
"id": {
"type": "integer",
"format": "int64",
Expand Down Expand Up @@ -6733,6 +6785,11 @@
"type": "string",
"x-go-name": "DiffURL"
},
"due_date": {
"type": "string",
"format": "date-time",
"x-go-name": "Deadline"
},
"head": {
"$ref": "#/definitions/PRBranchInfo"
},
Expand Down
27 changes: 22 additions & 5 deletions routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,20 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
// responses:
// "201":
// "$ref": "#/responses/Issue"

var deadline util.TimeStamp
deadline = util.TimeStamp(0)
Copy link
Member

Choose a reason for hiding this comment

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

This line could be removed I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems logic, I removed that.

if form.Deadline != nil {
deadline = util.TimeStamp(form.Deadline.Unix())
}

issue := &models.Issue{
RepoID: ctx.Repo.Repository.ID,
Title: form.Title,
PosterID: ctx.User.ID,
Poster: ctx.User,
Content: form.Body,
RepoID: ctx.Repo.Repository.ID,
Title: form.Title,
PosterID: ctx.User.ID,
Poster: ctx.User,
Content: form.Body,
DeadlineUnix: deadline,
}

if ctx.Repo.IsWriter() {
Expand Down Expand Up @@ -265,6 +273,15 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
issue.Content = *form.Body
}

if form.Deadline != nil && !form.Deadline.IsZero() {
issue.DeadlineUnix = util.TimeStamp(form.Deadline.Unix())
} else {
issue.DeadlineUnix = util.TimeStamp(0)
}
if err := models.UpdateIssueDeadline(issue, ctx.User); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

	var deadlineUnix util.TimeStamp
	if form.Deadline != nil && !form.Deadline.IsZero() {
		deadlineUnix = util.TimeStamp(form.Deadline.Unix())
	}
	if err := models.UpdateIssueDeadline(issue, ctx.Repo.Repository, deadlineUnix, ctx.User); err != nil {

Copy link
Member Author

Choose a reason for hiding this comment

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

What do I need the repo for?

Copy link
Member

Choose a reason for hiding this comment

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

for createDeadlineComment

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, but isn't the repo already available in issue.Repo?

ctx.Error(500, "UpdateIssueDeadline", err)
Copy link
Member

Choose a reason for hiding this comment

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

Missing return?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably. I've added one (same for pull.go).

}

if ctx.Repo.IsWriter() && form.Assignee != nil &&
(issue.Assignee == nil || issue.Assignee.LowerName != strings.ToLower(*form.Assignee)) {
if len(*form.Assignee) == 0 {
Expand Down
Loading