Skip to content

Commit

Permalink
Fix deleted milestone bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ethantkoenig committed Jun 15, 2017
1 parent b7d597e commit 2e5dee4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
16 changes: 7 additions & 9 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,14 @@ func (c *Comment) LoadLabel() error {
func (c *Comment) LoadMilestone() error {
if c.OldMilestoneID > 0 {
var oldMilestone Milestone
has, err := x.ID(c.OldMilestoneID).Get(&oldMilestone)
has, err := x.ID(c.OldMilestoneID).Get(oldMilestone)
if err != nil {
return err
} else if !has {
return ErrMilestoneNotExist{
ID: c.OldMilestoneID,
}
c.OldMilestone = NewGhostMilestone()
} else {
c.OldMilestone = &oldMilestone
}
c.OldMilestone = &oldMilestone
}

if c.MilestoneID > 0 {
Expand All @@ -245,11 +244,10 @@ func (c *Comment) LoadMilestone() error {
if err != nil {
return err
} else if !has {
return ErrMilestoneNotExist{
ID: c.MilestoneID,
}
c.Milestone = NewGhostMilestone()
} else {
c.Milestone = &milestone
}
c.Milestone = &milestone
}
return nil
}
Expand Down
8 changes: 8 additions & 0 deletions models/issue_milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ func NewMilestone(m *Milestone) (err error) {
return sess.Commit()
}

// NewGhostMilestone a fake milestone to hold the place of a deleted milestone
func NewGhostMilestone() *Milestone {
return &Milestone{
ID: -1,
Name: "Deleted",
}
}

func getMilestoneByRepoID(e Engine, repoID, id int64) (*Milestone, error) {
m := &Milestone{
ID: id,
Expand Down

0 comments on commit 2e5dee4

Please sign in to comment.