mirror of https://github.com/gogs/gogs.git
Merge 913c143845
into 4acaaac85a
commit
074ba82114
|
@ -25,6 +25,8 @@ var (
|
|||
to make automatic initialization process more smoothly`,
|
||||
Subcommands: []cli.Command{
|
||||
subcmdCreateUser,
|
||||
subcmdCreateRepo,
|
||||
|
||||
subcmdDeleteInactivateUsers,
|
||||
subcmdDeleteRepositoryArchives,
|
||||
subcmdDeleteMissingRepositories,
|
||||
|
@ -47,6 +49,20 @@ to make automatic initialization process more smoothly`,
|
|||
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{
|
||||
Name: "delete-inactive-users",
|
||||
|
@ -170,6 +186,50 @@ func runCreateUser(c *cli.Context) error {
|
|||
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 {
|
||||
return func(c *cli.Context) error {
|
||||
err := conf.Init(c.String("config"))
|
||||
|
|
Loading…
Reference in New Issue