Skip to content

Commit 7cfa8bf

Browse files
author
Gusted
authored
Merge branch 'main' into improve-code-review-comment
2 parents d489ecc + 0614ae1 commit 7cfa8bf

File tree

104 files changed

+2957
-424
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2957
-424
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fmt-check: fmt
280280

281281
.PHONY: misspell-check
282282
misspell-check:
283-
go run $(MISSPELL_PACKAGE) -error -i unknwon $(GO_DIRS) $(WEB_DIRS)
283+
go run $(MISSPELL_PACKAGE) -error $(GO_DIRS) $(WEB_DIRS)
284284

285285
.PHONY: vet
286286
vet:

docs/content/doc/developers/hacking-on-gitea.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ menu:
2323

2424
To get a quick working development environment you could use Gitpod.
2525

26-
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/go-gitea/gitea)
26+
[![Open in Gitpod](/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/go-gitea/gitea)
2727

2828
## Installing go
2929

docs/content/doc/features/comparison.en-us.md

Lines changed: 97 additions & 89 deletions
Large diffs are not rendered by default.

docs/content/doc/usage/reverse-proxies.zh-cn.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ menu:
1313
identifier: "reverse-proxies"
1414
---
1515

16+
# 反向代理
17+
18+
**目录**
19+
20+
{{< toc >}}
21+
1622
## 使用 Nginx 作为反向代理服务
1723

1824
如果您想使用 Nginx 作为 Gitea 的反向代理服务,您可以参照以下 `nginx.conf` 配置中 `server``http` 部分:
@@ -24,6 +30,10 @@ server {
2430
2531
location / {
2632
proxy_pass http://localhost:3000;
33+
proxy_set_header Host $host;
34+
proxy_set_header X-Real-IP $remote_addr;
35+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
36+
proxy_set_header X-Forwarded-Proto $scheme;
2737
}
2838
}
2939
```
@@ -41,6 +51,10 @@ server {
4151
location /git/ {
4252
# 注意: 反向代理后端 URL 的最后需要有一个路径符号
4353
proxy_pass http://localhost:3000/;
54+
proxy_set_header Host $host;
55+
proxy_set_header X-Real-IP $remote_addr;
56+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
57+
proxy_set_header X-Forwarded-Proto $scheme;
4458
}
4559
}
4660
```

docs/static/open-in-gitpod.svg

Lines changed: 23 additions & 0 deletions
Loading

models/activities/notification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ func getNotificationByID(ctx context.Context, notificationID int64) (*Notificati
806806
}
807807

808808
if !ok {
809-
return nil, db.ErrNotExist{ID: notificationID}
809+
return nil, db.ErrNotExist{Resource: "notification", ID: notificationID}
810810
}
811811

812812
return notification, nil

models/admin/task.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ func (err ErrTaskDoesNotExist) Error() string {
167167
err.ID, err.RepoID, err.Type)
168168
}
169169

170+
func (err ErrTaskDoesNotExist) Unwrap() error {
171+
return util.ErrNotExist
172+
}
173+
170174
// GetMigratingTask returns the migrating task by repo's id
171175
func GetMigratingTask(repoID int64) (*Task, error) {
172176
task := Task{

models/asymkey/error.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
package asymkey
66

7-
import "fmt"
7+
import (
8+
"fmt"
9+
10+
"code.gitea.io/gitea/modules/util"
11+
)
812

913
// ErrKeyUnableVerify represents a "KeyUnableVerify" kind of error.
1014
type ErrKeyUnableVerify struct {
@@ -36,6 +40,10 @@ func (err ErrKeyNotExist) Error() string {
3640
return fmt.Sprintf("public key does not exist [id: %d]", err.ID)
3741
}
3842

43+
func (err ErrKeyNotExist) Unwrap() error {
44+
return util.ErrNotExist
45+
}
46+
3947
// ErrKeyAlreadyExist represents a "KeyAlreadyExist" kind of error.
4048
type ErrKeyAlreadyExist struct {
4149
OwnerID int64
@@ -54,6 +62,10 @@ func (err ErrKeyAlreadyExist) Error() string {
5462
err.OwnerID, err.Fingerprint, err.Content)
5563
}
5664

65+
func (err ErrKeyAlreadyExist) Unwrap() error {
66+
return util.ErrAlreadyExist
67+
}
68+
5769
// ErrKeyNameAlreadyUsed represents a "KeyNameAlreadyUsed" kind of error.
5870
type ErrKeyNameAlreadyUsed struct {
5971
OwnerID int64
@@ -70,6 +82,10 @@ func (err ErrKeyNameAlreadyUsed) Error() string {
7082
return fmt.Sprintf("public key already exists [owner_id: %d, name: %s]", err.OwnerID, err.Name)
7183
}
7284

85+
func (err ErrKeyNameAlreadyUsed) Unwrap() error {
86+
return util.ErrAlreadyExist
87+
}
88+
7389
// ErrGPGNoEmailFound represents a "ErrGPGNoEmailFound" kind of error.
7490
type ErrGPGNoEmailFound struct {
7591
FailedEmails []string
@@ -132,6 +148,10 @@ func (err ErrGPGKeyNotExist) Error() string {
132148
return fmt.Sprintf("public gpg key does not exist [id: %d]", err.ID)
133149
}
134150

151+
func (err ErrGPGKeyNotExist) Unwrap() error {
152+
return util.ErrNotExist
153+
}
154+
135155
// ErrGPGKeyImportNotExist represents a "GPGKeyImportNotExist" kind of error.
136156
type ErrGPGKeyImportNotExist struct {
137157
ID string
@@ -147,6 +167,10 @@ func (err ErrGPGKeyImportNotExist) Error() string {
147167
return fmt.Sprintf("public gpg key import does not exist [id: %s]", err.ID)
148168
}
149169

170+
func (err ErrGPGKeyImportNotExist) Unwrap() error {
171+
return util.ErrNotExist
172+
}
173+
150174
// ErrGPGKeyIDAlreadyUsed represents a "GPGKeyIDAlreadyUsed" kind of error.
151175
type ErrGPGKeyIDAlreadyUsed struct {
152176
KeyID string
@@ -162,6 +186,10 @@ func (err ErrGPGKeyIDAlreadyUsed) Error() string {
162186
return fmt.Sprintf("public key already exists [key_id: %s]", err.KeyID)
163187
}
164188

189+
func (err ErrGPGKeyIDAlreadyUsed) Unwrap() error {
190+
return util.ErrAlreadyExist
191+
}
192+
165193
// ErrGPGKeyAccessDenied represents a "GPGKeyAccessDenied" kind of Error.
166194
type ErrGPGKeyAccessDenied struct {
167195
UserID int64
@@ -180,6 +208,10 @@ func (err ErrGPGKeyAccessDenied) Error() string {
180208
err.UserID, err.KeyID)
181209
}
182210

211+
func (err ErrGPGKeyAccessDenied) Unwrap() error {
212+
return util.ErrPermissionDenied
213+
}
214+
183215
// ErrKeyAccessDenied represents a "KeyAccessDenied" kind of error.
184216
type ErrKeyAccessDenied struct {
185217
UserID int64
@@ -198,6 +230,10 @@ func (err ErrKeyAccessDenied) Error() string {
198230
err.UserID, err.KeyID, err.Note)
199231
}
200232

233+
func (err ErrKeyAccessDenied) Unwrap() error {
234+
return util.ErrPermissionDenied
235+
}
236+
201237
// ErrDeployKeyNotExist represents a "DeployKeyNotExist" kind of error.
202238
type ErrDeployKeyNotExist struct {
203239
ID int64
@@ -215,6 +251,10 @@ func (err ErrDeployKeyNotExist) Error() string {
215251
return fmt.Sprintf("Deploy key does not exist [id: %d, key_id: %d, repo_id: %d]", err.ID, err.KeyID, err.RepoID)
216252
}
217253

254+
func (err ErrDeployKeyNotExist) Unwrap() error {
255+
return util.ErrNotExist
256+
}
257+
218258
// ErrDeployKeyAlreadyExist represents a "DeployKeyAlreadyExist" kind of error.
219259
type ErrDeployKeyAlreadyExist struct {
220260
KeyID int64
@@ -231,6 +271,10 @@ func (err ErrDeployKeyAlreadyExist) Error() string {
231271
return fmt.Sprintf("public key already exists [key_id: %d, repo_id: %d]", err.KeyID, err.RepoID)
232272
}
233273

274+
func (err ErrDeployKeyAlreadyExist) Unwrap() error {
275+
return util.ErrAlreadyExist
276+
}
277+
234278
// ErrDeployKeyNameAlreadyUsed represents a "DeployKeyNameAlreadyUsed" kind of error.
235279
type ErrDeployKeyNameAlreadyUsed struct {
236280
RepoID int64
@@ -247,6 +291,10 @@ func (err ErrDeployKeyNameAlreadyUsed) Error() string {
247291
return fmt.Sprintf("public key with name already exists [repo_id: %d, name: %s]", err.RepoID, err.Name)
248292
}
249293

294+
func (err ErrDeployKeyNameAlreadyUsed) Unwrap() error {
295+
return util.ErrNotExist
296+
}
297+
250298
// ErrSSHInvalidTokenSignature represents a "ErrSSHInvalidTokenSignature" kind of error.
251299
type ErrSSHInvalidTokenSignature struct {
252300
Wrapped error
@@ -262,3 +310,7 @@ func IsErrSSHInvalidTokenSignature(err error) bool {
262310
func (err ErrSSHInvalidTokenSignature) Error() string {
263311
return "the provided signature does not sign the token with the provided key"
264312
}
313+
314+
func (err ErrSSHInvalidTokenSignature) Unwrap() error {
315+
return util.ErrInvalidArgument
316+
}

models/auth/oauth2.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ type ErrOAuthClientIDInvalid struct {
486486
ClientID string
487487
}
488488

489-
// IsErrOauthClientIDInvalid checks if an error is a ErrReviewNotExist.
489+
// IsErrOauthClientIDInvalid checks if an error is a ErrOAuthClientIDInvalid.
490490
func IsErrOauthClientIDInvalid(err error) bool {
491491
_, ok := err.(ErrOAuthClientIDInvalid)
492492
return ok
@@ -497,6 +497,11 @@ func (err ErrOAuthClientIDInvalid) Error() string {
497497
return fmt.Sprintf("Client ID invalid [Client ID: %s]", err.ClientID)
498498
}
499499

500+
// Unwrap unwraps this as a ErrNotExist err
501+
func (err ErrOAuthClientIDInvalid) Unwrap() error {
502+
return util.ErrNotExist
503+
}
504+
500505
// ErrOAuthApplicationNotFound will be thrown if id cannot be found
501506
type ErrOAuthApplicationNotFound struct {
502507
ID int64
@@ -513,6 +518,11 @@ func (err ErrOAuthApplicationNotFound) Error() string {
513518
return fmt.Sprintf("OAuth application not found [ID: %d]", err.ID)
514519
}
515520

521+
// Unwrap unwraps this as a ErrNotExist err
522+
func (err ErrOAuthApplicationNotFound) Unwrap() error {
523+
return util.ErrNotExist
524+
}
525+
516526
// GetActiveOAuth2ProviderSources returns all actived LoginOAuth2 sources
517527
func GetActiveOAuth2ProviderSources() ([]*Source, error) {
518528
sources := make([]*Source, 0, 1)

models/auth/source.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/models/db"
1313
"code.gitea.io/gitea/modules/log"
1414
"code.gitea.io/gitea/modules/timeutil"
15+
"code.gitea.io/gitea/modules/util"
1516

1617
"xorm.io/xorm"
1718
"xorm.io/xorm/convert"
@@ -366,6 +367,11 @@ func (err ErrSourceNotExist) Error() string {
366367
return fmt.Sprintf("login source does not exist [id: %d]", err.ID)
367368
}
368369

370+
// Unwrap unwraps this as a ErrNotExist err
371+
func (err ErrSourceNotExist) Unwrap() error {
372+
return util.ErrNotExist
373+
}
374+
369375
// ErrSourceAlreadyExist represents a "SourceAlreadyExist" kind of error.
370376
type ErrSourceAlreadyExist struct {
371377
Name string
@@ -381,6 +387,11 @@ func (err ErrSourceAlreadyExist) Error() string {
381387
return fmt.Sprintf("login source already exists [name: %s]", err.Name)
382388
}
383389

390+
// Unwrap unwraps this as a ErrExist err
391+
func (err ErrSourceAlreadyExist) Unwrap() error {
392+
return util.ErrAlreadyExist
393+
}
394+
384395
// ErrSourceInUse represents a "SourceInUse" kind of error.
385396
type ErrSourceInUse struct {
386397
ID int64

models/auth/token.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ func (err ErrAccessTokenNotExist) Error() string {
3535
return fmt.Sprintf("access token does not exist [sha: %s]", err.Token)
3636
}
3737

38+
func (err ErrAccessTokenNotExist) Unwrap() error {
39+
return util.ErrNotExist
40+
}
41+
3842
// ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error.
3943
type ErrAccessTokenEmpty struct{}
4044

@@ -48,6 +52,10 @@ func (err ErrAccessTokenEmpty) Error() string {
4852
return "access token is empty"
4953
}
5054

55+
func (err ErrAccessTokenEmpty) Unwrap() error {
56+
return util.ErrInvalidArgument
57+
}
58+
5159
var successfulAccessTokenCache *lru.Cache
5260

5361
// AccessToken represents a personal access token.

models/auth/twofactor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ func (err ErrTwoFactorNotEnrolled) Error() string {
4141
return fmt.Sprintf("user not enrolled in 2FA [uid: %d]", err.UID)
4242
}
4343

44+
// Unwrap unwraps this as a ErrNotExist err
45+
func (err ErrTwoFactorNotEnrolled) Unwrap() error {
46+
return util.ErrNotExist
47+
}
48+
4449
// TwoFactor represents a two-factor authentication token.
4550
type TwoFactor struct {
4651
ID int64 `xorm:"pk autoincr"`

models/auth/webauthn.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"code.gitea.io/gitea/models/db"
1313
"code.gitea.io/gitea/modules/timeutil"
14+
"code.gitea.io/gitea/modules/util"
1415

1516
"github.com/duo-labs/webauthn/webauthn"
1617
"xorm.io/xorm"
@@ -29,6 +30,11 @@ func (err ErrWebAuthnCredentialNotExist) Error() string {
2930
return fmt.Sprintf("WebAuthn credential does not exist [credential_id: %x]", err.CredentialID)
3031
}
3132

33+
// Unwrap unwraps this as a ErrNotExist err
34+
func (err ErrWebAuthnCredentialNotExist) Unwrap() error {
35+
return util.ErrNotExist
36+
}
37+
3238
// IsErrWebAuthnCredentialNotExist checks if an error is a ErrWebAuthnCredentialNotExist.
3339
func IsErrWebAuthnCredentialNotExist(err error) bool {
3440
_, ok := err.(ErrWebAuthnCredentialNotExist)

models/db/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func NamesToBean(names ...string) ([]interface{}, error) {
225225
for _, name := range names {
226226
bean, ok := beanMap[strings.ToLower(strings.TrimSpace(name))]
227227
if !ok {
228-
return nil, fmt.Errorf("No table found that matches: %s", name)
228+
return nil, fmt.Errorf("no table found that matches: %s", name)
229229
}
230230
if !gotBean[bean] {
231231
beans = append(beans, bean)

0 commit comments

Comments
 (0)