From 07a6b6ce826630285b808366956c15a977c70fb7 Mon Sep 17 00:00:00 2001 From: Gusted Date: Fri, 1 May 2026 22:51:48 +0200 Subject: [PATCH] chore: make use of go1.26 features (#12369) Allows us to make use of Go features introduced in v1.26. I require a feature from v1.26 for a PR I want to make later. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12369 Reviewed-by: Mathieu Fenniak --- go.mod | 2 +- models/asymkey/gpg_key_test.go | 3 +- models/user/moderation.go | 4 +- modules/git/blame.go | 2 +- modules/jwtx/signingkey.go | 4 +- modules/util/util.go | 5 -- modules/util/util_test.go | 31 +++--------- routers/api/actions/artifactsv4.go | 2 +- routers/api/actions/oidc.go | 3 +- routers/web/repo/attachment.go | 3 +- services/actions/download.go | 3 +- services/migrations/codebase_test.go | 6 +-- services/migrations/gitea_downloader_test.go | 16 +++--- services/migrations/github_test.go | 16 +++--- services/migrations/gitlab_test.go | 10 ++-- services/migrations/main_test.go | 4 -- services/migrations/pagure_test.go | 52 +++++++++----------- 17 files changed, 66 insertions(+), 100 deletions(-) diff --git a/go.mod b/go.mod index 3813849121..d4b54ad8bf 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module forgejo.org -go 1.25.0 +go 1.26.0 toolchain go1.26.2 diff --git a/models/asymkey/gpg_key_test.go b/models/asymkey/gpg_key_test.go index d265f438eb..2da3bbe6e0 100644 --- a/models/asymkey/gpg_key_test.go +++ b/models/asymkey/gpg_key_test.go @@ -11,7 +11,6 @@ import ( "forgejo.org/models/unittest" user_model "forgejo.org/models/user" "forgejo.org/modules/timeutil" - "forgejo.org/modules/util" "github.com/ProtonMail/go-crypto/openpgp/packet" "github.com/stretchr/testify/assert" @@ -458,7 +457,7 @@ epiDVQ== func TestTryGetKeyIDFromSignature(t *testing.T) { assert.Empty(t, tryGetKeyIDFromSignature(&packet.Signature{})) assert.Equal(t, "038D1A3EADDBEA9C", tryGetKeyIDFromSignature(&packet.Signature{ - IssuerKeyId: util.ToPointer(uint64(0x38D1A3EADDBEA9C)), + IssuerKeyId: new(uint64(0x38D1A3EADDBEA9C)), })) assert.Equal(t, "038D1A3EADDBEA9C", tryGetKeyIDFromSignature(&packet.Signature{ IssuerFingerprint: []uint8{0xb, 0x23, 0x24, 0xc7, 0xe6, 0xfe, 0x4f, 0x3a, 0x6, 0x26, 0xc1, 0x21, 0x3, 0x8d, 0x1a, 0x3e, 0xad, 0xdb, 0xea, 0x9c}, diff --git a/models/user/moderation.go b/models/user/moderation.go index 765414acc0..fe8eef1806 100644 --- a/models/user/moderation.go +++ b/models/user/moderation.go @@ -89,8 +89,8 @@ var userDataColumnNames = sync.OnceValue(func() []string { mapper := new(names.GonicMapper) udType := reflect.TypeFor[UserData]() columnNames := make([]string, 0, udType.NumField()) - for i := 0; i < udType.NumField(); i++ { - columnNames = append(columnNames, mapper.Obj2Table(udType.Field(i).Name)) + for field := range udType.Fields() { + columnNames = append(columnNames, mapper.Obj2Table(field.Name)) } return columnNames }) diff --git a/modules/git/blame.go b/modules/git/blame.go index 868edab2b8..881ef04302 100644 --- a/modules/git/blame.go +++ b/modules/git/blame.go @@ -207,5 +207,5 @@ func tryCreateBlameIgnoreRevsFile(commit *Commit) *string { return nil } - return util.ToPointer(f.Name()) + return new(f.Name()) } diff --git a/modules/jwtx/signingkey.go b/modules/jwtx/signingkey.go index db9cf03aa2..f82f694d19 100644 --- a/modules/jwtx/signingkey.go +++ b/modules/jwtx/signingkey.go @@ -253,8 +253,8 @@ func (key ecdsaSigningKey) ToJWK() (map[string]string, error) { "alg": key.SigningMethod().Alg(), "kid": key.id, "crv": pubKey.Params().Name, - "x": base64.RawURLEncoding.EncodeToString(pubKey.X.Bytes()), - "y": base64.RawURLEncoding.EncodeToString(pubKey.Y.Bytes()), + "x": base64.RawURLEncoding.EncodeToString(pubKey.X.Bytes()), //nolint:staticcheck // no easy replacement. JWTX specification mandates marshalling to x, even if unsafe. + "y": base64.RawURLEncoding.EncodeToString(pubKey.Y.Bytes()), //nolint:staticcheck // no easy replacement. JWTX specification mandates marshalling to y, even if unsafe. }, nil } diff --git a/modules/util/util.go b/modules/util/util.go index f21936fb5f..996a566830 100644 --- a/modules/util/util.go +++ b/modules/util/util.go @@ -215,11 +215,6 @@ func ToFloat64(number any) (float64, error) { return value, nil } -// ToPointer returns the pointer of a copy of any given value -func ToPointer[T any](val T) *T { - return &val -} - // Iif is an "inline-if", it returns "trueVal" if "condition" is true, otherwise "falseVal" func Iif[T any](condition bool, trueVal, falseVal T) T { if condition { diff --git a/modules/util/util_test.go b/modules/util/util_test.go index 24fca75e7b..fae4f6673d 100644 --- a/modules/util/util_test.go +++ b/modules/util/util_test.go @@ -5,10 +5,10 @@ package util_test import ( - "bytes" "crypto/rand" "strings" "testing" + "testing/cryptotest" "forgejo.org/modules/test" "forgejo.org/modules/util" @@ -211,42 +211,25 @@ func TestToTitleCase(t *testing.T) { assert.Equal(t, `Foo Bar Baz`, util.ToTitleCase(`FOO BAR BAZ`)) } -func TestToPointer(t *testing.T) { - assert.Equal(t, "abc", *util.ToPointer("abc")) - assert.Equal(t, 123, *util.ToPointer(123)) - abc := "abc" - assert.NotSame(t, &abc, util.ToPointer(abc)) - val123 := 123 - assert.NotSame(t, &val123, util.ToPointer(val123)) -} - func TestReserveLineBreakForTextarea(t *testing.T) { assert.Equal(t, "test\ndata", util.ReserveLineBreakForTextarea("test\r\ndata")) assert.Equal(t, "test\ndata\n", util.ReserveLineBreakForTextarea("test\r\ndata\r\n")) } const ( - testPublicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAOhB7/zzhC+HXDdGOdLwJln5NYwm6UNXx3chmQSVTG4\n" + testPublicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHX8yEKexoMqBPPwG4pGAhhjo5CyiHLiJZ7p3jg0aJZM\n" testPrivateKey = `-----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtz -c2gtZWQyNTUxOQAAACADoQe/884Qvh1w3RjnS8CZZ+TWMJulDV8d3IZkElUxuAAA -AIggISIjICEiIwAAAAtzc2gtZWQyNTUxOQAAACADoQe/884Qvh1w3RjnS8CZZ+TW -MJulDV8d3IZkElUxuAAAAEAAAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0e -HwOhB7/zzhC+HXDdGOdLwJln5NYwm6UNXx3chmQSVTG4AAAAAAECAwQF +c2gtZWQyNTUxOQAAACB1/MhCnsaDKgTz8BuKRgIYY6OQsohy4iWe6d44NGiWTAAA +AIhNLlZvTS5WbwAAAAtzc2gtZWQyNTUxOQAAACB1/MhCnsaDKgTz8BuKRgIYY6OQ +sohy4iWe6d44NGiWTAAAAEDZh37ObTaKrBpvQZ7GJ8drG/sfo3xBoR6kat1qSNiU +dHX8yEKexoMqBPPwG4pGAhhjo5CyiHLiJZ7p3jg0aJZMAAAAAAECAwQF -----END OPENSSH PRIVATE KEY-----` + "\n" ) func TestGeneratingEd25519Keypair(t *testing.T) { defer test.MockProtect(&rand.Reader)() - - // Only 32 bytes needs to be provided to generate a ed25519 keypair. - // And another 32 bytes are required, which is included as random value - // in the OpenSSH format. - b := make([]byte, 64) - for i := range 64 { - b[i] = byte(i) - } - rand.Reader = bytes.NewReader(b) + cryptotest.SetGlobalRandom(t, 0) publicKey, privateKey, err := util.GenerateSSHKeypair() require.NoError(t, err) diff --git a/routers/api/actions/artifactsv4.go b/routers/api/actions/artifactsv4.go index 97da6c1735..56fe5cb2cc 100644 --- a/routers/api/actions/artifactsv4.go +++ b/routers/api/actions/artifactsv4.go @@ -562,7 +562,7 @@ func (r *artifactV4Routes) downloadArtifact(ctx *ArtifactContext) { return } - common.ServeContentByReadSeeker(ctx.Base, artifactName, util.ToPointer(artifact.UpdatedUnix.AsTime()), file) + common.ServeContentByReadSeeker(ctx.Base, artifactName, new(artifact.UpdatedUnix.AsTime()), file) } func (r *artifactV4Routes) deleteArtifact(ctx *ArtifactContext) { diff --git a/routers/api/actions/oidc.go b/routers/api/actions/oidc.go index fc82bc299f..23b6fec16c 100644 --- a/routers/api/actions/oidc.go +++ b/routers/api/actions/oidc.go @@ -103,8 +103,7 @@ func OIDCRoutes(prefix string) *web.Route { // and inspecting the names of the json struct tags rt := reflect.TypeFor[actions_service.IDTokenCustomClaims]() - for i := 0; i < rt.NumField(); i++ { - f := rt.Field(i) + for f := range rt.Fields() { v := strings.Split(f.Tag.Get("json"), ",")[0] if v == "" || v == "-" { continue diff --git a/routers/web/repo/attachment.go b/routers/web/repo/attachment.go index 5b2eaef889..5497738f0b 100644 --- a/routers/web/repo/attachment.go +++ b/routers/web/repo/attachment.go @@ -13,7 +13,6 @@ import ( "forgejo.org/modules/log" "forgejo.org/modules/setting" "forgejo.org/modules/storage" - "forgejo.org/modules/util" "forgejo.org/routers/common" "forgejo.org/services/attachment" "forgejo.org/services/context" @@ -154,7 +153,7 @@ func ServeAttachment(ctx *context.Context, uuid string) { } defer fr.Close() - common.ServeContentByReadSeeker(ctx.Base, attach.Name, util.ToPointer(attach.CreatedUnix.AsTime()), fr) + common.ServeContentByReadSeeker(ctx.Base, attach.Name, new(attach.CreatedUnix.AsTime()), fr) } // GetAttachment serve attachments diff --git a/services/actions/download.go b/services/actions/download.go index 04aa1ca289..34de121220 100644 --- a/services/actions/download.go +++ b/services/actions/download.go @@ -15,7 +15,6 @@ import ( "forgejo.org/modules/httplib" "forgejo.org/modules/setting" "forgejo.org/modules/storage" - "forgejo.org/modules/util" "forgejo.org/services/context" ) @@ -51,7 +50,7 @@ func serveV4Artifact(base *context.Base, art *actions_model.ActionArtifact) erro if err != nil { return err } - httplib.ServeContentByReadSeeker(base.Req, base.Resp, art.ArtifactName+".zip", util.ToPointer(art.UpdatedUnix.AsTime()), f) + httplib.ServeContentByReadSeeker(base.Req, base.Resp, art.ArtifactName+".zip", new(art.UpdatedUnix.AsTime()), f) return nil } diff --git a/services/migrations/codebase_test.go b/services/migrations/codebase_test.go index 315c7be709..5d90f7e8a2 100644 --- a/services/migrations/codebase_test.go +++ b/services/migrations/codebase_test.go @@ -55,12 +55,12 @@ func TestCodebaseDownloadRepo(t *testing.T) { assertMilestonesEqual(t, []*base.Milestone{ { Title: "Milestone1", - Deadline: timePtr(time.Date(2021, time.September, 16, 0, 0, 0, 0, time.UTC)), + Deadline: new(time.Date(2021, time.September, 16, 0, 0, 0, 0, time.UTC)), }, { Title: "Milestone2", - Deadline: timePtr(time.Date(2021, time.September, 17, 0, 0, 0, 0, time.UTC)), - Closed: timePtr(time.Date(2021, time.September, 17, 0, 0, 0, 0, time.UTC)), + Deadline: new(time.Date(2021, time.September, 17, 0, 0, 0, 0, time.UTC)), + Closed: new(time.Date(2021, time.September, 17, 0, 0, 0, 0, time.UTC)), State: "closed", }, }, milestones) diff --git a/services/migrations/gitea_downloader_test.go b/services/migrations/gitea_downloader_test.go index a4a4f29ddb..3db81bb158 100644 --- a/services/migrations/gitea_downloader_test.go +++ b/services/migrations/gitea_downloader_test.go @@ -93,16 +93,16 @@ func TestGiteaDownloadRepo(t *testing.T) { { Title: "V2 Finalize", Created: time.Unix(0, 0), - Deadline: timePtr(time.Unix(1599263999, 0)), - Updated: timePtr(time.Date(2022, 11, 13, 5, 29, 15, 0, time.UTC)), + Deadline: new(time.Unix(1599263999, 0)), + Updated: new(time.Date(2022, 11, 13, 5, 29, 15, 0, time.UTC)), State: "open", }, { Title: "V1", Description: "Generate Content", Created: time.Unix(0, 0), - Updated: timePtr(time.Unix(0, 0)), - Closed: timePtr(time.Unix(1598985406, 0)), + Updated: new(time.Unix(0, 0)), + Closed: new(time.Unix(1598985406, 0)), State: "closed", }, }, milestones) @@ -178,7 +178,7 @@ func TestGiteaDownloadRepo(t *testing.T) { Content: "laugh", }, }, - Closed: timePtr(time.Date(2020, 9, 1, 15, 49, 34, 0, time.UTC)), + Closed: new(time.Date(2020, 9, 1, 15, 49, 34, 0, time.UTC)), }, { Number: 2, @@ -197,7 +197,7 @@ func TestGiteaDownloadRepo(t *testing.T) { Color: "d4c5f9", Description: "", }}, - Closed: timePtr(time.Unix(1598969497, 0)), + Closed: new(time.Unix(1598969497, 0)), }, }, issues) @@ -244,7 +244,7 @@ func TestGiteaDownloadRepo(t *testing.T) { IsLocked: false, Created: time.Unix(1598982759, 0), Updated: time.Unix(1599023425, 0), - Closed: timePtr(time.Date(2020, 9, 1, 17, 55, 33, 0, time.UTC)), + Closed: new(time.Date(2020, 9, 1, 17, 55, 33, 0, time.UTC)), Assignees: []string{"techknowlogick"}, Base: base.PullRequestBranch{ CloneURL: "", @@ -261,7 +261,7 @@ func TestGiteaDownloadRepo(t *testing.T) { OwnerName: "6543-forks", }, Merged: true, - MergedTime: timePtr(time.Unix(1598982934, 0)), + MergedTime: new(time.Unix(1598982934, 0)), MergeCommitSHA: "827aa28a907853e5ddfa40c8f9bc52471a2685fd", PatchURL: server.URL + "/gitea/test_repo/pulls/12.patch", }, prs[1]) diff --git a/services/migrations/github_test.go b/services/migrations/github_test.go index 29a78f53fc..288eb4febb 100644 --- a/services/migrations/github_test.go +++ b/services/migrations/github_test.go @@ -163,24 +163,24 @@ func TestGitHubDownloadRepo(t *testing.T) { Title: "1.0.0", Description: "Version 1", Created: time.Date(2025, 8, 7, 12, 48, 56, 0, time.UTC), - Updated: timePtr(time.Date(2025, time.August, 12, 12, 34, 20, 0, time.UTC)), + Updated: new(time.Date(2025, time.August, 12, 12, 34, 20, 0, time.UTC)), State: "open", }, { Title: "0.9.0", Description: "A milestone", - Deadline: timePtr(time.Date(2025, 8, 1, 7, 0, 0, 0, time.UTC)), + Deadline: new(time.Date(2025, 8, 1, 7, 0, 0, 0, time.UTC)), Created: time.Date(2025, 8, 7, 12, 54, 20, 0, time.UTC), - Updated: timePtr(time.Date(2025, 8, 12, 11, 29, 52, 0, time.UTC)), - Closed: timePtr(time.Date(2025, 8, 7, 12, 54, 38, 0, time.UTC)), + Updated: new(time.Date(2025, 8, 12, 11, 29, 52, 0, time.UTC)), + Closed: new(time.Date(2025, 8, 7, 12, 54, 38, 0, time.UTC)), State: "closed", }, { Title: "1.1.0", Description: "We can do that", - Deadline: timePtr(time.Date(2025, 8, 31, 7, 0, 0, 0, time.UTC)), + Deadline: new(time.Date(2025, 8, 31, 7, 0, 0, 0, time.UTC)), Created: time.Date(2025, 8, 7, 12, 50, 58, 0, time.UTC), - Updated: timePtr(time.Date(2025, 8, 7, 12, 53, 15, 0, time.UTC)), + Updated: new(time.Date(2025, 8, 7, 12, 53, 15, 0, time.UTC)), State: "open", }, }, milestones) @@ -372,8 +372,8 @@ func TestGitHubDownloadRepo(t *testing.T) { State: "closed", Created: time.Date(2025, time.August, 7, 13, 1, 36, 0, time.UTC), Updated: time.Date(2025, time.August, 12, 12, 47, 35, 0, time.UTC), - Closed: timePtr(time.Date(2025, time.August, 7, 13, 2, 19, 0, time.UTC)), - MergedTime: timePtr(time.Date(2025, time.August, 7, 13, 2, 19, 0, time.UTC)), + Closed: new(time.Date(2025, time.August, 7, 13, 2, 19, 0, time.UTC)), + MergedTime: new(time.Date(2025, time.August, 7, 13, 2, 19, 0, time.UTC)), Labels: []*base.Label{ { Name: "bug", diff --git a/services/migrations/gitlab_test.go b/services/migrations/gitlab_test.go index 37fdea9475..029a4ecce1 100644 --- a/services/migrations/gitlab_test.go +++ b/services/migrations/gitlab_test.go @@ -57,14 +57,14 @@ func TestGitlabDownloadRepo(t *testing.T) { { Title: "1.0.0", Created: time.Date(2024, 9, 3, 13, 53, 8, 516000000, time.UTC), - Updated: timePtr(time.Date(2024, 9, 3, 20, 3, 57, 786000000, time.UTC)), - Closed: timePtr(time.Date(2024, 9, 3, 20, 3, 57, 786000000, time.UTC)), + Updated: new(time.Date(2024, 9, 3, 20, 3, 57, 786000000, time.UTC)), + Closed: new(time.Date(2024, 9, 3, 20, 3, 57, 786000000, time.UTC)), State: "closed", }, { Title: "1.1.0", Created: time.Date(2024, 9, 3, 13, 52, 48, 414000000, time.UTC), - Updated: timePtr(time.Date(2024, 9, 3, 14, 52, 14, 93000000, time.UTC)), + Updated: new(time.Date(2024, 9, 3, 14, 52, 14, 93000000, time.UTC)), State: "active", }, }, milestones) @@ -260,7 +260,7 @@ func TestGitlabDownloadRepo(t *testing.T) { Content: "hearts", }, }, - Closed: timePtr(time.Date(2024, 9, 3, 14, 43, 10, 906000000, time.UTC)), + Closed: new(time.Date(2024, 9, 3, 14, 43, 10, 906000000, time.UTC)), }, }, issues) issues, isEnd, err = downloader.GetIssues(2, 3) @@ -297,7 +297,7 @@ func TestGitlabDownloadRepo(t *testing.T) { Content: "open_mouth", }, }, - Closed: timePtr(time.Date(2024, 9, 3, 14, 43, 10, 708000000, time.UTC)), + Closed: new(time.Date(2024, 9, 3, 14, 43, 10, 708000000, time.UTC)), }, }, issues) diff --git a/services/migrations/main_test.go b/services/migrations/main_test.go index d304f345cf..44ab3f3fc8 100644 --- a/services/migrations/main_test.go +++ b/services/migrations/main_test.go @@ -19,10 +19,6 @@ func TestMain(m *testing.M) { unittest.MainTest(m) } -func timePtr(t time.Time) *time.Time { - return &t -} - func assertTimeEqual(t *testing.T, expected, actual time.Time) { assert.Equal(t, expected.UTC(), actual.UTC()) } diff --git a/services/migrations/pagure_test.go b/services/migrations/pagure_test.go index bac3eb24ad..3217e10300 100644 --- a/services/migrations/pagure_test.go +++ b/services/migrations/pagure_test.go @@ -85,7 +85,7 @@ func TestPagureDownloadRepoWithPublicIssues(t *testing.T) { Milestone: "Milestone BBBB", Created: time.Date(2023, time.October, 13, 4, 1, 16, 0, time.UTC), Updated: time.Date(2025, time.June, 25, 6, 25, 57, 0, time.UTC), - Closed: timePtr(time.Date(2025, time.June, 25, 6, 22, 59, 0, time.UTC)), + Closed: new(time.Date(2025, time.June, 25, 6, 22, 59, 0, time.UTC)), Labels: []*base.Label{ { Name: "cccc", @@ -111,7 +111,7 @@ func TestPagureDownloadRepoWithPublicIssues(t *testing.T) { Milestone: "Milestone AAAA", Created: time.Date(2023, time.October, 13, 3, 57, 42, 0, time.UTC), Updated: time.Date(2025, time.June, 25, 6, 25, 45, 0, time.UTC), - Closed: timePtr(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)), + Closed: new(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)), Labels: []*base.Label{ { Name: "aaaa", @@ -219,8 +219,8 @@ func TestPagureDownloadRepoWithPublicIssues(t *testing.T) { State: "closed", Created: time.Date(2025, time.May, 19, 6, 12, 45, 0, time.UTC), Updated: time.Date(2025, time.May, 19, 6, 17, 11, 0, time.UTC), - Closed: timePtr(time.Date(2025, time.May, 19, 6, 17, 11, 0, time.UTC)), - MergedTime: timePtr(time.Date(2025, time.May, 19, 6, 17, 11, 0, time.UTC)), + Closed: new(time.Date(2025, time.May, 19, 6, 17, 11, 0, time.UTC)), + MergedTime: new(time.Date(2025, time.May, 19, 6, 17, 11, 0, time.UTC)), Merged: true, PatchURL: server.URL + "/protop2g-test-srce/pull-request/10.patch", Labels: []*base.Label{ @@ -249,8 +249,8 @@ func TestPagureDownloadRepoWithPublicIssues(t *testing.T) { State: "closed", Created: time.Date(2025, time.May, 19, 6, 12, 41, 0, time.UTC), Updated: time.Date(2025, time.May, 19, 6, 14, 3, 0, time.UTC), - Closed: timePtr(time.Date(2025, time.May, 19, 6, 14, 3, 0, time.UTC)), - MergedTime: timePtr(time.Date(2025, time.May, 19, 6, 14, 3, 0, time.UTC)), + Closed: new(time.Date(2025, time.May, 19, 6, 14, 3, 0, time.UTC)), + MergedTime: new(time.Date(2025, time.May, 19, 6, 14, 3, 0, time.UTC)), Merged: true, PatchURL: server.URL + "/protop2g-test-srce/pull-request/9.patch", Labels: []*base.Label{ @@ -279,8 +279,8 @@ func TestPagureDownloadRepoWithPublicIssues(t *testing.T) { State: "closed", Created: time.Date(2025, time.May, 5, 6, 45, 32, 0, time.UTC), Updated: time.Date(2025, time.May, 5, 6, 54, 13, 0, time.UTC), - Closed: timePtr(time.Date(2025, time.May, 5, 6, 54, 13, 0, time.UTC)), - MergedTime: timePtr(time.Date(2025, time.May, 5, 6, 54, 13, 0, time.UTC)), // THIS IS WRONG + Closed: new(time.Date(2025, time.May, 5, 6, 54, 13, 0, time.UTC)), + MergedTime: new(time.Date(2025, time.May, 5, 6, 54, 13, 0, time.UTC)), // THIS IS WRONG Merged: false, PatchURL: server.URL + "/protop2g-test-srce/pull-request/8.patch", Labels: []*base.Label{ @@ -308,9 +308,9 @@ func TestPagureDownloadRepoWithPublicIssues(t *testing.T) { PosterID: -1, State: "closed", Created: time.Date(2025, time.May, 5, 6, 45, 6, 0, time.UTC), - Updated: time.Date(2025, time.May, 5, 6, 54, 3, 0, time.UTC), // IT SHOULD BE NIL - Closed: timePtr(time.Date(2025, time.May, 5, 6, 54, 3, 0, time.UTC)), // IT is CLOSED, Not MERGED so SHOULD NOT BE NIL - MergedTime: timePtr(time.Date(2025, time.May, 5, 6, 54, 3, 0, time.UTC)), // THIS IS WRONG + Updated: time.Date(2025, time.May, 5, 6, 54, 3, 0, time.UTC), // IT SHOULD BE NIL + Closed: new(time.Date(2025, time.May, 5, 6, 54, 3, 0, time.UTC)), // IT is CLOSED, Not MERGED so SHOULD NOT BE NIL + MergedTime: new(time.Date(2025, time.May, 5, 6, 54, 3, 0, time.UTC)), // THIS IS WRONG Merged: false, PatchURL: server.URL + "/protop2g-test-srce/pull-request/7.patch", Labels: []*base.Label{ @@ -339,8 +339,8 @@ func TestPagureDownloadRepoWithPublicIssues(t *testing.T) { State: "open", Created: time.Date(2025, time.May, 5, 6, 44, 30, 0, time.UTC), Updated: time.Date(2025, time.May, 19, 8, 30, 50, 0, time.UTC), - Closed: timePtr(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)), - MergedTime: timePtr(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)), + Closed: new(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)), + MergedTime: new(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)), Merged: false, PatchURL: server.URL + "/protop2g-test-srce/pull-request/6.patch", Labels: []*base.Label{ @@ -369,8 +369,8 @@ func TestPagureDownloadRepoWithPublicIssues(t *testing.T) { State: "open", Created: time.Date(2025, time.May, 5, 6, 43, 57, 0, time.UTC), Updated: time.Date(2025, time.May, 19, 6, 29, 45, 0, time.UTC), - Closed: timePtr(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)), - MergedTime: timePtr(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)), + Closed: new(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)), + MergedTime: new(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)), Merged: false, PatchURL: server.URL + "/protop2g-test-srce/pull-request/5.patch", Labels: []*base.Label{ @@ -428,22 +428,22 @@ func TestPagureDownloadRepoWithPublicIssues(t *testing.T) { dict := map[string]*base.Milestone{ "Milestone AAAA": { Title: "Milestone AAAA", - Deadline: timePtr(time.Date(2025, time.December, 12, 0, 0, 0, 0, time.UTC)), + Deadline: new(time.Date(2025, time.December, 12, 0, 0, 0, 0, time.UTC)), State: "open", }, "Milestone BBBB": { Title: "Milestone BBBB", - Deadline: timePtr(time.Date(2025, time.December, 12, 0, 0, 0, 0, time.UTC)), + Deadline: new(time.Date(2025, time.December, 12, 0, 0, 0, 0, time.UTC)), State: "closed", }, "Milestone CCCC": { Title: "Milestone CCCC", - Deadline: timePtr(time.Date(2025, time.December, 12, 0, 0, 0, 0, time.UTC)), + Deadline: new(time.Date(2025, time.December, 12, 0, 0, 0, 0, time.UTC)), State: "open", }, "Milestone DDDD": { Title: "Milestone DDDD", - Deadline: timePtr(time.Date(2025, time.December, 12, 0, 0, 0, 0, time.UTC)), + Deadline: new(time.Date(2025, time.December, 12, 0, 0, 0, 0, time.UTC)), State: "closed", }, } @@ -524,7 +524,7 @@ func TestPagureDownloadRepoWithPrivateIssues(t *testing.T) { Milestone: "Milestone DDDD", Created: time.Date(2023, time.November, 21, 8, 6, 56, 0, time.UTC), Updated: time.Date(2025, time.June, 25, 6, 26, 26, 0, time.UTC), - Closed: timePtr(time.Date(2025, time.June, 25, 6, 23, 51, 0, time.UTC)), + Closed: new(time.Date(2025, time.June, 25, 6, 23, 51, 0, time.UTC)), Labels: []*base.Label{ { Name: "gggg", @@ -550,7 +550,7 @@ func TestPagureDownloadRepoWithPrivateIssues(t *testing.T) { Milestone: "Milestone CCCC", Created: time.Date(2023, time.November, 21, 8, 3, 57, 0, time.UTC), Updated: time.Date(2025, time.June, 25, 6, 26, 7, 0, time.UTC), - Closed: timePtr(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)), + Closed: new(time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)), Labels: []*base.Label{ { Name: "eeee", @@ -649,17 +649,17 @@ func TestProcessDate(t *testing.T) { }, { name: "empty string", - input: strPtr(""), + input: new(""), expected: time.Time{}, }, { name: "unix timestamp", - input: strPtr("1609459200"), + input: new("1609459200"), expected: time.Unix(1609459200, 0), }, { name: "YYYY-MM-DD format", - input: strPtr("2025-12-12"), + input: new("2025-12-12"), expected: time.Date(2025, time.December, 12, 0, 0, 0, 0, time.UTC), }, } @@ -671,7 +671,3 @@ func TestProcessDate(t *testing.T) { }) } } - -func strPtr(s string) *string { - return &s -}