Skip to content

Commit adc078e

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin switch destination directory for apt signing keys (go-gitea#28639) Extend description for ARTIFACT_RETENTION_DAYS (go-gitea#28626) Refactor timeutil package (go-gitea#28623) Refactor some legacy code and remove unused code (go-gitea#28622) Remove unnecessary syncbranchToDB with tests (go-gitea#28624) Do not set `Accept` header twice (go-gitea#28598) [skip ci] Updated translations via Crowdin fix wrong link in user and organization profile when using relative url (go-gitea#28617) Add get actions runner registration token for API routes, repo, org, user and global level (go-gitea#27144) Fix session key conflict with database keyword (go-gitea#28613)
2 parents 10b053a + 4995b4a commit adc078e

File tree

37 files changed

+465
-189
lines changed

37 files changed

+465
-189
lines changed

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ PROXY_HOSTS = *.github.com
13901390
- `DEFAULT_ACTIONS_URL`: **github**: Default platform to get action plugins, `github` for `https://github.com`, `self` for the current Gitea instance.
13911391
- `STORAGE_TYPE`: **local**: Storage type for actions logs, `local` for local disk or `minio` for s3 compatible object storage service, default is `local` or other name defined with `[storage.xxx]`
13921392
- `MINIO_BASE_PATH`: **actions_log/**: Minio base path on the bucket only available when STORAGE_TYPE is `minio`
1393-
- `ARTIFACT_RETENTION_DAYS`: **90**: Number of days to keep artifacts. Set to 0 to disable artifact retention. Default is 90 days if not set.
1393+
- `ARTIFACT_RETENTION_DAYS`: **90**: Default number of days to keep artifacts. This can be overridden in `actions/upload_artifact`. Set to 0 to disable artifact retention. Default is 90 days if not set. Each artifact can have it's own number of retention days.
13941394
- `ZOMBIE_TASK_TIMEOUT`: **10m**: Timeout to stop the task which have running status, but haven't been updated for a long time
13951395
- `ENDLESS_TASK_TIMEOUT`: **3h**: Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time
13961396
- `ABANDONED_JOB_TIMEOUT`: **24h**: Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time

docs/content/usage/packages/debian.en-us.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The following examples use `apt`.
2727
To register the Debian registry add the url to the list of known apt sources:
2828

2929
```shell
30-
echo "deb https://gitea.example.com/api/packages/{owner}/debian {distribution} {component}" | sudo tee -a /etc/apt/sources.list.d/gitea.list
30+
echo "deb [signed-by=/etc/apt/keyrings/gitea-{owner}.asc] https://gitea.example.com/api/packages/{owner}/debian {distribution} {component}" | sudo tee -a /etc/apt/sources.list.d/gitea.list
3131
```
3232

3333
| Placeholder | Description |
@@ -39,13 +39,13 @@ echo "deb https://gitea.example.com/api/packages/{owner}/debian {distribution} {
3939
If the registry is private, provide credentials in the url. You can use a password or a [personal access token](development/api-usage.md#authentication):
4040

4141
```shell
42-
echo "deb https://{username}:{your_password_or_token}@gitea.example.com/api/packages/{owner}/debian {distribution} {component}" | sudo tee -a /etc/apt/sources.list.d/gitea.list
42+
echo "deb [signed-by=/etc/apt/keyrings/gitea-{owner}.asc] https://{username}:{your_password_or_token}@gitea.example.com/api/packages/{owner}/debian {distribution} {component}" | sudo tee -a /etc/apt/sources.list.d/gitea.list
4343
```
4444

4545
The Debian registry files are signed with a PGP key which must be known to apt:
4646

4747
```shell
48-
sudo curl https://gitea.example.com/api/packages/{owner}/debian/repository.key -o /etc/apt/trusted.gpg.d/gitea-{owner}.asc
48+
sudo curl https://gitea.example.com/api/packages/{owner}/debian/repository.key -o /etc/apt/keyrings/gitea-{owner}.asc
4949
```
5050

5151
Afterwards update the local package index:

docs/content/usage/packages/debian.zh-cn.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ menu:
2727
要注册 Debian 注册表,请将 URL 添加到已知 `apt` 源列表中:
2828

2929
```shell
30-
echo "deb https://gitea.example.com/api/packages/{owner}/debian {distribution} {component}" | sudo tee -a /etc/apt/sources.list.d/gitea.list
30+
echo "deb [signed-by=/etc/apt/keyrings/gitea-{owner}.asc] https://gitea.example.com/api/packages/{owner}/debian {distribution} {component}" | sudo tee -a /etc/apt/sources.list.d/gitea.list
3131
```
3232

3333
| 占位符 | 描述 |
@@ -39,13 +39,13 @@ echo "deb https://gitea.example.com/api/packages/{owner}/debian {distribution} {
3939
如果注册表是私有的,请在 URL 中提供凭据。您可以使用密码或[个人访问令牌](development/api-usage.md#通过-api-认证)
4040

4141
```shell
42-
echo "deb https://{username}:{your_password_or_token}@gitea.example.com/api/packages/{owner}/debian {distribution} {component}" | sudo tee -a /etc/apt/sources.list.d/gitea.list
42+
echo "deb [signed-by=/etc/apt/keyrings/gitea-{owner}.asc] https://{username}:{your_password_or_token}@gitea.example.com/api/packages/{owner}/debian {distribution} {component}" | sudo tee -a /etc/apt/sources.list.d/gitea.list
4343
```
4444

4545
Debian 注册表文件使用 PGP 密钥进行签名,`apt` 必须知道该密钥:
4646

4747
```shell
48-
sudo curl https://gitea.example.com/api/packages/{owner}/debian/repository.key -o /etc/apt/trusted.gpg.d/gitea-{owner}.asc
48+
sudo curl https://gitea.example.com/api/packages/{owner}/debian/repository.key -o /etc/apt/keyrings/gitea-{owner}.asc
4949
```
5050

5151
然后更新本地软件包索引:

models/activities/user_heatmap_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
5959
assert.NoError(t, unittest.PrepareTestDatabase())
6060

6161
// Mock time
62-
timeutil.Set(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC))
63-
defer timeutil.Unset()
62+
timeutil.MockSet(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC))
63+
defer timeutil.MockUnset()
6464

6565
for _, tc := range testCases {
6666
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: tc.userID})

models/asymkey/gpg_key_verify.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ func VerifyGPGKey(ctx context.Context, ownerID int64, keyID, token, signature st
107107
// VerificationToken returns token for the user that will be valid in minutes (time)
108108
func VerificationToken(user *user_model.User, minutes int) string {
109109
return base.EncodeSha256(
110-
time.Now().Truncate(1*time.Minute).Add(time.Duration(minutes)*time.Minute).Format(time.RFC1123Z) + ":" +
111-
user.CreatedUnix.FormatLong() + ":" +
110+
time.Now().Truncate(1*time.Minute).Add(time.Duration(minutes)*time.Minute).Format(
111+
time.RFC1123Z) + ":" +
112+
user.CreatedUnix.Format(time.RFC1123Z) + ":" +
112113
user.Name + ":" +
113114
user.Email + ":" +
114115
strconv.FormatInt(user.ID, 10))

models/auth/session.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ func ReadSession(ctx context.Context, key string) (*Session, error) {
4141
}
4242
defer committer.Close()
4343

44-
session, exist, err := db.Get[Session](ctx, builder.Eq{"key": key})
44+
session, exist, err := db.Get[Session](ctx, builder.Eq{"`key`": key})
4545
if err != nil {
4646
return nil, err
4747
} else if !exist {
48-
session.Expiry = timeutil.TimeStampNow()
49-
if err := db.Insert(ctx, &session); err != nil {
48+
session = &Session{
49+
Key: key,
50+
Expiry: timeutil.TimeStampNow(),
51+
}
52+
if err := db.Insert(ctx, session); err != nil {
5053
return nil, err
5154
}
5255
}
@@ -56,7 +59,7 @@ func ReadSession(ctx context.Context, key string) (*Session, error) {
5659

5760
// ExistSession checks if a session exists
5861
func ExistSession(ctx context.Context, key string) (bool, error) {
59-
return db.Exist[Session](ctx, builder.Eq{"key": key})
62+
return db.Exist[Session](ctx, builder.Eq{"`key`": key})
6063
}
6164

6265
// DestroySession destroys a session
@@ -75,13 +78,13 @@ func RegenerateSession(ctx context.Context, oldKey, newKey string) (*Session, er
7578
}
7679
defer committer.Close()
7780

78-
if has, err := db.Exist[Session](ctx, builder.Eq{"key": newKey}); err != nil {
81+
if has, err := db.Exist[Session](ctx, builder.Eq{"`key`": newKey}); err != nil {
7982
return nil, err
8083
} else if has {
8184
return nil, fmt.Errorf("session Key: %s already exists", newKey)
8285
}
8386

84-
if has, err := db.Exist[Session](ctx, builder.Eq{"key": oldKey}); err != nil {
87+
if has, err := db.Exist[Session](ctx, builder.Eq{"`key`": oldKey}); err != nil {
8588
return nil, err
8689
} else if !has {
8790
if err := db.Insert(ctx, &Session{
@@ -96,7 +99,7 @@ func RegenerateSession(ctx context.Context, oldKey, newKey string) (*Session, er
9699
return nil, err
97100
}
98101

99-
s, _, err := db.Get[Session](ctx, builder.Eq{"key": newKey})
102+
s, _, err := db.Get[Session](ctx, builder.Eq{"`key`": newKey})
100103
if err != nil {
101104
// is not exist, it should be impossible
102105
return nil, err

models/avatars/avatar.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package avatars
55

66
import (
77
"context"
8+
"crypto/md5"
9+
"encoding/hex"
810
"fmt"
911
"net/url"
1012
"path"
@@ -13,7 +15,6 @@ import (
1315
"sync/atomic"
1416

1517
"code.gitea.io/gitea/models/db"
16-
"code.gitea.io/gitea/modules/base"
1718
"code.gitea.io/gitea/modules/cache"
1819
"code.gitea.io/gitea/modules/log"
1920
"code.gitea.io/gitea/modules/setting"
@@ -90,7 +91,9 @@ func DefaultAvatarLink() string {
9091

9192
// HashEmail hashes email address to MD5 string. https://en.gravatar.com/site/implement/hash/
9293
func HashEmail(email string) string {
93-
return base.EncodeMD5(strings.ToLower(strings.TrimSpace(email)))
94+
m := md5.New()
95+
_, _ = m.Write([]byte(strings.ToLower(strings.TrimSpace(email))))
96+
return hex.EncodeToString(m.Sum(nil))
9497
}
9598

9699
// GetEmailForHash converts a provided md5sum to the email

models/git/protected_branch.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
repo_model "code.gitea.io/gitea/models/repo"
1818
"code.gitea.io/gitea/models/unit"
1919
user_model "code.gitea.io/gitea/models/user"
20-
"code.gitea.io/gitea/modules/base"
2120
"code.gitea.io/gitea/modules/log"
2221
"code.gitea.io/gitea/modules/timeutil"
2322
"code.gitea.io/gitea/modules/util"
@@ -127,7 +126,7 @@ func (protectBranch *ProtectedBranch) CanUserPush(ctx context.Context, user *use
127126
return writeAccess
128127
}
129128

130-
if base.Int64sContains(protectBranch.WhitelistUserIDs, user.ID) {
129+
if slices.Contains(protectBranch.WhitelistUserIDs, user.ID) {
131130
return true
132131
}
133132

@@ -150,7 +149,7 @@ func IsUserMergeWhitelisted(ctx context.Context, protectBranch *ProtectedBranch,
150149
return permissionInRepo.CanWrite(unit.TypeCode)
151150
}
152151

153-
if base.Int64sContains(protectBranch.MergeWhitelistUserIDs, userID) {
152+
if slices.Contains(protectBranch.MergeWhitelistUserIDs, userID) {
154153
return true
155154
}
156155

@@ -182,7 +181,7 @@ func IsUserOfficialReviewer(ctx context.Context, protectBranch *ProtectedBranch,
182181
return writeAccess, nil
183182
}
184183

185-
if base.Int64sContains(protectBranch.ApprovalsWhitelistUserIDs, user.ID) {
184+
if slices.Contains(protectBranch.ApprovalsWhitelistUserIDs, user.ID) {
186185
return true, nil
187186
}
188187

models/git/protected_tag.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ package git
66
import (
77
"context"
88
"regexp"
9+
"slices"
910
"strings"
1011

1112
"code.gitea.io/gitea/models/db"
1213
"code.gitea.io/gitea/models/organization"
13-
"code.gitea.io/gitea/modules/base"
1414
"code.gitea.io/gitea/modules/timeutil"
1515

1616
"github.com/gobwas/glob"
@@ -76,7 +76,7 @@ func DeleteProtectedTag(ctx context.Context, pt *ProtectedTag) error {
7676

7777
// IsUserAllowedModifyTag returns true if the user is allowed to modify the tag
7878
func IsUserAllowedModifyTag(ctx context.Context, pt *ProtectedTag, userID int64) (bool, error) {
79-
if base.Int64sContains(pt.AllowlistUserIDs, userID) {
79+
if slices.Contains(pt.AllowlistUserIDs, userID) {
8080
return true, nil
8181
}
8282

models/issues/comment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,15 +899,15 @@ func createDeadlineComment(ctx context.Context, doer *user_model.User, issue *Is
899899
// newDeadline = 0 means deleting
900900
if newDeadlineUnix == 0 {
901901
commentType = CommentTypeRemovedDeadline
902-
content = issue.DeadlineUnix.Format("2006-01-02")
902+
content = issue.DeadlineUnix.FormatDate()
903903
} else if issue.DeadlineUnix == 0 {
904904
// Check if the new date was added or modified
905905
// If the actual deadline is 0 => deadline added
906906
commentType = CommentTypeAddedDeadline
907-
content = newDeadlineUnix.Format("2006-01-02")
907+
content = newDeadlineUnix.FormatDate()
908908
} else { // Otherwise modified
909909
commentType = CommentTypeModifiedDeadline
910-
content = newDeadlineUnix.Format("2006-01-02") + "|" + issue.DeadlineUnix.Format("2006-01-02")
910+
content = newDeadlineUnix.FormatDate() + "|" + issue.DeadlineUnix.FormatDate()
911911
}
912912

913913
if err := issue.LoadRepo(ctx); err != nil {

models/issues/milestone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (m *Milestone) AfterLoad() {
8686
return
8787
}
8888

89-
m.DeadlineString = m.DeadlineUnix.Format("2006-01-02")
89+
m.DeadlineString = m.DeadlineUnix.FormatDate()
9090
if m.IsClosed {
9191
m.IsOverdue = m.ClosedDateUnix >= m.DeadlineUnix
9292
} else {

models/issues/review.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package issues
66
import (
77
"context"
88
"fmt"
9+
"slices"
910
"strings"
1011

1112
"code.gitea.io/gitea/models/db"
@@ -15,7 +16,6 @@ import (
1516
access_model "code.gitea.io/gitea/models/perm/access"
1617
"code.gitea.io/gitea/models/unit"
1718
user_model "code.gitea.io/gitea/models/user"
18-
"code.gitea.io/gitea/modules/base"
1919
"code.gitea.io/gitea/modules/structs"
2020
"code.gitea.io/gitea/modules/timeutil"
2121
"code.gitea.io/gitea/modules/util"
@@ -279,7 +279,7 @@ func IsOfficialReviewerTeam(ctx context.Context, issue *Issue, team *organizatio
279279
return team.UnitAccessMode(ctx, unit.TypeCode) >= perm.AccessModeWrite, nil
280280
}
281281

282-
return base.Int64sContains(pb.ApprovalsWhitelistTeamIDs, team.ID), nil
282+
return slices.Contains(pb.ApprovalsWhitelistTeamIDs, team.ID), nil
283283
}
284284

285285
// CreateReview creates a new review based on opts

modules/base/tool.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package base
55

66
import (
7-
"crypto/md5"
87
"crypto/sha1"
98
"encoding/base64"
109
"encoding/hex"
@@ -16,7 +15,6 @@ import (
1615
"strconv"
1716
"strings"
1817
"time"
19-
"unicode"
2018
"unicode/utf8"
2119

2220
"code.gitea.io/gitea/modules/git"
@@ -27,13 +25,6 @@ import (
2725
"github.com/minio/sha256-simd"
2826
)
2927

30-
// EncodeMD5 encodes string to md5 hex value.
31-
func EncodeMD5(str string) string {
32-
m := md5.New()
33-
_, _ = m.Write([]byte(str))
34-
return hex.EncodeToString(m.Sum(nil))
35-
}
36-
3728
// EncodeSha1 string to sha1 hex value.
3829
func EncodeSha1(str string) string {
3930
h := sha1.New()
@@ -70,11 +61,6 @@ func BasicAuthDecode(encoded string) (string, string, error) {
7061
return auth[0], auth[1], nil
7162
}
7263

73-
// BasicAuthEncode encode basic auth string
74-
func BasicAuthEncode(username, password string) string {
75-
return base64.StdEncoding.EncodeToString([]byte(username + ":" + password))
76-
}
77-
7864
// VerifyTimeLimitCode verify time limit code
7965
func VerifyTimeLimitCode(data string, minutes int, code string) bool {
8066
if len(code) <= 18 {
@@ -184,22 +170,6 @@ func Int64sToStrings(ints []int64) []string {
184170
return strs
185171
}
186172

187-
// Int64sContains returns if a int64 in a slice of int64
188-
func Int64sContains(intsSlice []int64, a int64) bool {
189-
for _, c := range intsSlice {
190-
if c == a {
191-
return true
192-
}
193-
}
194-
return false
195-
}
196-
197-
// IsLetter reports whether the rune is a letter (category L).
198-
// https://github.com/golang/go/blob/c3b4918/src/go/scanner/scanner.go#L342
199-
func IsLetter(ch rune) bool {
200-
return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch >= 0x80 && unicode.IsLetter(ch)
201-
}
202-
203173
// EntryIcon returns the octicon class for displaying files/directories
204174
func EntryIcon(entry *git.TreeEntry) string {
205175
switch {

modules/base/tool_test.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
)
1313

14-
func TestEncodeMD5(t *testing.T) {
15-
assert.Equal(t,
16-
"3858f62230ac3c915f300c664312c63f",
17-
EncodeMD5("foobar"),
18-
)
19-
}
20-
2114
func TestEncodeSha1(t *testing.T) {
2215
assert.Equal(t,
2316
"8843d7f92416211de9ebb963ff4ce28125932878",
@@ -52,11 +45,6 @@ func TestBasicAuthDecode(t *testing.T) {
5245
assert.Error(t, err)
5346
}
5447

55-
func TestBasicAuthEncode(t *testing.T) {
56-
assert.Equal(t, "Zm9vOmJhcg==", BasicAuthEncode("foo", "bar"))
57-
assert.Equal(t, "MjM6IjotLS0t", BasicAuthEncode("23:\"", "----"))
58-
}
59-
6048
func TestVerifyTimeLimitCode(t *testing.T) {
6149
tc := []struct {
6250
data string
@@ -167,29 +155,6 @@ func TestInt64sToStrings(t *testing.T) {
167155
)
168156
}
169157

170-
func TestInt64sContains(t *testing.T) {
171-
assert.True(t, Int64sContains([]int64{6, 44324, 4324, 32, 1, 2323}, 1))
172-
assert.True(t, Int64sContains([]int64{2323}, 2323))
173-
assert.False(t, Int64sContains([]int64{6, 44324, 4324, 32, 1, 2323}, 232))
174-
}
175-
176-
func TestIsLetter(t *testing.T) {
177-
assert.True(t, IsLetter('a'))
178-
assert.True(t, IsLetter('e'))
179-
assert.True(t, IsLetter('q'))
180-
assert.True(t, IsLetter('z'))
181-
assert.True(t, IsLetter('A'))
182-
assert.True(t, IsLetter('E'))
183-
assert.True(t, IsLetter('Q'))
184-
assert.True(t, IsLetter('Z'))
185-
assert.True(t, IsLetter('_'))
186-
assert.False(t, IsLetter('-'))
187-
assert.False(t, IsLetter('1'))
188-
assert.False(t, IsLetter('$'))
189-
assert.False(t, IsLetter(0x00))
190-
assert.False(t, IsLetter(0x93))
191-
}
192-
193158
// TODO: Test EntryIcon
194159

195160
func TestSetupGiteaRoot(t *testing.T) {

0 commit comments

Comments
 (0)