Skip to content

Commit bbbdc38

Browse files
committed
Merge branch 'main' into bugfix/notify_pr_sync
2 parents cdd8381 + 8913916 commit bbbdc38

File tree

21 files changed

+306
-148
lines changed

21 files changed

+306
-148
lines changed

cmd/admin.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ var (
180180
Name: "raw",
181181
Usage: "Display only the token value",
182182
},
183+
cli.StringFlag{
184+
Name: "scopes",
185+
Value: "",
186+
Usage: "Comma separated list of scopes to apply to access token",
187+
},
183188
},
184189
Action: runGenerateAccessToken,
185190
}
@@ -698,9 +703,15 @@ func runGenerateAccessToken(c *cli.Context) error {
698703
return err
699704
}
700705

706+
accessTokenScope, err := auth_model.AccessTokenScope(c.String("scopes")).Normalize()
707+
if err != nil {
708+
return err
709+
}
710+
701711
t := &auth_model.AccessToken{
702-
Name: c.String("token-name"),
703-
UID: user.ID,
712+
Name: c.String("token-name"),
713+
UID: user.ID,
714+
Scope: accessTokenScope,
704715
}
705716

706717
if err := auth_model.NewAccessToken(t); err != nil {

models/asymkey/error.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func (err ErrKeyUnableVerify) Error() string {
2424
return fmt.Sprintf("Unable to verify key content [result: %s]", err.Result)
2525
}
2626

27+
// ErrKeyIsPrivate is returned when the provided key is a private key not a public key
28+
var ErrKeyIsPrivate = util.NewSilentWrapErrorf(util.ErrInvalidArgument, "the provided key is a private key")
29+
2730
// ErrKeyNotExist represents a "KeyNotExist" kind of error.
2831
type ErrKeyNotExist struct {
2932
ID int64

models/asymkey/ssh_key_parse.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ func parseKeyString(content string) (string, error) {
9696
if block == nil {
9797
return "", fmt.Errorf("failed to parse PEM block containing the public key")
9898
}
99+
if strings.Contains(block.Type, "PRIVATE") {
100+
return "", ErrKeyIsPrivate
101+
}
99102

100103
pub, err := x509.ParsePKIXPublicKey(block.Bytes)
101104
if err != nil {

models/dbfs/dbfs.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@ import (
1010
"code.gitea.io/gitea/models/db"
1111
)
1212

13+
/*
14+
The reasons behind the DBFS (database-filesystem) package:
15+
When a Gitea action is running, the Gitea action server should collect and store all the logs.
16+
17+
The requirements are:
18+
* The running logs must be stored across the cluster if the Gitea servers are deployed as a cluster.
19+
* The logs will be archived to Object Storage (S3/MinIO, etc.) after a period of time.
20+
* The Gitea action UI should be able to render the running logs and the archived logs.
21+
22+
Some possible solutions for the running logs:
23+
* [Not ideal] Using local temp file: it can not be shared across the cluster.
24+
* [Not ideal] Using shared file in the filesystem of git repository: although at the moment, the Gitea cluster's
25+
git repositories must be stored in a shared filesystem, in the future, Gitea may need a dedicated Git Service Server
26+
to decouple the shared filesystem. Then the action logs will become a blocker.
27+
* [Not ideal] Record the logs in a database table line by line: it has a couple of problems:
28+
- It's difficult to make multiple increasing sequence (log line number) for different databases.
29+
- The database table will have a lot of rows and be affected by the big-table performance problem.
30+
- It's difficult to load logs by using the same interface as other storages.
31+
- It's difficult to calculate the size of the logs.
32+
33+
The DBFS solution:
34+
* It can be used in a cluster.
35+
* It can share the same interface (Read/Write/Seek) as other storages.
36+
* It's very friendly to database because it only needs to store much fewer rows than the log-line solution.
37+
* In the future, when Gitea action needs to limit the log size (other CI/CD services also do so), it's easier to calculate the log file size.
38+
* Even sometimes the UI needs to render the tailing lines, the tailing lines can be found be counting the "\n" from the end of the file by seek.
39+
The seeking and finding is not the fastest way, but it's still acceptable and won't affect the performance too much.
40+
*/
41+
1342
type dbfsMeta struct {
1443
ID int64 `xorm:"pk autoincr"`
1544
FullPath string `xorm:"VARCHAR(500) UNIQUE NOT NULL"`

models/fixtures/repository.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
owner_name: user2
55
lower_name: repo1
66
name: repo1
7+
default_branch: master
78
num_watches: 4
89
num_stars: 0
910
num_forks: 0
@@ -34,6 +35,7 @@
3435
owner_name: user2
3536
lower_name: repo2
3637
name: repo2
38+
default_branch: master
3739
num_watches: 0
3840
num_stars: 1
3941
num_forks: 0
@@ -64,6 +66,7 @@
6466
owner_name: user3
6567
lower_name: repo3
6668
name: repo3
69+
default_branch: master
6770
num_watches: 0
6871
num_stars: 0
6972
num_forks: 0
@@ -94,6 +97,7 @@
9497
owner_name: user5
9598
lower_name: repo4
9699
name: repo4
100+
default_branch: master
97101
num_watches: 0
98102
num_stars: 1
99103
num_forks: 0
@@ -274,6 +278,7 @@
274278
owner_name: user12
275279
lower_name: repo10
276280
name: repo10
281+
default_branch: master
277282
num_watches: 0
278283
num_stars: 0
279284
num_forks: 1
@@ -304,6 +309,7 @@
304309
owner_name: user13
305310
lower_name: repo11
306311
name: repo11
312+
default_branch: master
307313
num_watches: 0
308314
num_stars: 0
309315
num_forks: 0
@@ -425,6 +431,7 @@
425431
owner_name: user2
426432
lower_name: repo15
427433
name: repo15
434+
default_branch: master
428435
num_watches: 0
429436
num_stars: 0
430437
num_forks: 0
@@ -455,6 +462,7 @@
455462
owner_name: user2
456463
lower_name: repo16
457464
name: repo16
465+
default_branch: master
458466
num_watches: 0
459467
num_stars: 0
460468
num_forks: 0
@@ -905,6 +913,7 @@
905913
owner_name: user2
906914
lower_name: repo20
907915
name: repo20
916+
default_branch: master
908917
num_watches: 0
909918
num_stars: 0
910919
num_forks: 0
@@ -965,6 +974,7 @@
965974
owner_name: user2
966975
lower_name: utf8
967976
name: utf8
977+
default_branch: master
968978
num_watches: 0
969979
num_stars: 0
970980
num_forks: 0
@@ -1055,6 +1065,7 @@
10551065
owner_name: user2
10561066
lower_name: commits_search_test
10571067
name: commits_search_test
1068+
default_branch: master
10581069
num_watches: 0
10591070
num_stars: 0
10601071
num_forks: 0
@@ -1085,6 +1096,7 @@
10851096
owner_name: user2
10861097
lower_name: git_hooks_test
10871098
name: git_hooks_test
1099+
default_branch: master
10881100
num_watches: 0
10891101
num_stars: 0
10901102
num_forks: 0
@@ -1115,6 +1127,7 @@
11151127
owner_name: limited_org
11161128
lower_name: public_repo_on_limited_org
11171129
name: public_repo_on_limited_org
1130+
default_branch: master
11181131
num_watches: 0
11191132
num_stars: 0
11201133
num_forks: 0
@@ -1145,6 +1158,7 @@
11451158
owner_name: limited_org
11461159
lower_name: private_repo_on_limited_org
11471160
name: private_repo_on_limited_org
1161+
default_branch: master
11481162
num_watches: 0
11491163
num_stars: 0
11501164
num_forks: 0
@@ -1175,6 +1189,7 @@
11751189
owner_name: privated_org
11761190
lower_name: public_repo_on_private_org
11771191
name: public_repo_on_private_org
1192+
default_branch: master
11781193
num_watches: 0
11791194
num_stars: 0
11801195
num_forks: 0
@@ -1205,6 +1220,7 @@
12051220
owner_name: privated_org
12061221
lower_name: private_repo_on_private_org
12071222
name: private_repo_on_private_org
1223+
default_branch: master
12081224
num_watches: 0
12091225
num_stars: 0
12101226
num_forks: 0
@@ -1235,6 +1251,7 @@
12351251
owner_name: user2
12361252
lower_name: glob
12371253
name: glob
1254+
default_branch: master
12381255
num_watches: 0
12391256
num_stars: 0
12401257
num_forks: 0
@@ -1295,6 +1312,7 @@
12951312
owner_name: user27
12961313
lower_name: template1
12971314
name: template1
1315+
default_branch: master
12981316
num_watches: 0
12991317
num_stars: 0
13001318
num_forks: 0
@@ -1355,6 +1373,7 @@
13551373
owner_name: org26
13561374
lower_name: repo_external_tracker
13571375
name: repo_external_tracker
1376+
default_branch: master
13581377
num_watches: 0
13591378
num_stars: 0
13601379
num_forks: 0
@@ -1385,6 +1404,7 @@
13851404
owner_name: org26
13861405
lower_name: repo_external_tracker_numeric
13871406
name: repo_external_tracker_numeric
1407+
default_branch: master
13881408
num_watches: 0
13891409
num_stars: 0
13901410
num_forks: 0
@@ -1415,6 +1435,7 @@
14151435
owner_name: org26
14161436
lower_name: repo_external_tracker_alpha
14171437
name: repo_external_tracker_alpha
1438+
default_branch: master
14181439
num_watches: 0
14191440
num_stars: 0
14201441
num_forks: 0
@@ -1445,6 +1466,7 @@
14451466
owner_name: user27
14461467
lower_name: repo49
14471468
name: repo49
1469+
default_branch: master
14481470
num_watches: 0
14491471
num_stars: 0
14501472
num_forks: 0
@@ -1475,6 +1497,7 @@
14751497
owner_name: user30
14761498
lower_name: repo50
14771499
name: repo50
1500+
default_branch: master
14781501
num_watches: 0
14791502
num_stars: 0
14801503
num_forks: 0
@@ -1505,6 +1528,7 @@
15051528
owner_name: user30
15061529
lower_name: repo51
15071530
name: repo51
1531+
default_branch: master
15081532
num_watches: 0
15091533
num_stars: 0
15101534
num_forks: 0
@@ -1565,6 +1589,7 @@
15651589
owner_name: user30
15661590
lower_name: renderer
15671591
name: renderer
1592+
default_branch: master
15681593
is_archived: false
15691594
is_empty: false
15701595
is_private: false
@@ -1592,6 +1617,7 @@
15921617
owner_name: user2
15931618
lower_name: lfs
15941619
name: lfs
1620+
default_branch: master
15951621
is_empty: false
15961622
is_archived: false
15971623
is_private: true

models/issues/pull_list.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,9 @@ func (prs PullRequestList) loadAttributes(ctx context.Context) error {
173173
for i := range issues {
174174
set[issues[i].ID] = issues[i]
175175
}
176-
for i := range prs {
177-
prs[i].Issue = set[prs[i].IssueID]
176+
for _, pr := range prs {
177+
pr.Issue = set[pr.IssueID]
178+
pr.Issue.PullRequest = pr // panic here means issueIDs and prs are not in sync
178179
}
179180
return nil
180181
}

models/repo/repo.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,6 @@ func (repo *Repository) IsBroken() bool {
227227

228228
// AfterLoad is invoked from XORM after setting the values of all fields of this object.
229229
func (repo *Repository) AfterLoad() {
230-
// FIXME: use models migration to solve all at once.
231-
if len(repo.DefaultBranch) == 0 {
232-
repo.DefaultBranch = setting.Repository.DefaultBranch
233-
}
234-
235230
repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
236231
repo.NumOpenPulls = repo.NumPulls - repo.NumClosedPulls
237232
repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones

modules/actions/workflows.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ func DetectWorkflows(commit *git.Commit, triggedEvent webhook_module.HookEventTy
7575
if evt.Name != triggedEvent.Event() {
7676
continue
7777
}
78-
7978
if detectMatched(commit, triggedEvent, payload, evt) {
8079
workflows[entry.Name()] = content
8180
}
@@ -105,8 +104,9 @@ func detectMatched(commit *git.Commit, triggedEvent webhook_module.HookEventType
105104
for cond, vals := range evt.Acts {
106105
switch cond {
107106
case "branches", "tags":
107+
refShortName := git.RefName(pushPayload.Ref).ShortName()
108108
for _, val := range vals {
109-
if glob.MustCompile(val, '/').Match(pushPayload.Ref) {
109+
if glob.MustCompile(val, '/').Match(refShortName) {
110110
matchTimes++
111111
break
112112
}
@@ -160,8 +160,9 @@ func detectMatched(commit *git.Commit, triggedEvent webhook_module.HookEventType
160160
}
161161
}
162162
case "branches":
163+
refShortName := git.RefName(prPayload.PullRequest.Base.Ref).ShortName()
163164
for _, val := range vals {
164-
if glob.MustCompile(val, '/').Match(prPayload.PullRequest.Base.Ref) {
165+
if glob.MustCompile(val, '/').Match(refShortName) {
165166
matchTimes++
166167
break
167168
}

modules/charset/escape.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func EscapeControlReader(reader io.Reader, writer io.Writer, locale translation.
4444
return streamer.escaped, err
4545
}
4646

47-
// EscapeControlStringReader escapes the unicode control sequences in a provided reader of string content and writer in a locale and returns the findings as an EscapeStatus and the escaped []byte
47+
// EscapeControlStringReader escapes the unicode control sequences in a provided reader of string content and writer in a locale and returns the findings as an EscapeStatus and the escaped []byte. HTML line breaks are not inserted after every newline by this method.
4848
func EscapeControlStringReader(reader io.Reader, writer io.Writer, locale translation.Locale, allowed ...rune) (escaped *EscapeStatus, err error) {
4949
bufRd := bufio.NewReader(reader)
5050
outputStream := &HTMLStreamerWriter{Writer: writer}
@@ -65,10 +65,6 @@ func EscapeControlStringReader(reader io.Reader, writer io.Writer, locale transl
6565
}
6666
break
6767
}
68-
if err := streamer.SelfClosingTag("br"); err != nil {
69-
streamer.escaped.HasError = true
70-
return streamer.escaped, err
71-
}
7268
}
7369
return streamer.escaped, err
7470
}

modules/httpcache/httpcache.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
func AddCacheControlToHeader(h http.Header, maxAge time.Duration, additionalDirectives ...string) {
2020
directives := make([]string, 0, 2+len(additionalDirectives))
2121

22+
// "max-age=0 + must-revalidate" (aka "no-cache") is preferred instead of "no-store"
23+
// because browsers may restore some input fields after navigate-back / reload a page.
2224
if setting.IsProd {
2325
if maxAge == 0 {
2426
directives = append(directives, "max-age=0", "private", "must-revalidate")

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ organization_leave_success = You have successfully left the organization %s.
518518
invalid_ssh_key = Cannot verify your SSH key: %s
519519
invalid_gpg_key = Cannot verify your GPG key: %s
520520
invalid_ssh_principal = Invalid principal: %s
521+
must_use_public_key = The key you provided is a private key. Please do not upload your private key anywhere. Use your public key instead.
521522
unable_verify_ssh_key = "Cannot verify the SSH key; double-check it for mistakes."
522523
auth_failed = Authentication failed: %v
523524

routers/web/repo/setting.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,10 @@ func DeployKeysPost(ctx *context.Context) {
11581158
ctx.Flash.Info(ctx.Tr("settings.ssh_disabled"))
11591159
} else if asymkey_model.IsErrKeyUnableVerify(err) {
11601160
ctx.Flash.Info(ctx.Tr("form.unable_verify_ssh_key"))
1161+
} else if err == asymkey_model.ErrKeyIsPrivate {
1162+
ctx.Data["HasError"] = true
1163+
ctx.Data["Err_Content"] = true
1164+
ctx.Flash.Error(ctx.Tr("form.must_use_public_key"))
11611165
} else {
11621166
ctx.Data["HasError"] = true
11631167
ctx.Data["Err_Content"] = true

0 commit comments

Comments
 (0)