Skip to content

Commit 8234a57

Browse files
committed
Merge branch 'main' into lunny/optimaze_dashboard_heatmap
2 parents 8f79553 + 1b4adc0 commit 8234a57

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

+321
-110
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Gitea DevContainer",
3-
"image": "mcr.microsoft.com/devcontainers/go:1.23-bookworm",
3+
"image": "mcr.microsoft.com/devcontainers/go:1.24-bookworm",
44
"features": {
55
// installs nodejs into container
66
"ghcr.io/devcontainers/features/node:1": {

models/actions/variable.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ package actions
66
import (
77
"context"
88
"strings"
9+
"unicode/utf8"
910

1011
"code.gitea.io/gitea/models/db"
1112
"code.gitea.io/gitea/modules/log"
1213
"code.gitea.io/gitea/modules/timeutil"
14+
"code.gitea.io/gitea/modules/util"
1315

1416
"xorm.io/builder"
1517
)
@@ -32,26 +34,39 @@ type ActionVariable struct {
3234
RepoID int64 `xorm:"INDEX UNIQUE(owner_repo_name)"`
3335
Name string `xorm:"UNIQUE(owner_repo_name) NOT NULL"`
3436
Data string `xorm:"LONGTEXT NOT NULL"`
37+
Description string `xorm:"TEXT"`
3538
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
3639
UpdatedUnix timeutil.TimeStamp `xorm:"updated"`
3740
}
3841

42+
const (
43+
VariableDataMaxLength = 65536
44+
VariableDescriptionMaxLength = 4096
45+
)
46+
3947
func init() {
4048
db.RegisterModel(new(ActionVariable))
4149
}
4250

43-
func InsertVariable(ctx context.Context, ownerID, repoID int64, name, data string) (*ActionVariable, error) {
51+
func InsertVariable(ctx context.Context, ownerID, repoID int64, name, data, description string) (*ActionVariable, error) {
4452
if ownerID != 0 && repoID != 0 {
4553
// It's trying to create a variable that belongs to a repository, but OwnerID has been set accidentally.
4654
// Remove OwnerID to avoid confusion; it's not worth returning an error here.
4755
ownerID = 0
4856
}
4957

58+
if utf8.RuneCountInString(data) > VariableDataMaxLength {
59+
return nil, util.NewInvalidArgumentErrorf("data too long")
60+
}
61+
62+
description = util.TruncateRunes(description, VariableDescriptionMaxLength)
63+
5064
variable := &ActionVariable{
51-
OwnerID: ownerID,
52-
RepoID: repoID,
53-
Name: strings.ToUpper(name),
54-
Data: data,
65+
OwnerID: ownerID,
66+
RepoID: repoID,
67+
Name: strings.ToUpper(name),
68+
Data: data,
69+
Description: description,
5570
}
5671
return variable, db.Insert(ctx, variable)
5772
}
@@ -96,6 +111,12 @@ func FindVariables(ctx context.Context, opts FindVariablesOpts) ([]*ActionVariab
96111
}
97112

98113
func UpdateVariableCols(ctx context.Context, variable *ActionVariable, cols ...string) (bool, error) {
114+
if utf8.RuneCountInString(variable.Data) > VariableDataMaxLength {
115+
return false, util.NewInvalidArgumentErrorf("data too long")
116+
}
117+
118+
variable.Description = util.TruncateRunes(variable.Description, VariableDescriptionMaxLength)
119+
99120
variable.Name = strings.ToUpper(variable.Name)
100121
count, err := db.GetEngine(ctx).
101122
ID(variable.ID).

models/migrations/migrations.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ func prepareMigrationTasks() []*migration {
376376
newMigration(313, "Move PinOrder from issue table to a new table issue_pin", v1_24.MovePinOrderToTableIssuePin),
377377
newMigration(314, "Update OwnerID as zero for repository level action tables", v1_24.UpdateOwnerIDOfRepoLevelActionsTables),
378378
newMigration(315, "Add Ephemeral to ActionRunner", v1_24.AddEphemeralToActionRunner),
379-
newMigration(316, "Add new index for action for heatmap", v1_24.AddNewIndexForUserDashboard),
379+
newMigration(316, "Add description for secrets and variables", v1_24.AddDescriptionForSecretsAndVariables),
380+
newMigration(317, "Add new index for action for heatmap", v1_24.AddNewIndexForUserDashboard),
380381
}
381382
return preparedMigrations
382383
}

models/migrations/v1_24/v316.go

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,17 @@
44
package v1_24 //nolint
55

66
import (
7-
"code.gitea.io/gitea/modules/timeutil"
8-
97
"xorm.io/xorm"
10-
"xorm.io/xorm/schemas"
118
)
129

13-
type improveActionTableIndicesAction struct {
14-
ID int64 `xorm:"pk autoincr"`
15-
UserID int64 `xorm:"INDEX"` // Receiver user id.
16-
OpType int
17-
ActUserID int64 // Action user id.
18-
RepoID int64
19-
CommentID int64 `xorm:"INDEX"`
20-
IsDeleted bool `xorm:"NOT NULL DEFAULT false"`
21-
RefName string
22-
IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
23-
Content string `xorm:"TEXT"`
24-
CreatedUnix timeutil.TimeStamp `xorm:"created"`
25-
}
26-
27-
// TableName sets the name of this table
28-
func (*improveActionTableIndicesAction) TableName() string {
29-
return "action"
30-
}
31-
32-
// TableIndices implements xorm's TableIndices interface
33-
func (a *improveActionTableIndicesAction) TableIndices() []*schemas.Index {
34-
repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType)
35-
repoIndex.AddColumn("repo_id", "user_id", "is_deleted")
36-
37-
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
38-
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
10+
func AddDescriptionForSecretsAndVariables(x *xorm.Engine) error {
11+
type Secret struct {
12+
Description string `xorm:"TEXT"`
13+
}
3914

40-
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
41-
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
42-
43-
cuIndex := schemas.NewIndex("c_u", schemas.IndexType)
44-
cuIndex.AddColumn("user_id", "is_deleted")
45-
46-
actUserUserIndex := schemas.NewIndex("au_c_u", schemas.IndexType)
47-
actUserUserIndex.AddColumn("act_user_id", "created_unix", "user_id")
48-
49-
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex, cuIndex, actUserUserIndex}
50-
51-
return indices
52-
}
15+
type ActionVariable struct {
16+
Description string `xorm:"TEXT"`
17+
}
5318

54-
func AddNewIndexForUserDashboard(x *xorm.Engine) error {
55-
return x.Sync(new(improveActionTableIndicesAction))
19+
return x.Sync(new(Secret), new(ActionVariable))
5620
}

models/migrations/v1_24/v317.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_24 //nolint
5+
6+
import (
7+
"code.gitea.io/gitea/modules/timeutil"
8+
9+
"xorm.io/xorm"
10+
"xorm.io/xorm/schemas"
11+
)
12+
13+
type improveActionTableIndicesAction struct {
14+
ID int64 `xorm:"pk autoincr"`
15+
UserID int64 `xorm:"INDEX"` // Receiver user id.
16+
OpType int
17+
ActUserID int64 // Action user id.
18+
RepoID int64
19+
CommentID int64 `xorm:"INDEX"`
20+
IsDeleted bool `xorm:"NOT NULL DEFAULT false"`
21+
RefName string
22+
IsPrivate bool `xorm:"NOT NULL DEFAULT false"`
23+
Content string `xorm:"TEXT"`
24+
CreatedUnix timeutil.TimeStamp `xorm:"created"`
25+
}
26+
27+
// TableName sets the name of this table
28+
func (*improveActionTableIndicesAction) TableName() string {
29+
return "action"
30+
}
31+
32+
// TableIndices implements xorm's TableIndices interface
33+
func (a *improveActionTableIndicesAction) TableIndices() []*schemas.Index {
34+
repoIndex := schemas.NewIndex("r_u_d", schemas.IndexType)
35+
repoIndex.AddColumn("repo_id", "user_id", "is_deleted")
36+
37+
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
38+
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
39+
40+
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
41+
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
42+
43+
cuIndex := schemas.NewIndex("c_u", schemas.IndexType)
44+
cuIndex.AddColumn("user_id", "is_deleted")
45+
46+
actUserUserIndex := schemas.NewIndex("au_c_u", schemas.IndexType)
47+
actUserUserIndex.AddColumn("act_user_id", "created_unix", "user_id")
48+
49+
indices := []*schemas.Index{actUserIndex, repoIndex, cudIndex, cuIndex, actUserUserIndex}
50+
51+
return indices
52+
}
53+
54+
func AddNewIndexForUserDashboard(x *xorm.Engine) error {
55+
return x.Sync(new(improveActionTableIndicesAction))
56+
}

models/secret/secret.go

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ type Secret struct {
4040
RepoID int64 `xorm:"INDEX UNIQUE(owner_repo_name) NOT NULL DEFAULT 0"`
4141
Name string `xorm:"UNIQUE(owner_repo_name) NOT NULL"`
4242
Data string `xorm:"LONGTEXT"` // encrypted data
43+
Description string `xorm:"TEXT"`
4344
CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL"`
4445
}
4546

47+
const (
48+
SecretDataMaxLength = 65536
49+
SecretDescriptionMaxLength = 4096
50+
)
51+
4652
// ErrSecretNotFound represents a "secret not found" error.
4753
type ErrSecretNotFound struct {
4854
Name string
@@ -57,7 +63,7 @@ func (err ErrSecretNotFound) Unwrap() error {
5763
}
5864

5965
// InsertEncryptedSecret Creates, encrypts, and validates a new secret with yet unencrypted data and insert into database
60-
func InsertEncryptedSecret(ctx context.Context, ownerID, repoID int64, name, data string) (*Secret, error) {
66+
func InsertEncryptedSecret(ctx context.Context, ownerID, repoID int64, name, data, description string) (*Secret, error) {
6167
if ownerID != 0 && repoID != 0 {
6268
// It's trying to create a secret that belongs to a repository, but OwnerID has been set accidentally.
6369
// Remove OwnerID to avoid confusion; it's not worth returning an error here.
@@ -67,15 +73,23 @@ func InsertEncryptedSecret(ctx context.Context, ownerID, repoID int64, name, dat
6773
return nil, fmt.Errorf("%w: ownerID and repoID cannot be both zero, global secrets are not supported", util.ErrInvalidArgument)
6874
}
6975

76+
if len(data) > SecretDataMaxLength {
77+
return nil, util.NewInvalidArgumentErrorf("data too long")
78+
}
79+
80+
description = util.TruncateRunes(description, SecretDescriptionMaxLength)
81+
7082
encrypted, err := secret_module.EncryptSecret(setting.SecretKey, data)
7183
if err != nil {
7284
return nil, err
7385
}
86+
7487
secret := &Secret{
75-
OwnerID: ownerID,
76-
RepoID: repoID,
77-
Name: strings.ToUpper(name),
78-
Data: encrypted,
88+
OwnerID: ownerID,
89+
RepoID: repoID,
90+
Name: strings.ToUpper(name),
91+
Data: encrypted,
92+
Description: description,
7993
}
8094
return secret, db.Insert(ctx, secret)
8195
}
@@ -114,16 +128,23 @@ func (opts FindSecretsOptions) ToConds() builder.Cond {
114128
}
115129

116130
// UpdateSecret changes org or user reop secret.
117-
func UpdateSecret(ctx context.Context, secretID int64, data string) error {
131+
func UpdateSecret(ctx context.Context, secretID int64, data, description string) error {
132+
if len(data) > SecretDataMaxLength {
133+
return util.NewInvalidArgumentErrorf("data too long")
134+
}
135+
136+
description = util.TruncateRunes(description, SecretDescriptionMaxLength)
137+
118138
encrypted, err := secret_module.EncryptSecret(setting.SecretKey, data)
119139
if err != nil {
120140
return err
121141
}
122142

123143
s := &Secret{
124-
Data: encrypted,
144+
Data: encrypted,
145+
Description: description,
125146
}
126-
affected, err := db.GetEngine(ctx).ID(secretID).Cols("data").Update(s)
147+
affected, err := db.GetEngine(ctx).ID(secretID).Cols("data", "description").Update(s)
127148
if affected != 1 {
128149
return ErrSecretNotFound{}
129150
}

modules/structs/secret.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import "time"
1010
type Secret struct {
1111
// the secret's name
1212
Name string `json:"name"`
13+
// the secret's description
14+
Description string `json:"description"`
1315
// swagger:strfmt date-time
1416
Created time.Time `json:"created_at"`
1517
}
@@ -21,4 +23,9 @@ type CreateOrUpdateSecretOption struct {
2123
//
2224
// required: true
2325
Data string `json:"data" binding:"Required"`
26+
27+
// Description of the secret to update
28+
//
29+
// required: false
30+
Description string `json:"description"`
2431
}

modules/structs/variable.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ type CreateVariableOption struct {
1010
//
1111
// required: true
1212
Value string `json:"value" binding:"Required"`
13+
14+
// Description of the variable to create
15+
//
16+
// required: false
17+
Description string `json:"description"`
1318
}
1419

1520
// UpdateVariableOption the option when updating variable
@@ -21,6 +26,11 @@ type UpdateVariableOption struct {
2126
//
2227
// required: true
2328
Value string `json:"value" binding:"Required"`
29+
30+
// Description of the variable to update
31+
//
32+
// required: false
33+
Description string `json:"description"`
2434
}
2535

2636
// ActionVariable return value of the query API
@@ -34,4 +44,6 @@ type ActionVariable struct {
3444
Name string `json:"name"`
3545
// the value of the variable
3646
Data string `json:"data"`
47+
// the description of the variable
48+
Description string `json:"description"`
3749
}

options/locale/locale_cs-CZ.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,6 +3679,7 @@ secrets=Tajné klíče
36793679
description=Tejné klíče budou předány určitým akcím a nelze je přečíst jinak.
36803680
none=Zatím zde nejsou žádné tajné klíče.
36813681
creation=Přidat tajný klíč
3682+
creation.description=Popis
36823683
creation.name_placeholder=nerozlišovat velká a malá písmena, pouze alfanumerické znaky nebo podtržítka, nemohou začínat na GITEA_ nebo GITHUB_
36833684
creation.value_placeholder=Vložte jakýkoliv obsah. Mezery na začátku a konci budou vynechány.
36843685
creation.success=Tajný klíč „%s“ byl přidán.

options/locale/locale_de-DE.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3670,6 +3670,7 @@ secrets=Secrets
36703670
description=Secrets werden an bestimmte Aktionen weitergegeben und können nicht anderweitig ausgelesen werden.
36713671
none=Noch keine Secrets vorhanden.
36723672
creation=Secret hinzufügen
3673+
creation.description=Beschreibung
36733674
creation.name_placeholder=Groß-/Kleinschreibung wird ignoriert, nur alphanumerische Zeichen oder Unterstriche, darf nicht mit GITEA_ oder GITHUB_ beginnen
36743675
creation.value_placeholder=Beliebigen Inhalt eingeben. Leerzeichen am Anfang und Ende werden weggelassen.
36753676
creation.success=Das Secret "%s" wurde hinzugefügt.

0 commit comments

Comments
 (0)