Skip to content

Commit 5647c41

Browse files
authored
Merge branch 'main' into support-trace
2 parents 8fdccb0 + b7614e2 commit 5647c41

Some content is hidden

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

49 files changed

+266
-316
lines changed

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@
2929
poetry
3030

3131
# backend
32+
go_1_23
3233
gofumpt
3334
sqlite
3435
];
36+
shellHook = ''
37+
export GO="${pkgs.go_1_23}/bin/go"
38+
export GOROOT="${pkgs.go_1_23}/share/go"
39+
'';
3540
};
3641
}
3742
);

models/git/branch.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ type FindRecentlyPushedNewBranchesOptions struct {
440440
}
441441

442442
type RecentlyPushedNewBranch struct {
443+
BranchRepo *repo_model.Repository
444+
BranchName string
443445
BranchDisplayName string
444446
BranchLink string
445447
BranchCompareURL string
@@ -540,7 +542,9 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o
540542
branchDisplayName = fmt.Sprintf("%s:%s", branch.Repo.FullName(), branchDisplayName)
541543
}
542544
newBranches = append(newBranches, &RecentlyPushedNewBranch{
545+
BranchRepo: branch.Repo,
543546
BranchDisplayName: branchDisplayName,
547+
BranchName: branch.Name,
544548
BranchLink: fmt.Sprintf("%s/src/branch/%s", branch.Repo.Link(), util.PathEscapeSegments(branch.Name)),
545549
BranchCompareURL: branch.Repo.ComposeBranchCompareURL(opts.BaseRepo, branch.Name),
546550
CommitTime: branch.CommitTime,

models/issues/stopwatch.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ func (s Stopwatch) Seconds() int64 {
4646
return int64(timeutil.TimeStampNow() - s.CreatedUnix)
4747
}
4848

49-
// Duration returns a human-readable duration string based on local server time
50-
func (s Stopwatch) Duration() string {
51-
return util.SecToTime(s.Seconds())
52-
}
53-
5449
func getStopwatch(ctx context.Context, userID, issueID int64) (sw *Stopwatch, exists bool, err error) {
5550
sw = new(Stopwatch)
5651
exists, err = db.GetEngine(ctx).
@@ -201,7 +196,7 @@ func FinishIssueStopwatch(ctx context.Context, user *user_model.User, issue *Iss
201196
Doer: user,
202197
Issue: issue,
203198
Repo: issue.Repo,
204-
Content: util.SecToTime(timediff),
199+
Content: util.SecToHours(timediff),
205200
Type: CommentTypeStopTracking,
206201
TimeID: tt.ID,
207202
}); err != nil {

modules/git/diff.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
6464
} else if commit.ParentCount() == 0 {
6565
cmd.AddArguments("show").AddDynamicArguments(endCommit).AddDashesAndList(files...)
6666
} else {
67-
c, _ := commit.Parent(0)
67+
c, err := commit.Parent(0)
68+
if err != nil {
69+
return err
70+
}
6871
cmd.AddArguments("diff", "-M").AddDynamicArguments(c.ID.String(), endCommit).AddDashesAndList(files...)
6972
}
7073
case RawDiffPatch:
@@ -74,7 +77,10 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
7477
} else if commit.ParentCount() == 0 {
7578
cmd.AddArguments("format-patch", "--no-signature", "--stdout", "--root").AddDynamicArguments(endCommit).AddDashesAndList(files...)
7679
} else {
77-
c, _ := commit.Parent(0)
80+
c, err := commit.Parent(0)
81+
if err != nil {
82+
return err
83+
}
7884
query := fmt.Sprintf("%s...%s", endCommit, c.ID.String())
7985
cmd.AddArguments("format-patch", "--no-signature", "--stdout").AddDynamicArguments(query).AddDashesAndList(files...)
8086
}

modules/repository/branch.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package repository
66
import (
77
"context"
88
"fmt"
9-
"strings"
109

1110
"code.gitea.io/gitea/models/db"
1211
git_model "code.gitea.io/gitea/models/git"
@@ -52,9 +51,6 @@ func SyncRepoBranchesWithRepo(ctx context.Context, repo *repo_model.Repository,
5251
{
5352
branches, _, err := gitRepo.GetBranchNames(0, 0)
5453
if err != nil {
55-
if strings.Contains(err.Error(), "ref file is empty") {
56-
return 0, nil
57-
}
5854
return 0, err
5955
}
6056
log.Trace("SyncRepoBranches[%s]: branches[%d]: %v", repo.FullName(), len(branches), branches)

modules/templates/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func NewFuncMap() template.FuncMap {
6969
// time / number / format
7070
"FileSize": base.FileSize,
7171
"CountFmt": countFmt,
72-
"Sec2Time": util.SecToTime,
72+
"Sec2Time": util.SecToHours,
7373

7474
"TimeEstimateString": timeEstimateString,
7575

modules/util/sec_to_time.go

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,17 @@ import (
88
"strings"
99
)
1010

11-
// SecToTime converts an amount of seconds to a human-readable string. E.g.
12-
// 66s -> 1 minute 6 seconds
13-
// 52410s -> 14 hours 33 minutes
14-
// 563418 -> 6 days 12 hours
15-
// 1563418 -> 2 weeks 4 days
16-
// 3937125s -> 1 month 2 weeks
17-
// 45677465s -> 1 year 6 months
18-
func SecToTime(durationVal any) string {
11+
// SecToHours converts an amount of seconds to a human-readable hours string.
12+
// This is stable for planning and managing timesheets.
13+
// Here it only supports hours and minutes, because a work day could contain 6 or 7 or 8 hours.
14+
func SecToHours(durationVal any) string {
1915
duration, _ := ToInt64(durationVal)
20-
21-
formattedTime := ""
22-
23-
// The following four variables are calculated by taking
24-
// into account the previously calculated variables, this avoids
25-
// pitfalls when using remainders. As that could lead to incorrect
26-
// results when the calculated number equals the quotient number.
27-
remainingDays := duration / (60 * 60 * 24)
28-
years := remainingDays / 365
29-
remainingDays -= years * 365
30-
months := remainingDays * 12 / 365
31-
remainingDays -= months * 365 / 12
32-
weeks := remainingDays / 7
33-
remainingDays -= weeks * 7
34-
days := remainingDays
35-
36-
// The following three variables are calculated without depending
37-
// on the previous calculated variables.
38-
hours := (duration / 3600) % 24
16+
hours := duration / 3600
3917
minutes := (duration / 60) % 60
40-
seconds := duration % 60
4118

42-
// Extract only the relevant information of the time
43-
// If the time is greater than a year, it makes no sense to display seconds.
44-
switch {
45-
case years > 0:
46-
formattedTime = formatTime(years, "year", formattedTime)
47-
formattedTime = formatTime(months, "month", formattedTime)
48-
case months > 0:
49-
formattedTime = formatTime(months, "month", formattedTime)
50-
formattedTime = formatTime(weeks, "week", formattedTime)
51-
case weeks > 0:
52-
formattedTime = formatTime(weeks, "week", formattedTime)
53-
formattedTime = formatTime(days, "day", formattedTime)
54-
case days > 0:
55-
formattedTime = formatTime(days, "day", formattedTime)
56-
formattedTime = formatTime(hours, "hour", formattedTime)
57-
case hours > 0:
58-
formattedTime = formatTime(hours, "hour", formattedTime)
59-
formattedTime = formatTime(minutes, "minute", formattedTime)
60-
default:
61-
formattedTime = formatTime(minutes, "minute", formattedTime)
62-
formattedTime = formatTime(seconds, "second", formattedTime)
63-
}
19+
formattedTime := ""
20+
formattedTime = formatTime(hours, "hour", formattedTime)
21+
formattedTime = formatTime(minutes, "minute", formattedTime)
6422

6523
// The formatTime() function always appends a space at the end. This will be trimmed
6624
return strings.TrimRight(formattedTime, " ")
@@ -76,6 +34,5 @@ func formatTime(value int64, name, formattedTime string) string {
7634
} else if value > 1 {
7735
formattedTime = fmt.Sprintf("%s%d %ss ", formattedTime, value, name)
7836
}
79-
8037
return formattedTime
8138
}

modules/util/sec_to_time_test.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,17 @@ import (
99
"github.com/stretchr/testify/assert"
1010
)
1111

12-
func TestSecToTime(t *testing.T) {
12+
func TestSecToHours(t *testing.T) {
1313
second := int64(1)
1414
minute := 60 * second
1515
hour := 60 * minute
1616
day := 24 * hour
17-
year := 365 * day
1817

19-
assert.Equal(t, "1 minute 6 seconds", SecToTime(minute+6*second))
20-
assert.Equal(t, "1 hour", SecToTime(hour))
21-
assert.Equal(t, "1 hour", SecToTime(hour+second))
22-
assert.Equal(t, "14 hours 33 minutes", SecToTime(14*hour+33*minute+30*second))
23-
assert.Equal(t, "6 days 12 hours", SecToTime(6*day+12*hour+30*minute+18*second))
24-
assert.Equal(t, "2 weeks 4 days", SecToTime((2*7+4)*day+2*hour+16*minute+58*second))
25-
assert.Equal(t, "4 weeks", SecToTime(4*7*day))
26-
assert.Equal(t, "4 weeks 1 day", SecToTime((4*7+1)*day))
27-
assert.Equal(t, "1 month 2 weeks", SecToTime((6*7+3)*day+13*hour+38*minute+45*second))
28-
assert.Equal(t, "11 months", SecToTime(year-25*day))
29-
assert.Equal(t, "1 year 5 months", SecToTime(year+163*day+10*hour+11*minute+5*second))
18+
assert.Equal(t, "1 minute", SecToHours(minute+6*second))
19+
assert.Equal(t, "1 hour", SecToHours(hour))
20+
assert.Equal(t, "1 hour", SecToHours(hour+second))
21+
assert.Equal(t, "14 hours 33 minutes", SecToHours(14*hour+33*minute+30*second))
22+
assert.Equal(t, "156 hours 30 minutes", SecToHours(6*day+12*hour+30*minute+18*second))
23+
assert.Equal(t, "98 hours 16 minutes", SecToHours(4*day+2*hour+16*minute+58*second))
24+
assert.Equal(t, "672 hours", SecToHours(4*7*day))
3025
}

options/locale/locale_cs-CZ.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,16 +1683,13 @@ issues.timetracker_timer_manually_add=Přidat čas
16831683

16841684
issues.time_estimate_set=Nastavit odhadovaný čas
16851685
issues.time_estimate_display=Odhad: %s
1686-
issues.change_time_estimate_at=změnil/a odhad času na <b>%s</b> %s
16871686
issues.remove_time_estimate_at=odstranil/a odhad času %s
16881687
issues.time_estimate_invalid=Formát odhadu času je neplatný
16891688
issues.start_tracking_history=započal/a práci %s
16901689
issues.tracker_auto_close=Časovač se automaticky zastaví po zavření tohoto úkolu
16911690
issues.tracking_already_started=`Již jste spustili sledování času na <a href="%s">jiném úkolu</a>!`
1692-
issues.stop_tracking_history=pracoval/a <b>%s</b> %s
16931691
issues.cancel_tracking_history=`zrušil/a sledování času %s`
16941692
issues.del_time=Odstranit tento časový záznam
1695-
issues.add_time_history=přidal/a strávený čas <b>%s</b> %s
16961693
issues.del_time_history=`odstranil/a strávený čas %s`
16971694
issues.add_time_manually=Přidat čas ručně
16981695
issues.add_time_hours=Hodiny
@@ -3566,7 +3563,6 @@ conda.install=Pro instalaci balíčku pomocí Conda spusťte následující př
35663563
container.details.type=Typ obrazu
35673564
container.details.platform=Platforma
35683565
container.pull=Stáhněte obraz z příkazové řádky:
3569-
container.digest=Výběr:
35703566
container.multi_arch=OS/architektura
35713567
container.layers=Vrstvy obrazů
35723568
container.labels=Štítky

0 commit comments

Comments
 (0)