Skip to content

Commit 6cd8019

Browse files
committed
Merge remote-tracking branch 'giteaoffical/main'
* giteaoffical/main: (22 commits) Add MP4 as default allowed attachment type (go-gitea#18170) [skip ci] Updated translations via Crowdin Include folders into size cost (go-gitea#18158) Don't delete branch if other PRs with this branch are open (go-gitea#18164) Remove unused route "/tasks/trigger" (go-gitea#18160) Fix EasyMDE validation (go-gitea#18161) Fix bug (go-gitea#18168) tests: add coverage for models migration helpers (go-gitea#18162) [skip ci] Updated translations via Crowdin Require codereview to have content (go-gitea#18156) chore(lint): use golangci-lint to call revive and misspell checker. (go-gitea#18145) Update owners for 2022 (go-gitea#18155) Refactor auth package (go-gitea#17962) Unify and simplify TrN for i18n (go-gitea#18141) Use correct user when determining max repo limits for error messages (go-gitea#18153) Add singuliere to MAINTAINERS (go-gitea#18148) [skip ci] Updated licenses and gitignores Add API to get issue/pull comments and events (timeline) (go-gitea#17403) Upgrade certmagic from v0.14.1 to v0.15.2 (go-gitea#18138) Upgrade certmagic from v0.14.1 to v0.15.2 (go-gitea#18138) ...
2 parents 739d84c + 165346c commit 6cd8019

File tree

234 files changed

+5744
-3861
lines changed

Some content is hidden

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

234 files changed

+5744
-3861
lines changed

.golangci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ linters:
1616
- gocritic
1717
- bidichk
1818
- ineffassign
19+
- revive
1920
enable-all: false
2021
disable-all: true
2122
fast: false
@@ -28,6 +29,34 @@ linters-settings:
2829
disabled-checks:
2930
- ifElseChain
3031
- singleCaseSwitch # Every time this occurred in the code, there was no other way.
32+
revive:
33+
ignore-generated-header: false
34+
severity: warning
35+
confidence: 0.8
36+
errorCode: 1
37+
warningCode: 1
38+
rules:
39+
- name: blank-imports
40+
- name: context-as-argument
41+
- name: context-keys-type
42+
- name: dot-imports
43+
- name: error-return
44+
- name: error-strings
45+
- name: error-naming
46+
- name: exported
47+
- name: if-return
48+
- name: increment-decrement
49+
- name: var-naming
50+
- name: var-declaration
51+
- name: package-comments
52+
- name: range
53+
- name: receiver-naming
54+
- name: time-naming
55+
- name: unexported-return
56+
- name: indent-error-flow
57+
- name: errorf
58+
- name: duplicated-imports
59+
- name: modifies-value-receiver
3160

3261
issues:
3362
exclude-rules:

.revive.toml

Lines changed: 0 additions & 27 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ and lead the development of Gitea.
299299
To honor the past owners, here's the history of the owners and the time
300300
they served:
301301

302+
* 2022-01-01 ~ 2022-12-31 - https://github.com/go-gitea/gitea/issues/17872
303+
* [Lunny Xiao](https://gitea.com/lunny) <xiaolunwen@gmail.com>
304+
* [Matti Ranta](https://gitea.com/techknowlogick) <techknowlogick@gitea.io>
305+
* [Andrew Thornton](https://gitea.com/zeripath) <art27@cantab.net>
306+
302307
* 2021-01-01 ~ 2021-12-31 - https://github.com/go-gitea/gitea/issues/13801
303308
* [Lunny Xiao](https://gitea.com/lunny) <xiaolunwen@gmail.com>
304309
* [Lauris Bukšis-Haberkorns](https://gitea.com/lafriks) <lauris@nix.lv>

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,4 @@ Steven Kriegler <sk.bunsenbrenner@gmail.com> (@justusbunsi)
4545
Jimmy Praet <jimmy.praet@telenet.be> (@jpraet)
4646
Leon Hofmeister <dev.lh@web.de> (@delvh)
4747
Gusted <williamzijl7@hotmail.com) (@Gusted)
48+
singuliere <singuliere@autistici.org> (@singuliere)

Makefile

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ help:
186186
@echo " - generate-swagger generate the swagger spec from code comments"
187187
@echo " - swagger-validate check if the swagger spec is valid"
188188
@echo " - golangci-lint run golangci-lint linter"
189-
@echo " - revive run revive linter"
190-
@echo " - misspell check for misspellings"
191189
@echo " - vet examines Go source code and reports suspicious constructs"
192190
@echo " - test[\#TestSpecificName] run unit test"
193191
@echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite"
@@ -280,29 +278,6 @@ errcheck:
280278
@echo "Running errcheck..."
281279
@errcheck $(GO_PACKAGES)
282280

283-
.PHONY: revive
284-
revive:
285-
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
286-
$(GO) install github.com/mgechev/revive@v1.1.2; \
287-
fi
288-
@revive -config .revive.toml -exclude=./vendor/... ./...
289-
290-
.PHONY: misspell-check
291-
misspell-check:
292-
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
293-
$(GO) install github.com/client9/misspell/cmd/misspell@v0.3.4; \
294-
fi
295-
@echo "Running misspell-check..."
296-
@$(GO) run build/code-batch-process.go misspell -error -i unknwon '{file-list}'
297-
298-
.PHONY: misspell
299-
misspell:
300-
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
301-
$(GO) install github.com/client9/misspell/cmd/misspell@v0.3.4; \
302-
fi
303-
@echo "Running go misspell..."
304-
@$(GO) run build/code-batch-process.go misspell -w -i unknwon '{file-list}'
305-
306281
.PHONY: fmt-check
307282
fmt-check:
308283
# get all go files and run go fmt on them
@@ -320,7 +295,7 @@ checks: checks-frontend checks-backend
320295
checks-frontend: svg-check
321296

322297
.PHONY: checks-backend
323-
checks-backend: misspell-check test-vendor swagger-check swagger-validate
298+
checks-backend: test-vendor swagger-check swagger-validate
324299

325300
.PHONY: lint
326301
lint: lint-frontend lint-backend
@@ -332,7 +307,7 @@ lint-frontend: node_modules
332307
npx editorconfig-checker templates
333308

334309
.PHONY: lint-backend
335-
lint-backend: golangci-lint revive vet
310+
lint-backend: golangci-lint vet
336311

337312
.PHONY: watch
338313
watch:

cmd/admin.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515

1616
"code.gitea.io/gitea/models"
1717
asymkey_model "code.gitea.io/gitea/models/asymkey"
18+
"code.gitea.io/gitea/models/auth"
1819
"code.gitea.io/gitea/models/db"
19-
"code.gitea.io/gitea/models/login"
2020
user_model "code.gitea.io/gitea/models/user"
2121
"code.gitea.io/gitea/modules/git"
2222
"code.gitea.io/gitea/modules/graceful"
@@ -700,8 +700,8 @@ func runAddOauth(c *cli.Context) error {
700700
return err
701701
}
702702

703-
return login.CreateSource(&login.Source{
704-
Type: login.OAuth2,
703+
return auth.CreateSource(&auth.Source{
704+
Type: auth.OAuth2,
705705
Name: c.String("name"),
706706
IsActive: true,
707707
Cfg: parseOAuth2Config(c),
@@ -720,7 +720,7 @@ func runUpdateOauth(c *cli.Context) error {
720720
return err
721721
}
722722

723-
source, err := login.GetSourceByID(c.Int64("id"))
723+
source, err := auth.GetSourceByID(c.Int64("id"))
724724
if err != nil {
725725
return err
726726
}
@@ -801,7 +801,7 @@ func runUpdateOauth(c *cli.Context) error {
801801
oAuth2Config.CustomURLMapping = customURLMapping
802802
source.Cfg = oAuth2Config
803803

804-
return login.UpdateSource(source)
804+
return auth.UpdateSource(source)
805805
}
806806

807807
func runListAuth(c *cli.Context) error {
@@ -812,7 +812,7 @@ func runListAuth(c *cli.Context) error {
812812
return err
813813
}
814814

815-
loginSources, err := login.Sources()
815+
authSources, err := auth.Sources()
816816

817817
if err != nil {
818818
return err
@@ -831,7 +831,7 @@ func runListAuth(c *cli.Context) error {
831831
// loop through each source and print
832832
w := tabwriter.NewWriter(os.Stdout, c.Int("min-width"), c.Int("tab-width"), c.Int("padding"), padChar, flags)
833833
fmt.Fprintf(w, "ID\tName\tType\tEnabled\n")
834-
for _, source := range loginSources {
834+
for _, source := range authSources {
835835
fmt.Fprintf(w, "%d\t%s\t%s\t%t\n", source.ID, source.Name, source.Type.String(), source.IsActive)
836836
}
837837
w.Flush()
@@ -851,10 +851,10 @@ func runDeleteAuth(c *cli.Context) error {
851851
return err
852852
}
853853

854-
source, err := login.GetSourceByID(c.Int64("id"))
854+
source, err := auth.GetSourceByID(c.Int64("id"))
855855
if err != nil {
856856
return err
857857
}
858858

859-
return auth_service.DeleteLoginSource(source)
859+
return auth_service.DeleteSource(source)
860860
}

cmd/admin_auth_ldap.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ import (
99
"fmt"
1010
"strings"
1111

12-
"code.gitea.io/gitea/models/login"
12+
"code.gitea.io/gitea/models/auth"
1313
"code.gitea.io/gitea/services/auth/source/ldap"
1414

1515
"github.com/urfave/cli"
1616
)
1717

1818
type (
1919
authService struct {
20-
initDB func(ctx context.Context) error
21-
createLoginSource func(loginSource *login.Source) error
22-
updateLoginSource func(loginSource *login.Source) error
23-
getLoginSourceByID func(id int64) (*login.Source, error)
20+
initDB func(ctx context.Context) error
21+
createAuthSource func(*auth.Source) error
22+
updateAuthSource func(*auth.Source) error
23+
getAuthSourceByID func(id int64) (*auth.Source, error)
2424
}
2525
)
2626

@@ -168,23 +168,23 @@ var (
168168
// newAuthService creates a service with default functions.
169169
func newAuthService() *authService {
170170
return &authService{
171-
initDB: initDB,
172-
createLoginSource: login.CreateSource,
173-
updateLoginSource: login.UpdateSource,
174-
getLoginSourceByID: login.GetSourceByID,
171+
initDB: initDB,
172+
createAuthSource: auth.CreateSource,
173+
updateAuthSource: auth.UpdateSource,
174+
getAuthSourceByID: auth.GetSourceByID,
175175
}
176176
}
177177

178-
// parseLoginSource assigns values on loginSource according to command line flags.
179-
func parseLoginSource(c *cli.Context, loginSource *login.Source) {
178+
// parseAuthSource assigns values on authSource according to command line flags.
179+
func parseAuthSource(c *cli.Context, authSource *auth.Source) {
180180
if c.IsSet("name") {
181-
loginSource.Name = c.String("name")
181+
authSource.Name = c.String("name")
182182
}
183183
if c.IsSet("not-active") {
184-
loginSource.IsActive = !c.Bool("not-active")
184+
authSource.IsActive = !c.Bool("not-active")
185185
}
186186
if c.IsSet("synchronize-users") {
187-
loginSource.IsSyncEnabled = c.Bool("synchronize-users")
187+
authSource.IsSyncEnabled = c.Bool("synchronize-users")
188188
}
189189
}
190190

@@ -275,23 +275,23 @@ func findLdapSecurityProtocolByName(name string) (ldap.SecurityProtocol, bool) {
275275
return 0, false
276276
}
277277

278-
// getLoginSource gets the login source by its id defined in the command line flags.
278+
// getAuthSource gets the login source by its id defined in the command line flags.
279279
// It returns an error if the id is not set, does not match any source or if the source is not of expected type.
280-
func (a *authService) getLoginSource(c *cli.Context, loginType login.Type) (*login.Source, error) {
280+
func (a *authService) getAuthSource(c *cli.Context, authType auth.Type) (*auth.Source, error) {
281281
if err := argsSet(c, "id"); err != nil {
282282
return nil, err
283283
}
284284

285-
loginSource, err := a.getLoginSourceByID(c.Int64("id"))
285+
authSource, err := a.getAuthSourceByID(c.Int64("id"))
286286
if err != nil {
287287
return nil, err
288288
}
289289

290-
if loginSource.Type != loginType {
291-
return nil, fmt.Errorf("Invalid authentication type. expected: %s, actual: %s", loginType.String(), loginSource.Type.String())
290+
if authSource.Type != authType {
291+
return nil, fmt.Errorf("Invalid authentication type. expected: %s, actual: %s", authType.String(), authSource.Type.String())
292292
}
293293

294-
return loginSource, nil
294+
return authSource, nil
295295
}
296296

297297
// addLdapBindDn adds a new LDAP via Bind DN authentication source.
@@ -307,20 +307,20 @@ func (a *authService) addLdapBindDn(c *cli.Context) error {
307307
return err
308308
}
309309

310-
loginSource := &login.Source{
311-
Type: login.LDAP,
310+
authSource := &auth.Source{
311+
Type: auth.LDAP,
312312
IsActive: true, // active by default
313313
Cfg: &ldap.Source{
314314
Enabled: true, // always true
315315
},
316316
}
317317

318-
parseLoginSource(c, loginSource)
319-
if err := parseLdapConfig(c, loginSource.Cfg.(*ldap.Source)); err != nil {
318+
parseAuthSource(c, authSource)
319+
if err := parseLdapConfig(c, authSource.Cfg.(*ldap.Source)); err != nil {
320320
return err
321321
}
322322

323-
return a.createLoginSource(loginSource)
323+
return a.createAuthSource(authSource)
324324
}
325325

326326
// updateLdapBindDn updates a new LDAP via Bind DN authentication source.
@@ -332,17 +332,17 @@ func (a *authService) updateLdapBindDn(c *cli.Context) error {
332332
return err
333333
}
334334

335-
loginSource, err := a.getLoginSource(c, login.LDAP)
335+
authSource, err := a.getAuthSource(c, auth.LDAP)
336336
if err != nil {
337337
return err
338338
}
339339

340-
parseLoginSource(c, loginSource)
341-
if err := parseLdapConfig(c, loginSource.Cfg.(*ldap.Source)); err != nil {
340+
parseAuthSource(c, authSource)
341+
if err := parseLdapConfig(c, authSource.Cfg.(*ldap.Source)); err != nil {
342342
return err
343343
}
344344

345-
return a.updateLoginSource(loginSource)
345+
return a.updateAuthSource(authSource)
346346
}
347347

348348
// addLdapSimpleAuth adds a new LDAP (simple auth) authentication source.
@@ -358,20 +358,20 @@ func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
358358
return err
359359
}
360360

361-
loginSource := &login.Source{
362-
Type: login.DLDAP,
361+
authSource := &auth.Source{
362+
Type: auth.DLDAP,
363363
IsActive: true, // active by default
364364
Cfg: &ldap.Source{
365365
Enabled: true, // always true
366366
},
367367
}
368368

369-
parseLoginSource(c, loginSource)
370-
if err := parseLdapConfig(c, loginSource.Cfg.(*ldap.Source)); err != nil {
369+
parseAuthSource(c, authSource)
370+
if err := parseLdapConfig(c, authSource.Cfg.(*ldap.Source)); err != nil {
371371
return err
372372
}
373373

374-
return a.createLoginSource(loginSource)
374+
return a.createAuthSource(authSource)
375375
}
376376

377377
// updateLdapBindDn updates a new LDAP (simple auth) authentication source.
@@ -383,15 +383,15 @@ func (a *authService) updateLdapSimpleAuth(c *cli.Context) error {
383383
return err
384384
}
385385

386-
loginSource, err := a.getLoginSource(c, login.DLDAP)
386+
authSource, err := a.getAuthSource(c, auth.DLDAP)
387387
if err != nil {
388388
return err
389389
}
390390

391-
parseLoginSource(c, loginSource)
392-
if err := parseLdapConfig(c, loginSource.Cfg.(*ldap.Source)); err != nil {
391+
parseAuthSource(c, authSource)
392+
if err := parseLdapConfig(c, authSource.Cfg.(*ldap.Source)); err != nil {
393393
return err
394394
}
395395

396-
return a.updateLoginSource(loginSource)
396+
return a.updateAuthSource(authSource)
397397
}

0 commit comments

Comments
 (0)