mirror of
https://github.com/gogs/gogs.git
synced 2025-04-27 13:13:10 +00:00
Merge 913c14384520ce5e71f65c29860c998be07f5753 into 4acaaac85aca427771030ab2e9a1465e9517ba1d
This commit is contained in:
commit
074ba82114
@ -25,6 +25,8 @@ var (
|
|||||||
to make automatic initialization process more smoothly`,
|
to make automatic initialization process more smoothly`,
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
subcmdCreateUser,
|
subcmdCreateUser,
|
||||||
|
subcmdCreateRepo,
|
||||||
|
|
||||||
subcmdDeleteInactivateUsers,
|
subcmdDeleteInactivateUsers,
|
||||||
subcmdDeleteRepositoryArchives,
|
subcmdDeleteRepositoryArchives,
|
||||||
subcmdDeleteMissingRepositories,
|
subcmdDeleteMissingRepositories,
|
||||||
@ -47,6 +49,20 @@ to make automatic initialization process more smoothly`,
|
|||||||
stringFlag("config, c", "", "Custom configuration file path"),
|
stringFlag("config, c", "", "Custom configuration file path"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
subcmdCreateRepo = cli.Command{
|
||||||
|
Name: "create-repository",
|
||||||
|
Usage: "Create a new repo in database for a user",
|
||||||
|
Action: runCreateRepo,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
stringFlag("username", "", "Username of repository's owner"),
|
||||||
|
stringFlag("repository_name", "", "Repository name"),
|
||||||
|
stringFlag("private", "false", "Private repository"),
|
||||||
|
stringFlag("unlisted", "false", "Listable repository"),
|
||||||
|
stringFlag("mirror", "false", "Whether the repository is a mirror"),
|
||||||
|
|
||||||
|
stringFlag("config, c", "", "Custom configuration file path"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
subcmdDeleteInactivateUsers = cli.Command{
|
subcmdDeleteInactivateUsers = cli.Command{
|
||||||
Name: "delete-inactive-users",
|
Name: "delete-inactive-users",
|
||||||
@ -170,6 +186,50 @@ func runCreateUser(c *cli.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runCreateRepo(c *cli.Context) error {
|
||||||
|
if !c.IsSet("username") {
|
||||||
|
return errors.New("Username is not specified")
|
||||||
|
} else if !c.IsSet("repository_name") {
|
||||||
|
return errors.New("Respository name is not specified")
|
||||||
|
}
|
||||||
|
|
||||||
|
err := conf.Init(c.String("config"))
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "init configuration")
|
||||||
|
}
|
||||||
|
conf.InitLogging(true)
|
||||||
|
|
||||||
|
if _, err = db.SetEngine(); err != nil {
|
||||||
|
return errors.Wrap(err, "set engine")
|
||||||
|
}
|
||||||
|
// find user by username
|
||||||
|
user, err := db.Users.GetByUsername(
|
||||||
|
context.Background(),
|
||||||
|
c.String("username"),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "No user was found with "+c.String("username"))
|
||||||
|
}
|
||||||
|
|
||||||
|
repo, err := db.CreateRepository(
|
||||||
|
user,
|
||||||
|
user,
|
||||||
|
db.CreateRepoOptionsLegacy{
|
||||||
|
Name: c.String("repository_name"),
|
||||||
|
Description: "",
|
||||||
|
IsPrivate: c.Bool("private") || conf.Repository.ForcePrivate,
|
||||||
|
IsUnlisted: c.Bool("unlisted"),
|
||||||
|
IsMirror: c.Bool("mirror"),
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Repo")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("New repository %q has been successfully created!\n", repo.Name)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func adminDashboardOperation(operation func() error, successMessage string) func(*cli.Context) error {
|
func adminDashboardOperation(operation func() error, successMessage string) func(*cli.Context) error {
|
||||||
return func(c *cli.Context) error {
|
return func(c *cli.Context) error {
|
||||||
err := conf.Init(c.String("config"))
|
err := conf.Init(c.String("config"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user