Skip to content

Commit 1a0ceec

Browse files
forgejo-backport-actionfloss4good
authored andcommitted
[v12.0/forgejo] fix: load OldMilestone based on OldMilestoneID, not MilestoneID (go-gitea#8349)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/8330 Fixes go-gitea#8329 ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. ### Documentation - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. Co-authored-by: floss4good <[email protected]> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8349 Reviewed-by: floss4good <[email protected]> Co-authored-by: forgejo-backport-action <[email protected]> Co-committed-by: forgejo-backport-action <[email protected]>
1 parent 164c5ef commit 1a0ceec

File tree

3 files changed

+70
-10
lines changed

3 files changed

+70
-10
lines changed

models/fixtures/comment.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,46 @@
186186
type: 8 # milestone
187187
poster_id: 1
188188
issue_id: 1 # in repo_id 1
189-
milestone_id: 10 # not exsting milestone
189+
milestone_id: 10 # not existing milestone
190190
old_milestone_id: 0
191191
created_unix: 946685080
192192

193+
-
194+
id: 2004
195+
type: 8 # milestone
196+
poster_id: 1
197+
issue_id: 1 # in repo_id 1
198+
milestone_id: 1
199+
old_milestone_id: 10 # not existing (ghost) milestone
200+
created_unix: 946685085
201+
202+
-
203+
id: 2005
204+
type: 8 # milestone
205+
poster_id: 1
206+
issue_id: 1 # in repo_id 1
207+
milestone_id: 10 # not existing (ghost) milestone
208+
old_milestone_id: 1
209+
created_unix: 946685090
210+
211+
-
212+
id: 2006
213+
type: 8 # milestone
214+
poster_id: 1
215+
issue_id: 1 # in repo_id 1
216+
milestone_id: 11 # not existing (ghost) milestone
217+
old_milestone_id: 10 # not existing (ghost) milestone
218+
created_unix: 946685095
219+
220+
-
221+
id: 2007
222+
type: 8 # milestone
223+
poster_id: 1
224+
issue_id: 1 # in repo_id 1
225+
milestone_id: 0
226+
old_milestone_id: 11 # not existing (ghost) milestone
227+
created_unix: 946685100
228+
193229
-
194230
id: 2010
195231
type: 30 # project

models/issues/comment_list.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (comments CommentList) loadMilestones(ctx context.Context) error {
101101
return nil
102102
}
103103

104-
milestoneMaps := make(map[int64]*Milestone, len(milestoneIDs))
104+
milestones := make(map[int64]*Milestone, len(milestoneIDs))
105105
left := len(milestoneIDs)
106106
for left > 0 {
107107
limit := db.DefaultMaxInSize
@@ -110,16 +110,16 @@ func (comments CommentList) loadMilestones(ctx context.Context) error {
110110
}
111111
err := db.GetEngine(ctx).
112112
In("id", milestoneIDs[:limit]).
113-
Find(&milestoneMaps)
113+
Find(&milestones)
114114
if err != nil {
115115
return err
116116
}
117117
left -= limit
118118
milestoneIDs = milestoneIDs[limit:]
119119
}
120120

121-
for _, issue := range comments {
122-
issue.Milestone = milestoneMaps[issue.MilestoneID]
121+
for _, comment := range comments {
122+
comment.Milestone = milestones[comment.MilestoneID]
123123
}
124124
return nil
125125
}
@@ -140,7 +140,7 @@ func (comments CommentList) loadOldMilestones(ctx context.Context) error {
140140
return nil
141141
}
142142

143-
milestoneMaps := make(map[int64]*Milestone, len(milestoneIDs))
143+
milestones := make(map[int64]*Milestone, len(milestoneIDs))
144144
left := len(milestoneIDs)
145145
for left > 0 {
146146
limit := db.DefaultMaxInSize
@@ -149,16 +149,16 @@ func (comments CommentList) loadOldMilestones(ctx context.Context) error {
149149
}
150150
err := db.GetEngine(ctx).
151151
In("id", milestoneIDs[:limit]).
152-
Find(&milestoneMaps)
152+
Find(&milestones)
153153
if err != nil {
154154
return err
155155
}
156156
left -= limit
157157
milestoneIDs = milestoneIDs[limit:]
158158
}
159159

160-
for _, issue := range comments {
161-
issue.OldMilestone = milestoneMaps[issue.MilestoneID]
160+
for _, comment := range comments {
161+
comment.OldMilestone = milestones[comment.OldMilestoneID]
162162
}
163163
return nil
164164
}

tests/integration/issue_comment_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,35 @@ func TestIssueCommentChangeMilestone(t *testing.T) {
102102
[]string{"user1 removed this from the milestone2 milestone"},
103103
[]string{"/user1", "/user2/repo1/milestone/2"})
104104

105-
// Deleted milestone
105+
// Added milestone that in the meantime was deleted
106106
testIssueCommentChangeEvent(t, htmlDoc, "2003",
107107
"octicon-milestone", "User One", "/user1",
108108
[]string{"user1 added this to the (deleted) milestone"},
109109
[]string{"/user1"})
110+
111+
// Modified milestone - from a meantime deleted one to a valid one
112+
testIssueCommentChangeEvent(t, htmlDoc, "2004",
113+
"octicon-milestone", "User One", "/user1",
114+
[]string{"user1 modified the milestone from (deleted) to milestone1"},
115+
[]string{"/user1", "/user2/repo1/milestone/1"})
116+
117+
// Modified milestone - from a valid one to a meantime deleted one
118+
testIssueCommentChangeEvent(t, htmlDoc, "2005",
119+
"octicon-milestone", "User One", "/user1",
120+
[]string{"user1 modified the milestone from milestone1 to (deleted)"},
121+
[]string{"/user1", "/user2/repo1/milestone/1"})
122+
123+
// Modified milestone - from a meantime deleted one to a meantime deleted one
124+
testIssueCommentChangeEvent(t, htmlDoc, "2006",
125+
"octicon-milestone", "User One", "/user1",
126+
[]string{"user1 modified the milestone from (deleted) to (deleted)"},
127+
[]string{"/user1"})
128+
129+
// Removed milestone that in the meantime was deleted
130+
testIssueCommentChangeEvent(t, htmlDoc, "2007",
131+
"octicon-milestone", "User One", "/user1",
132+
[]string{"user1 removed this from the (deleted) milestone"},
133+
[]string{"/user1"})
110134
}
111135

112136
func TestIssueCommentChangeProject(t *testing.T) {

0 commit comments

Comments
 (0)