Skip to content

Commit 17d7023

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Fix pull requests API convert panic when head repository is deleted. (go-gitea#34685) [skip ci] Updated translations via Crowdin Hide href attribute of a tag if there is no target_url (go-gitea#34556) Fix commit message rendering and some UI problems (go-gitea#34680) Migrate to urfave v3 (go-gitea#34510)
2 parents 333545a + fbc3796 commit 17d7023

Some content is hidden

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

63 files changed

+2265
-1314
lines changed

assets/go-licenses.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/actions.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44
package cmd
55

66
import (
7+
"context"
78
"fmt"
89

910
"code.gitea.io/gitea/modules/private"
1011
"code.gitea.io/gitea/modules/setting"
1112

12-
"github.com/urfave/cli/v2"
13+
"github.com/urfave/cli/v3"
1314
)
1415

1516
var (
1617
// CmdActions represents the available actions sub-commands.
1718
CmdActions = &cli.Command{
1819
Name: "actions",
1920
Usage: "Manage Gitea Actions",
20-
Subcommands: []*cli.Command{
21+
Commands: []*cli.Command{
2122
subcmdActionsGenRunnerToken,
2223
},
2324
}
@@ -38,10 +39,7 @@ var (
3839
}
3940
)
4041

41-
func runGenerateActionsRunnerToken(c *cli.Context) error {
42-
ctx, cancel := installSignals()
43-
defer cancel()
44-
42+
func runGenerateActionsRunnerToken(ctx context.Context, c *cli.Command) error {
4543
setting.MustInstalled()
4644

4745
scope := c.String("scope")

cmd/admin.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import (
1515
"code.gitea.io/gitea/modules/log"
1616
repo_module "code.gitea.io/gitea/modules/repository"
1717

18-
"github.com/urfave/cli/v2"
18+
"github.com/urfave/cli/v3"
1919
)
2020

2121
var (
2222
// CmdAdmin represents the available admin sub-command.
2323
CmdAdmin = &cli.Command{
2424
Name: "admin",
2525
Usage: "Perform common administrative operations",
26-
Subcommands: []*cli.Command{
26+
Commands: []*cli.Command{
2727
subcmdUser,
2828
subcmdRepoSyncReleases,
2929
subcmdRegenerate,
@@ -41,7 +41,7 @@ var (
4141
subcmdRegenerate = &cli.Command{
4242
Name: "regenerate",
4343
Usage: "Regenerate specific files",
44-
Subcommands: []*cli.Command{
44+
Commands: []*cli.Command{
4545
microcmdRegenHooks,
4646
microcmdRegenKeys,
4747
},
@@ -50,15 +50,15 @@ var (
5050
subcmdAuth = &cli.Command{
5151
Name: "auth",
5252
Usage: "Modify external auth providers",
53-
Subcommands: []*cli.Command{
54-
microcmdAuthAddOauth,
55-
microcmdAuthUpdateOauth,
56-
microcmdAuthAddLdapBindDn,
57-
microcmdAuthUpdateLdapBindDn,
58-
microcmdAuthAddLdapSimpleAuth,
59-
microcmdAuthUpdateLdapSimpleAuth,
60-
microcmdAuthAddSMTP,
61-
microcmdAuthUpdateSMTP,
53+
Commands: []*cli.Command{
54+
microcmdAuthAddOauth(),
55+
microcmdAuthUpdateOauth(),
56+
microcmdAuthAddLdapBindDn(),
57+
microcmdAuthUpdateLdapBindDn(),
58+
microcmdAuthAddLdapSimpleAuth(),
59+
microcmdAuthUpdateLdapSimpleAuth(),
60+
microcmdAuthAddSMTP(),
61+
microcmdAuthUpdateSMTP(),
6262
microcmdAuthList,
6363
microcmdAuthDelete,
6464
},
@@ -70,9 +70,9 @@ var (
7070
Action: runSendMail,
7171
Flags: []cli.Flag{
7272
&cli.StringFlag{
73-
Name: "title",
74-
Usage: `a title of a message`,
75-
Value: "",
73+
Name: "title",
74+
Usage: "a title of a message",
75+
Required: true,
7676
},
7777
&cli.StringFlag{
7878
Name: "content",
@@ -86,17 +86,16 @@ var (
8686
},
8787
},
8888
}
89+
)
8990

90-
idFlag = &cli.Int64Flag{
91+
func idFlag() *cli.Int64Flag {
92+
return &cli.Int64Flag{
9193
Name: "id",
9294
Usage: "ID of authentication source",
9395
}
94-
)
95-
96-
func runRepoSyncReleases(_ *cli.Context) error {
97-
ctx, cancel := installSignals()
98-
defer cancel()
96+
}
9997

98+
func runRepoSyncReleases(ctx context.Context, _ *cli.Command) error {
10099
if err := initDB(ctx); err != nil {
101100
return err
102101
}

cmd/admin_auth.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package cmd
55

66
import (
7+
"context"
78
"errors"
89
"fmt"
910
"os"
@@ -13,14 +14,14 @@ import (
1314
"code.gitea.io/gitea/models/db"
1415
auth_service "code.gitea.io/gitea/services/auth"
1516

16-
"github.com/urfave/cli/v2"
17+
"github.com/urfave/cli/v3"
1718
)
1819

1920
var (
2021
microcmdAuthDelete = &cli.Command{
2122
Name: "delete",
2223
Usage: "Delete specific auth source",
23-
Flags: []cli.Flag{idFlag},
24+
Flags: []cli.Flag{idFlag()},
2425
Action: runDeleteAuth,
2526
}
2627
microcmdAuthList = &cli.Command{
@@ -56,10 +57,7 @@ var (
5657
}
5758
)
5859

59-
func runListAuth(c *cli.Context) error {
60-
ctx, cancel := installSignals()
61-
defer cancel()
62-
60+
func runListAuth(ctx context.Context, c *cli.Command) error {
6361
if err := initDB(ctx); err != nil {
6462
return err
6563
}
@@ -90,14 +88,11 @@ func runListAuth(c *cli.Context) error {
9088
return nil
9189
}
9290

93-
func runDeleteAuth(c *cli.Context) error {
91+
func runDeleteAuth(ctx context.Context, c *cli.Command) error {
9492
if !c.IsSet("id") {
9593
return errors.New("--id flag is missing")
9694
}
9795

98-
ctx, cancel := installSignals()
99-
defer cancel()
100-
10196
if err := initDB(ctx); err != nil {
10297
return err
10398
}

cmd/admin_auth_ldap.go

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"code.gitea.io/gitea/modules/util"
1313
"code.gitea.io/gitea/services/auth/source/ldap"
1414

15-
"github.com/urfave/cli/v2"
15+
"github.com/urfave/cli/v3"
1616
)
1717

1818
type (
@@ -24,8 +24,8 @@ type (
2424
}
2525
)
2626

27-
var (
28-
commonLdapCLIFlags = []cli.Flag{
27+
func commonLdapCLIFlags() []cli.Flag {
28+
return []cli.Flag{
2929
&cli.StringFlag{
3030
Name: "name",
3131
Usage: "Authentication name.",
@@ -103,8 +103,10 @@ var (
103103
Usage: "The attribute of the user’s LDAP record containing the user’s avatar.",
104104
},
105105
}
106+
}
106107

107-
ldapBindDnCLIFlags = append(commonLdapCLIFlags,
108+
func ldapBindDnCLIFlags() []cli.Flag {
109+
return append(commonLdapCLIFlags(),
108110
&cli.StringFlag{
109111
Name: "bind-dn",
110112
Usage: "The DN to bind to the LDAP server with when searching for the user.",
@@ -157,49 +159,59 @@ var (
157159
Name: "group-team-map-removal",
158160
Usage: "Remove users from synchronized teams if user does not belong to corresponding LDAP group",
159161
})
162+
}
160163

161-
ldapSimpleAuthCLIFlags = append(commonLdapCLIFlags,
164+
func ldapSimpleAuthCLIFlags() []cli.Flag {
165+
return append(commonLdapCLIFlags(),
162166
&cli.StringFlag{
163167
Name: "user-dn",
164168
Usage: "The user's DN.",
165169
})
170+
}
166171

167-
microcmdAuthAddLdapBindDn = &cli.Command{
172+
func microcmdAuthAddLdapBindDn() *cli.Command {
173+
return &cli.Command{
168174
Name: "add-ldap",
169175
Usage: "Add new LDAP (via Bind DN) authentication source",
170-
Action: func(c *cli.Context) error {
171-
return newAuthService().addLdapBindDn(c)
176+
Action: func(ctx context.Context, cmd *cli.Command) error {
177+
return newAuthService().addLdapBindDn(ctx, cmd)
172178
},
173-
Flags: ldapBindDnCLIFlags,
179+
Flags: ldapBindDnCLIFlags(),
174180
}
181+
}
175182

176-
microcmdAuthUpdateLdapBindDn = &cli.Command{
183+
func microcmdAuthUpdateLdapBindDn() *cli.Command {
184+
return &cli.Command{
177185
Name: "update-ldap",
178186
Usage: "Update existing LDAP (via Bind DN) authentication source",
179-
Action: func(c *cli.Context) error {
180-
return newAuthService().updateLdapBindDn(c)
187+
Action: func(ctx context.Context, cmd *cli.Command) error {
188+
return newAuthService().updateLdapBindDn(ctx, cmd)
181189
},
182-
Flags: append([]cli.Flag{idFlag}, ldapBindDnCLIFlags...),
190+
Flags: append([]cli.Flag{idFlag()}, ldapBindDnCLIFlags()...),
183191
}
192+
}
184193

185-
microcmdAuthAddLdapSimpleAuth = &cli.Command{
194+
func microcmdAuthAddLdapSimpleAuth() *cli.Command {
195+
return &cli.Command{
186196
Name: "add-ldap-simple",
187197
Usage: "Add new LDAP (simple auth) authentication source",
188-
Action: func(c *cli.Context) error {
189-
return newAuthService().addLdapSimpleAuth(c)
198+
Action: func(ctx context.Context, cmd *cli.Command) error {
199+
return newAuthService().addLdapSimpleAuth(ctx, cmd)
190200
},
191-
Flags: ldapSimpleAuthCLIFlags,
201+
Flags: ldapSimpleAuthCLIFlags(),
192202
}
203+
}
193204

194-
microcmdAuthUpdateLdapSimpleAuth = &cli.Command{
205+
func microcmdAuthUpdateLdapSimpleAuth() *cli.Command {
206+
return &cli.Command{
195207
Name: "update-ldap-simple",
196208
Usage: "Update existing LDAP (simple auth) authentication source",
197-
Action: func(c *cli.Context) error {
198-
return newAuthService().updateLdapSimpleAuth(c)
209+
Action: func(ctx context.Context, cmd *cli.Command) error {
210+
return newAuthService().updateLdapSimpleAuth(ctx, cmd)
199211
},
200-
Flags: append([]cli.Flag{idFlag}, ldapSimpleAuthCLIFlags...),
212+
Flags: append([]cli.Flag{idFlag()}, ldapSimpleAuthCLIFlags()...),
201213
}
202-
)
214+
}
203215

204216
// newAuthService creates a service with default functions.
205217
func newAuthService() *authService {
@@ -212,7 +224,7 @@ func newAuthService() *authService {
212224
}
213225

214226
// parseAuthSourceLdap assigns values on authSource according to command line flags.
215-
func parseAuthSourceLdap(c *cli.Context, authSource *auth.Source) {
227+
func parseAuthSourceLdap(c *cli.Command, authSource *auth.Source) {
216228
if c.IsSet("name") {
217229
authSource.Name = c.String("name")
218230
}
@@ -232,7 +244,7 @@ func parseAuthSourceLdap(c *cli.Context, authSource *auth.Source) {
232244
}
233245

234246
// parseLdapConfig assigns values on config according to command line flags.
235-
func parseLdapConfig(c *cli.Context, config *ldap.Source) error {
247+
func parseLdapConfig(c *cli.Command, config *ldap.Source) error {
236248
if c.IsSet("name") {
237249
config.Name = c.String("name")
238250
}
@@ -245,7 +257,7 @@ func parseLdapConfig(c *cli.Context, config *ldap.Source) error {
245257
if c.IsSet("security-protocol") {
246258
p, ok := findLdapSecurityProtocolByName(c.String("security-protocol"))
247259
if !ok {
248-
return fmt.Errorf("Unknown security protocol name: %s", c.String("security-protocol"))
260+
return fmt.Errorf("unknown security protocol name: %s", c.String("security-protocol"))
249261
}
250262
config.SecurityProtocol = p
251263
}
@@ -337,32 +349,27 @@ func findLdapSecurityProtocolByName(name string) (ldap.SecurityProtocol, bool) {
337349

338350
// getAuthSource gets the login source by its id defined in the command line flags.
339351
// It returns an error if the id is not set, does not match any source or if the source is not of expected type.
340-
func (a *authService) getAuthSource(ctx context.Context, c *cli.Context, authType auth.Type) (*auth.Source, error) {
352+
func (a *authService) getAuthSource(ctx context.Context, c *cli.Command, authType auth.Type) (*auth.Source, error) {
341353
if err := argsSet(c, "id"); err != nil {
342354
return nil, err
343355
}
344-
345356
authSource, err := a.getAuthSourceByID(ctx, c.Int64("id"))
346357
if err != nil {
347358
return nil, err
348359
}
349360

350361
if authSource.Type != authType {
351-
return nil, fmt.Errorf("Invalid authentication type. expected: %s, actual: %s", authType.String(), authSource.Type.String())
362+
return nil, fmt.Errorf("invalid authentication type. expected: %s, actual: %s", authType.String(), authSource.Type.String())
352363
}
353364

354365
return authSource, nil
355366
}
356367

357368
// addLdapBindDn adds a new LDAP via Bind DN authentication source.
358-
func (a *authService) addLdapBindDn(c *cli.Context) error {
369+
func (a *authService) addLdapBindDn(ctx context.Context, c *cli.Command) error {
359370
if err := argsSet(c, "name", "security-protocol", "host", "port", "user-search-base", "user-filter", "email-attribute"); err != nil {
360371
return err
361372
}
362-
363-
ctx, cancel := installSignals()
364-
defer cancel()
365-
366373
if err := a.initDB(ctx); err != nil {
367374
return err
368375
}
@@ -384,10 +391,7 @@ func (a *authService) addLdapBindDn(c *cli.Context) error {
384391
}
385392

386393
// updateLdapBindDn updates a new LDAP via Bind DN authentication source.
387-
func (a *authService) updateLdapBindDn(c *cli.Context) error {
388-
ctx, cancel := installSignals()
389-
defer cancel()
390-
394+
func (a *authService) updateLdapBindDn(ctx context.Context, c *cli.Command) error {
391395
if err := a.initDB(ctx); err != nil {
392396
return err
393397
}
@@ -406,14 +410,11 @@ func (a *authService) updateLdapBindDn(c *cli.Context) error {
406410
}
407411

408412
// addLdapSimpleAuth adds a new LDAP (simple auth) authentication source.
409-
func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
413+
func (a *authService) addLdapSimpleAuth(ctx context.Context, c *cli.Command) error {
410414
if err := argsSet(c, "name", "security-protocol", "host", "port", "user-dn", "user-filter", "email-attribute"); err != nil {
411415
return err
412416
}
413417

414-
ctx, cancel := installSignals()
415-
defer cancel()
416-
417418
if err := a.initDB(ctx); err != nil {
418419
return err
419420
}
@@ -435,10 +436,7 @@ func (a *authService) addLdapSimpleAuth(c *cli.Context) error {
435436
}
436437

437438
// updateLdapSimpleAuth updates a new LDAP (simple auth) authentication source.
438-
func (a *authService) updateLdapSimpleAuth(c *cli.Context) error {
439-
ctx, cancel := installSignals()
440-
defer cancel()
441-
439+
func (a *authService) updateLdapSimpleAuth(ctx context.Context, c *cli.Command) error {
442440
if err := a.initDB(ctx); err != nil {
443441
return err
444442
}

0 commit comments

Comments
 (0)