aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorSandro Santilli <strk@kbt.io>2017-12-31 15:45:46 +0100
committerLauris BH <lauris@nix.lv>2017-12-31 16:45:46 +0200
commit8cd987af0c4669623ec350a50096433583e74828 (patch)
treeb85b0a04803d8d15d4c42cab7e3e938733ff211f /cmd
parentae9cc8f972912678e59d840c38d31b2b4663b690 (diff)
downloadgitea-8cd987af0c4669623ec350a50096433583e74828.tar.gz
gitea-8cd987af0c4669623ec350a50096433583e74828.zip
Add repo-sync-releases admin command (#3254)
* Add repo-sync-releases admin command Will help recovering corrupted database, see #3247 * Load repos in chunks of 10, exit with error if unable to get a list, scan private repos, fix typo * Fix debug output about num releases * Introduce RepositoryListDefaultPageSize constant, set to 64 Use it from the new admin command * Use RepositoryListDefaultPageSize in more places * Document RepositoryListDefaultPageSize
Diffstat (limited to 'cmd')
-rw-r--r--cmd/admin.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/cmd/admin.go b/cmd/admin.go
index 928bc1ebba..4df28358a2 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -8,7 +8,9 @@ package cmd
import (
"fmt"
+ "code.gitea.io/git"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"github.com/urfave/cli"
@@ -24,6 +26,7 @@ to make automatic initialization process more smoothly`,
Subcommands: []cli.Command{
subcmdCreateUser,
subcmdChangePassword,
+ subcmdRepoSyncReleases,
},
}
@@ -76,6 +79,12 @@ to make automatic initialization process more smoothly`,
},
},
}
+
+ subcmdRepoSyncReleases = cli.Command{
+ Name: "repo-sync-releases",
+ Usage: "Synchronize repository releases with tags",
+ Action: runRepoSyncReleases,
+ }
)
func runChangePassword(c *cli.Context) error {
@@ -145,3 +154,69 @@ func runCreateUser(c *cli.Context) error {
fmt.Printf("New user '%s' has been successfully created!\n", c.String("name"))
return nil
}
+
+func runRepoSyncReleases(c *cli.Context) error {
+
+ setting.NewContext()
+ models.LoadConfigs()
+
+ setting.NewXORMLogService(false)
+ if err := models.SetEngine(); err != nil {
+ return fmt.Errorf("models.SetEngine: %v", err)
+ }
+
+ log.Trace("Synchronizing repository releases (this may take a while)")
+ for page := 1; ; page++ {
+ repos, count, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
+ Page: page,
+ PageSize: models.RepositoryListDefaultPageSize,
+ Private: true,
+ })
+ if err != nil {
+ log.Fatal(4, "SearchRepositoryByName: %v", err)
+ return err
+ }
+ if len(repos) == 0 {
+ break
+ }
+ log.Trace("Processing next %d repos of %d", len(repos), count)
+ for _, repo := range repos {
+ log.Trace("Synchronizing repo %s with path %s", repo.FullName(), repo.RepoPath())
+ gitRepo, err := git.OpenRepository(repo.RepoPath())
+ if err != nil {
+ log.Warn("OpenRepository: %v", err)
+ continue
+ }
+
+ oldnum, err := models.GetReleaseCountByRepoID(repo.ID,
+ models.FindReleasesOptions{
+ IncludeDrafts: false,
+ IncludeTags: true,
+ })
+ if err != nil {
+ log.Warn(" GetReleaseCountByRepoID: %v", err)
+ }
+ log.Trace(" currentNumReleases is %d, running SyncReleasesWithTags", oldnum)
+
+ if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil {
+ log.Warn(" SyncReleasesWithTags: %v", err)
+ continue
+ }
+
+ count, err = models.GetReleaseCountByRepoID(repo.ID,
+ models.FindReleasesOptions{
+ IncludeDrafts: false,
+ IncludeTags: true,
+ })
+ if err != nil {
+ log.Warn(" GetReleaseCountByRepoID: %v", err)
+ continue
+ }
+
+ log.Trace(" repo %s releases synchronized to tags: from %d to %d",
+ repo.FullName(), oldnum, count)
+ }
+ }
+
+ return nil
+}