Skip to content

Commit 05f701b

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Use `object-fit: contain` for oauth2 custom icons (go-gitea#26493) add disable workflow feature (go-gitea#26413) Move dropzone progress bar to bottom to show filename when uploading (go-gitea#26492) Handle base64 decoding correctly to avoid panic (go-gitea#26483) Allow to archive labels (go-gitea#26478)
2 parents 295d726 + c91a7e8 commit 05f701b

File tree

37 files changed

+341
-53
lines changed

37 files changed

+341
-53
lines changed

cmd/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ func runGenerateInternalToken(c *cli.Context) error {
7070
}
7171

7272
func runGenerateLfsJwtSecret(c *cli.Context) error {
73-
JWTSecretBase64, err := generate.NewJwtSecretBase64()
73+
_, jwtSecretBase64, err := generate.NewJwtSecretBase64()
7474
if err != nil {
7575
return err
7676
}
7777

78-
fmt.Printf("%s", JWTSecretBase64)
78+
fmt.Printf("%s", jwtSecretBase64)
7979

8080
if isatty.IsTerminal(os.Stdout.Fd()) {
8181
fmt.Printf("\n")

models/fixtures/label.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
exclusive: false
88
num_issues: 2
99
num_closed_issues: 0
10+
archived_unix: 0
1011

1112
-
1213
id: 2
@@ -17,6 +18,7 @@
1718
exclusive: false
1819
num_issues: 1
1920
num_closed_issues: 1
21+
archived_unix: 0
2022

2123
-
2224
id: 3
@@ -27,6 +29,7 @@
2729
exclusive: false
2830
num_issues: 0
2931
num_closed_issues: 0
32+
archived_unix: 0
3033

3134
-
3235
id: 4
@@ -37,6 +40,7 @@
3740
exclusive: false
3841
num_issues: 1
3942
num_closed_issues: 0
43+
archived_unix: 0
4044

4145
-
4246
id: 5
@@ -47,6 +51,7 @@
4751
exclusive: false
4852
num_issues: 0
4953
num_closed_issues: 0
54+
archived_unix: 0
5055

5156
-
5257
id: 6
@@ -57,6 +62,7 @@
5762
exclusive: false
5863
num_issues: 0
5964
num_closed_issues: 0
65+
archived_unix: 0
6066

6167
-
6268
id: 7
@@ -67,6 +73,7 @@
6773
exclusive: true
6874
num_issues: 0
6975
num_closed_issues: 0
76+
archived_unix: 0
7077

7178
-
7279
id: 8
@@ -77,6 +84,7 @@
7784
exclusive: true
7885
num_issues: 0
7986
num_closed_issues: 0
87+
archived_unix: 0
8088

8189
-
8290
id: 9
@@ -87,3 +95,4 @@
8795
exclusive: true
8896
num_issues: 0
8997
num_closed_issues: 0
98+
archived_unix: 0

models/issues/label.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ type Label struct {
9797
QueryString string `xorm:"-"`
9898
IsSelected bool `xorm:"-"`
9999
IsExcluded bool `xorm:"-"`
100+
101+
ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT NULL"`
100102
}
101103

102104
func init() {
@@ -109,6 +111,15 @@ func (l *Label) CalOpenIssues() {
109111
l.NumOpenIssues = l.NumIssues - l.NumClosedIssues
110112
}
111113

114+
// SetArchived set the label as archived
115+
func (l *Label) SetArchived(isArchived bool) {
116+
if isArchived && l.ArchivedUnix.IsZero() {
117+
l.ArchivedUnix = timeutil.TimeStampNow()
118+
} else {
119+
l.ArchivedUnix = timeutil.TimeStamp(0)
120+
}
121+
}
122+
112123
// CalOpenOrgIssues calculates the open issues of a label for a specific repo
113124
func (l *Label) CalOpenOrgIssues(ctx context.Context, repoID, labelID int64) {
114125
counts, _ := CountIssuesByRepo(ctx, &IssuesOptions{
@@ -153,6 +164,11 @@ func (l *Label) BelongsToOrg() bool {
153164
return l.OrgID > 0
154165
}
155166

167+
// IsArchived returns true if label is an archived
168+
func (l *Label) IsArchived() bool {
169+
return l.ArchivedUnix > 0
170+
}
171+
156172
// BelongsToRepo returns true if label is a repository label
157173
func (l *Label) BelongsToRepo() bool {
158174
return l.RepoID > 0
@@ -211,7 +227,7 @@ func UpdateLabel(l *Label) error {
211227
}
212228
l.Color = color
213229

214-
return updateLabelCols(db.DefaultContext, l, "name", "description", "color", "exclusive")
230+
return updateLabelCols(db.DefaultContext, l, "name", "description", "color", "exclusive", "archived_unix")
215231
}
216232

217233
// DeleteLabel delete a label

models/issues/label_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
repo_model "code.gitea.io/gitea/models/repo"
1212
"code.gitea.io/gitea/models/unittest"
1313
user_model "code.gitea.io/gitea/models/user"
14+
"code.gitea.io/gitea/modules/timeutil"
1415

1516
"github.com/stretchr/testify/assert"
1617
)
@@ -259,11 +260,12 @@ func TestUpdateLabel(t *testing.T) {
259260
label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1})
260261
// make sure update wont overwrite it
261262
update := &issues_model.Label{
262-
ID: label.ID,
263-
Color: "#ffff00",
264-
Name: "newLabelName",
265-
Description: label.Description,
266-
Exclusive: false,
263+
ID: label.ID,
264+
Color: "#ffff00",
265+
Name: "newLabelName",
266+
Description: label.Description,
267+
Exclusive: false,
268+
ArchivedUnix: timeutil.TimeStamp(0),
267269
}
268270
label.Color = update.Color
269271
label.Name = update.Name
@@ -273,6 +275,7 @@ func TestUpdateLabel(t *testing.T) {
273275
assert.EqualValues(t, label.Color, newLabel.Color)
274276
assert.EqualValues(t, label.Name, newLabel.Name)
275277
assert.EqualValues(t, label.Description, newLabel.Description)
278+
assert.EqualValues(t, newLabel.ArchivedUnix, 0)
276279
unittest.CheckConsistencyFor(t, &issues_model.Label{}, &repo_model.Repository{})
277280
}
278281

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ var migrations = []Migration{
522522
NewMigration("Drop deleted branch table", v1_21.DropDeletedBranchTable),
523523
// v270 -> v271
524524
NewMigration("Fix PackageProperty typo", v1_21.FixPackagePropertyTypo),
525+
// v271 -> v272
526+
NewMigration("Allow archiving labels", v1_21.AddArchivedUnixColumInLabelTable),
525527
}
526528

527529
// GetCurrentDBVersion returns the current db version

models/migrations/v1_21/v271.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_21 //nolint
5+
import (
6+
"code.gitea.io/gitea/modules/timeutil"
7+
8+
"xorm.io/xorm"
9+
)
10+
11+
func AddArchivedUnixColumInLabelTable(x *xorm.Engine) error {
12+
type Label struct {
13+
ArchivedUnix timeutil.TimeStamp `xorm:"DEFAULT NULL"`
14+
}
15+
return x.Sync(new(Label))
16+
}

models/repo/repo.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,13 @@ func (repo *Repository) MustGetUnit(ctx context.Context, tp unit.Type) *RepoUnit
391391
Type: tp,
392392
Config: new(IssuesConfig),
393393
}
394+
} else if tp == unit.TypeActions {
395+
return &RepoUnit{
396+
Type: tp,
397+
Config: new(ActionsConfig),
398+
}
394399
}
400+
395401
return &RepoUnit{
396402
Type: tp,
397403
Config: new(UnitConfig),

models/repo/repo_unit.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package repo
66
import (
77
"context"
88
"fmt"
9+
"strings"
910

1011
"code.gitea.io/gitea/models/db"
1112
"code.gitea.io/gitea/models/unit"
@@ -162,6 +163,42 @@ func (cfg *PullRequestsConfig) GetDefaultMergeStyle() MergeStyle {
162163
return MergeStyleMerge
163164
}
164165

166+
type ActionsConfig struct {
167+
DisabledWorkflows []string
168+
}
169+
170+
func (cfg *ActionsConfig) EnableWorkflow(file string) {
171+
cfg.DisabledWorkflows = util.SliceRemoveAll(cfg.DisabledWorkflows, file)
172+
}
173+
174+
func (cfg *ActionsConfig) ToString() string {
175+
return strings.Join(cfg.DisabledWorkflows, ",")
176+
}
177+
178+
func (cfg *ActionsConfig) IsWorkflowDisabled(file string) bool {
179+
return util.SliceContains(cfg.DisabledWorkflows, file)
180+
}
181+
182+
func (cfg *ActionsConfig) DisableWorkflow(file string) {
183+
for _, workflow := range cfg.DisabledWorkflows {
184+
if file == workflow {
185+
return
186+
}
187+
}
188+
189+
cfg.DisabledWorkflows = append(cfg.DisabledWorkflows, file)
190+
}
191+
192+
// FromDB fills up a ActionsConfig from serialized format.
193+
func (cfg *ActionsConfig) FromDB(bs []byte) error {
194+
return json.UnmarshalHandleDoubleEncode(bs, &cfg)
195+
}
196+
197+
// ToDB exports a ActionsConfig to a serialized format.
198+
func (cfg *ActionsConfig) ToDB() ([]byte, error) {
199+
return json.Marshal(cfg)
200+
}
201+
165202
// BeforeSet is invoked from XORM before setting the value of a field of this object.
166203
func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
167204
switch colName {
@@ -175,7 +212,9 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) {
175212
r.Config = new(PullRequestsConfig)
176213
case unit.TypeIssues:
177214
r.Config = new(IssuesConfig)
178-
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects, unit.TypePackages, unit.TypeActions:
215+
case unit.TypeActions:
216+
r.Config = new(ActionsConfig)
217+
case unit.TypeCode, unit.TypeReleases, unit.TypeWiki, unit.TypeProjects, unit.TypePackages:
179218
fallthrough
180219
default:
181220
r.Config = new(UnitConfig)
@@ -218,6 +257,11 @@ func (r *RepoUnit) ExternalTrackerConfig() *ExternalTrackerConfig {
218257
return r.Config.(*ExternalTrackerConfig)
219258
}
220259

260+
// ActionsConfig returns config for unit.ActionsConfig
261+
func (r *RepoUnit) ActionsConfig() *ActionsConfig {
262+
return r.Config.(*ActionsConfig)
263+
}
264+
221265
func getUnitsByRepoID(ctx context.Context, repoID int64) (units []*RepoUnit, err error) {
222266
var tmpUnits []*RepoUnit
223267
if err := db.GetEngine(ctx).Where("repo_id = ?", repoID).Find(&tmpUnits); err != nil {

models/repo/repo_unit_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package repo
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestActionsConfig(t *testing.T) {
13+
cfg := &ActionsConfig{}
14+
cfg.DisableWorkflow("test1.yaml")
15+
assert.EqualValues(t, []string{"test1.yaml"}, cfg.DisabledWorkflows)
16+
17+
cfg.DisableWorkflow("test1.yaml")
18+
assert.EqualValues(t, []string{"test1.yaml"}, cfg.DisabledWorkflows)
19+
20+
cfg.EnableWorkflow("test1.yaml")
21+
assert.EqualValues(t, []string{}, cfg.DisabledWorkflows)
22+
23+
cfg.EnableWorkflow("test1.yaml")
24+
assert.EqualValues(t, []string{}, cfg.DisabledWorkflows)
25+
26+
cfg.DisableWorkflow("test1.yaml")
27+
cfg.DisableWorkflow("test2.yaml")
28+
cfg.DisableWorkflow("test3.yaml")
29+
assert.EqualValues(t, "test1.yaml,test2.yaml,test3.yaml", cfg.ToString())
30+
}

modules/generate/generate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ func NewJwtSecret() ([]byte, error) {
4949
}
5050

5151
// NewJwtSecretBase64 generates a new base64 encoded value intended to be used for JWT secrets.
52-
func NewJwtSecretBase64() (string, error) {
52+
func NewJwtSecretBase64() ([]byte, string, error) {
5353
bytes, err := NewJwtSecret()
5454
if err != nil {
55-
return "", err
55+
return nil, "", err
5656
}
57-
return base64.RawURLEncoding.EncodeToString(bytes), nil
57+
return bytes, base64.RawURLEncoding.EncodeToString(bytes), nil
5858
}
5959

6060
// NewSecretKey generate a new value intended to be used by SECRET_KEY.

0 commit comments

Comments
 (0)