Skip to content

Commit 495fee4

Browse files
Closed milestones with no issues now show as 100% completed (#36220)
Closed milestones with 0 issues currently display as having 0% completion. This makes sense if the milestone is still open, but if the milestone is closed it seems like that it should show 100% completeness instead. Before: <img width="1708" height="252" alt="image" src="https://github.com/user-attachments/assets/0b58c78f-0609-44ee-8d58-bd67534c6164" /> After: <img width="1716" height="263" alt="image" src="https://github.com/user-attachments/assets/3fb0044f-d76c-4888-9d60-640f2ca5fec6" />
1 parent 05c3b84 commit 495fee4

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

models/issues/milestone.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ func init() {
7575
func (m *Milestone) BeforeUpdate() {
7676
if m.NumIssues > 0 {
7777
m.Completeness = m.NumClosedIssues * 100 / m.NumIssues
78+
} else if m.IsClosed {
79+
m.Completeness = 100
7880
} else {
7981
m.Completeness = 0
8082
}
@@ -195,8 +197,8 @@ func UpdateMilestoneCounters(ctx context.Context, id int64) error {
195197
if err != nil {
196198
return err
197199
}
198-
_, err = e.Exec("UPDATE `milestone` SET completeness=100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) WHERE id=?",
199-
id,
200+
_, err = e.Exec("UPDATE `milestone` SET completeness=(CASE WHEN is_closed = ? AND num_issues = 0 THEN 100 ELSE 100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) END) WHERE id=?",
201+
true, id,
200202
)
201203
return err
202204
}
@@ -240,6 +242,11 @@ func changeMilestoneStatus(ctx context.Context, m *Milestone, isClosed bool) err
240242
if count < 1 {
241243
return nil
242244
}
245+
246+
if err := UpdateMilestoneCounters(ctx, m.ID); err != nil {
247+
return err
248+
}
249+
243250
return updateRepoMilestoneNum(ctx, m.RepoID)
244251
}
245252

models/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ func prepareMigrationTasks() []*migration {
398398
// Gitea 1.25.0 ends at migration ID number 322 (database version 323)
399399

400400
newMigration(323, "Add support for actions concurrency", v1_26.AddActionsConcurrency),
401+
newMigration(324, "Fix closed milestone completeness for milestones with no issues", v1_26.FixClosedMilestoneCompleteness),
401402
}
402403
return preparedMigrations
403404
}

models/migrations/v1_26/v324.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_26
5+
6+
import (
7+
"fmt"
8+
9+
"xorm.io/xorm"
10+
)
11+
12+
func FixClosedMilestoneCompleteness(x *xorm.Engine) error {
13+
// Update all milestones to recalculate completeness with the new logic:
14+
// - Closed milestones with 0 issues should show 100%
15+
// - All other milestones should calculate based on closed/total ratio
16+
_, err := x.Exec("UPDATE `milestone` SET completeness=(CASE WHEN is_closed = ? AND num_issues = 0 THEN 100 ELSE 100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) END)",
17+
true,
18+
)
19+
if err != nil {
20+
return fmt.Errorf("error updating milestone completeness: %w", err)
21+
}
22+
23+
return nil
24+
}

0 commit comments

Comments
 (0)