From ac9a485ca22f5df3a0f1664415ebed5b1154c469 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Fri, 28 Apr 2017 00:40:15 +0300 Subject: [PATCH] Add reindex cli command --- cmd/admin.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cmd/admin.go b/cmd/admin.go index 02b192d5..0813eaf5 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -21,6 +21,7 @@ var ( to make automatic initialization process more smoothly`, Subcommands: []cli.Command{ subcmdCreateUser, + subcmdReindex, }, } @@ -36,6 +37,16 @@ to make automatic initialization process more smoothly`, stringFlag("config, c", "custom/conf/app.ini", "Custom configuration file path"), }, } + + subcmdReindex = cli.Command{ + Name: "reindex", + Usage: "Reindex repository", + Action: runReindex, + Flags: []cli.Flag{ + stringFlag("owner", "", "Repository owner"), + stringFlag("repo", "", "Repository name"), + }, + } ) func runCreateUser(c *cli.Context) error { @@ -68,3 +79,22 @@ func runCreateUser(c *cli.Context) error { fmt.Printf("New user '%s' has been successfully created!\n", c.String("name")) return nil } + +func runReindex(c *cli.Context) error { + if !c.IsSet("owner") { + return fmt.Errorf("Owner is not specified") + } else if !c.IsSet("repo") { + return fmt.Errorf("Repository is not specified") + } + + setting.NewContext() + models.LoadConfigs() + models.SetEngine() + + if err := models.ReindexCommits(c.String("owner"), c.String("repo")); err != nil { + return fmt.Errorf("ReindexRepository: %v", err) + } + + fmt.Printf("Repository %s/%s reindexed\n", c.String("owner"), c.String("repo")) + return nil +}