Skip to content

Commit 0b58f58

Browse files
authored
Merge branch 'main' into fix-git-lfs
2 parents 01c0ac5 + 24b83ff commit 0b58f58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+544
-493
lines changed

models/actions/schedule_spec_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ import (
77
"testing"
88
"time"
99

10+
"code.gitea.io/gitea/modules/test"
11+
1012
"github.com/stretchr/testify/assert"
1113
"github.com/stretchr/testify/require"
1214
)
1315

1416
func TestActionScheduleSpec_Parse(t *testing.T) {
1517
// Mock the local timezone is not UTC
16-
local := time.Local
1718
tz, err := time.LoadLocation("Asia/Shanghai")
1819
require.NoError(t, err)
19-
defer func() {
20-
time.Local = local
21-
}()
22-
time.Local = tz
20+
defer test.MockVariableValue(&time.Local, tz)()
2321

2422
now, err := time.Parse(time.RFC3339, "2024-07-31T15:47:55+08:00")
2523
require.NoError(t, err)

models/issues/milestone.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ func (m *Milestone) BeforeUpdate() {
8484
// this object.
8585
func (m *Milestone) AfterLoad() {
8686
m.NumOpenIssues = m.NumIssues - m.NumClosedIssues
87-
if m.DeadlineUnix.Year() == 9999 {
87+
if m.DeadlineUnix == 0 {
8888
return
8989
}
90-
9190
m.DeadlineString = m.DeadlineUnix.FormatDate()
9291
if m.IsClosed {
9392
m.IsOverdue = m.ClosedDateUnix >= m.DeadlineUnix

models/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ func prepareMigrationTasks() []*migration {
364364
newMigration(304, "Add index for release sha1", v1_23.AddIndexForReleaseSha1),
365365
newMigration(305, "Add Repository Licenses", v1_23.AddRepositoryLicenses),
366366
newMigration(306, "Add BlockAdminMergeOverride to ProtectedBranch", v1_23.AddBlockAdminMergeOverrideBranchProtection),
367+
newMigration(307, "Fix milestone deadline_unix when there is no due date", v1_23.FixMilestoneNoDueDate),
367368
}
368369
return preparedMigrations
369370
}

models/migrations/v1_23/v307.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_23 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/timeutil"
8+
9+
"xorm.io/xorm"
10+
)
11+
12+
func FixMilestoneNoDueDate(x *xorm.Engine) error {
13+
type Milestone struct {
14+
DeadlineUnix timeutil.TimeStamp
15+
}
16+
// Wednesday, December 1, 9999 12:00:00 AM GMT+00:00
17+
_, err := x.Table("milestone").Where("deadline_unix > 253399622400").
18+
Cols("deadline_unix").
19+
Update(&Milestone{DeadlineUnix: 0})
20+
return err
21+
}

models/repo/user_repo.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,28 @@ func GetRepoAssignees(ctx context.Context, repo *Repository) (_ []*user_model.Us
110110
return nil, err
111111
}
112112

113-
additionalUserIDs := make([]int64, 0, 10)
114-
if err = e.Table("team_user").
115-
Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
116-
Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
117-
Where("`team_repo`.repo_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
118-
repo.ID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
119-
Distinct("`team_user`.uid").
120-
Select("`team_user`.uid").
121-
Find(&additionalUserIDs); err != nil {
122-
return nil, err
123-
}
124-
125113
uniqueUserIDs := make(container.Set[int64])
126114
uniqueUserIDs.AddMultiple(userIDs...)
127-
uniqueUserIDs.AddMultiple(additionalUserIDs...)
115+
116+
if repo.Owner.IsOrganization() {
117+
additionalUserIDs := make([]int64, 0, 10)
118+
if err = e.Table("team_user").
119+
Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
120+
Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
121+
Where("`team_repo`.repo_id = ? AND (`team_unit`.access_mode >= ? OR (`team_unit`.access_mode = ? AND `team_unit`.`type` = ?))",
122+
repo.ID, perm.AccessModeWrite, perm.AccessModeRead, unit.TypePullRequests).
123+
Distinct("`team_user`.uid").
124+
Select("`team_user`.uid").
125+
Find(&additionalUserIDs); err != nil {
126+
return nil, err
127+
}
128+
uniqueUserIDs.AddMultiple(additionalUserIDs...)
129+
}
128130

129131
// Leave a seat for owner itself to append later, but if owner is an organization
130132
// and just waste 1 unit is cheaper than re-allocate memory once.
131133
users := make([]*user_model.User, 0, len(uniqueUserIDs)+1)
132-
if len(userIDs) > 0 {
134+
if len(uniqueUserIDs) > 0 {
133135
if err = e.In("id", uniqueUserIDs.Values()).
134136
Where(builder.Eq{"`user`.is_active": true}).
135137
OrderBy(user_model.GetOrderByName()).

modules/gitgraph/graph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func GetCommitGraph(r *git.Repository, page, maxAllowedColors int, hidePRRefs bo
3232
graphCmd.AddArguments("--all")
3333
}
3434

35-
graphCmd.AddArguments("-C", "-M", "--date=iso").
35+
graphCmd.AddArguments("-C", "-M", "--date=iso-strict").
3636
AddOptionFormat("-n %d", setting.UI.GraphMaxCommitNum*page).
3737
AddOptionFormat("--pretty=format:%s", format)
3838

modules/gitgraph/graph_models.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"strings"
11+
"time"
1112

1213
asymkey_model "code.gitea.io/gitea/models/asymkey"
1314
"code.gitea.io/gitea/models/db"
@@ -192,6 +193,14 @@ var RelationCommit = &Commit{
192193
Row: -1,
193194
}
194195

196+
func parseGitTime(timeStr string) time.Time {
197+
t, err := time.Parse(time.RFC3339, timeStr)
198+
if err != nil {
199+
return time.Unix(0, 0)
200+
}
201+
return t
202+
}
203+
195204
// NewCommit creates a new commit from a provided line
196205
func NewCommit(row, column int, line []byte) (*Commit, error) {
197206
data := bytes.SplitN(line, []byte("|"), 5)
@@ -206,7 +215,7 @@ func NewCommit(row, column int, line []byte) (*Commit, error) {
206215
// 1 matches git log --pretty=format:%H => commit hash
207216
Rev: string(data[1]),
208217
// 2 matches git log --pretty=format:%ad => author date (format respects --date= option)
209-
Date: string(data[2]),
218+
Date: parseGitTime(string(data[2])),
210219
// 3 matches git log --pretty=format:%h => abbreviated commit hash
211220
ShortRev: string(data[3]),
212221
// 4 matches git log --pretty=format:%s => subject
@@ -245,7 +254,7 @@ type Commit struct {
245254
Column int
246255
Refs []git.Reference
247256
Rev string
248-
Date string
257+
Date time.Time
249258
ShortRev string
250259
Subject string
251260
}

modules/templates/helper.go

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ func NewFuncMap() template.FuncMap {
7373
return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
7474
},
7575

76-
// for backward compatibility only, do not use them anymore
77-
"TimeSince": timeSinceLegacy,
78-
"TimeSinceUnix": timeSinceLegacy,
79-
"DateTime": dateTimeLegacy,
80-
8176
// -----------------------------------------------------------------
8277
// setting
8378
"AppName": func() string {
@@ -156,18 +151,8 @@ func NewFuncMap() template.FuncMap {
156151

157152
// -----------------------------------------------------------------
158153
// render
159-
"RenderCommitMessage": RenderCommitMessage,
160-
"RenderCommitMessageLinkSubject": renderCommitMessageLinkSubject,
161-
162-
"RenderCommitBody": renderCommitBody,
163-
"RenderCodeBlock": renderCodeBlock,
164-
"RenderIssueTitle": renderIssueTitle,
165-
"RenderEmoji": renderEmoji,
166-
"ReactionToEmoji": reactionToEmoji,
167-
168-
"RenderMarkdownToHtml": RenderMarkdownToHtml,
169-
"RenderLabel": renderLabel,
170-
"RenderLabels": RenderLabels,
154+
"RenderCodeBlock": renderCodeBlock,
155+
"ReactionToEmoji": reactionToEmoji,
171156

172157
// -----------------------------------------------------------------
173158
// misc
@@ -179,6 +164,22 @@ func NewFuncMap() template.FuncMap {
179164

180165
"FilenameIsImage": filenameIsImage,
181166
"TabSizeClass": tabSizeClass,
167+
168+
// for backward compatibility only, do not use them anymore
169+
"TimeSince": timeSinceLegacy,
170+
"TimeSinceUnix": timeSinceLegacy,
171+
"DateTime": dateTimeLegacy,
172+
173+
"RenderEmoji": renderEmojiLegacy,
174+
"RenderLabel": renderLabelLegacy,
175+
"RenderLabels": renderLabelsLegacy,
176+
"RenderIssueTitle": renderIssueTitleLegacy,
177+
178+
"RenderMarkdownToHtml": renderMarkdownToHtmlLegacy,
179+
180+
"RenderCommitMessage": renderCommitMessageLegacy,
181+
"RenderCommitMessageLinkSubject": renderCommitMessageLinkSubjectLegacy,
182+
"RenderCommitBody": renderCommitBodyLegacy,
182183
}
183184
}
184185

@@ -296,3 +297,9 @@ func userThemeName(user *user_model.User) string {
296297
}
297298
return setting.UI.DefaultTheme
298299
}
300+
301+
func panicIfDevOrTesting() {
302+
if !setting.IsProd || setting.IsInTesting {
303+
panic("legacy template functions are for backward compatibility only, do not use them in new code")
304+
}
305+
}

modules/templates/util_date.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"code.gitea.io/gitea/modules/setting"
1414
"code.gitea.io/gitea/modules/timeutil"
15-
"code.gitea.io/gitea/modules/translation"
1615
)
1716

1817
type DateUtils struct{}
@@ -28,7 +27,7 @@ func (du *DateUtils) AbsoluteShort(time any) template.HTML {
2827

2928
// AbsoluteLong renders in "January 01, 2006" format
3029
func (du *DateUtils) AbsoluteLong(time any) template.HTML {
31-
return dateTimeFormat("short", time)
30+
return dateTimeFormat("long", time)
3231
}
3332

3433
// FullTime renders in "Jan 01, 2006 20:33:44" format
@@ -54,23 +53,6 @@ func parseLegacy(datetime string) time.Time {
5453
return t
5554
}
5655

57-
func dateTimeLegacy(format string, datetime any, _ ...string) template.HTML {
58-
if !setting.IsProd || setting.IsInTesting {
59-
panic("dateTimeLegacy is for backward compatibility only, do not use it in new code")
60-
}
61-
if s, ok := datetime.(string); ok {
62-
datetime = parseLegacy(s)
63-
}
64-
return dateTimeFormat(format, datetime)
65-
}
66-
67-
func timeSinceLegacy(time any, _ translation.Locale) template.HTML {
68-
if !setting.IsProd || setting.IsInTesting {
69-
panic("timeSinceLegacy is for backward compatibility only, do not use it in new code")
70-
}
71-
return TimeSince(time)
72-
}
73-
7456
func anyToTime(any any) (t time.Time, isZero bool) {
7557
switch v := any.(type) {
7658
case nil:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package templates
5+
6+
import (
7+
"html/template"
8+
9+
"code.gitea.io/gitea/modules/translation"
10+
)
11+
12+
func dateTimeLegacy(format string, datetime any, _ ...string) template.HTML {
13+
panicIfDevOrTesting()
14+
if s, ok := datetime.(string); ok {
15+
datetime = parseLegacy(s)
16+
}
17+
return dateTimeFormat(format, datetime)
18+
}
19+
20+
func timeSinceLegacy(time any, _ translation.Locale) template.HTML {
21+
panicIfDevOrTesting()
22+
return TimeSince(time)
23+
}

0 commit comments

Comments
 (0)