Browse Source

internal: move packages under this directory (#5836)

* Rename pkg -> internal

* Rename routes -> route

* Move route -> internal/route

* Rename models -> db

* Move db -> internal/db

* Fix route2 -> route

* Move cmd -> internal/cmd

* Bump version
Unknwon 5 years ago
parent
commit
01c8df01ec
100 changed files with 364 additions and 363 deletions
  1. 5 5
      Makefile
  2. 3 3
      gogs.go
  3. 16 16
      internal/auth/auth.go
  4. 0 0
      internal/auth/github/github.go
  5. 0 0
      internal/auth/ldap/README.md
  6. 0 0
      internal/auth/ldap/ldap.go
  7. 0 0
      internal/auth/pam/pam.go
  8. 0 0
      internal/auth/pam/pam_stub.go
  9. 0 0
      internal/avatar/avatar.go
  10. 0 0
      internal/avatar/avatar_test.go
  11. 0 0
      internal/bindata/bindata.go
  12. 14 14
      internal/cmd/admin.go
  13. 5 5
      internal/cmd/backup.go
  14. 0 0
      internal/cmd/cert.go
  15. 0 0
      internal/cmd/cert_stub.go
  16. 0 0
      internal/cmd/cmd.go
  17. 27 27
      internal/cmd/hook.go
  18. 1 1
      internal/cmd/import.go
  19. 6 6
      internal/cmd/restore.go
  20. 26 26
      internal/cmd/serv.go
  21. 30 30
      internal/cmd/web.go
  22. 1 1
      internal/context/api.go
  23. 3 3
      internal/context/api_org.go
  24. 3 3
      internal/context/auth.go
  25. 11 11
      internal/context/context.go
  26. 3 3
      internal/context/notice.go
  27. 8 8
      internal/context/org.go
  28. 24 24
      internal/context/repo.go
  29. 4 4
      internal/context/user.go
  30. 10 10
      internal/cron/cron.go
  31. 2 2
      internal/db/access.go
  32. 6 6
      internal/db/action.go
  33. 3 3
      internal/db/admin.go
  34. 3 3
      internal/db/attachment.go
  35. 4 4
      internal/db/comment.go
  36. 1 1
      internal/db/error.go
  37. 0 0
      internal/db/errors/errors.go
  38. 0 0
      internal/db/errors/issue.go
  39. 0 0
      internal/db/errors/login_source.go
  40. 0 0
      internal/db/errors/org.go
  41. 0 0
      internal/db/errors/repo.go
  42. 0 0
      internal/db/errors/token.go
  43. 0 0
      internal/db/errors/two_factor.go
  44. 0 0
      internal/db/errors/user.go
  45. 0 0
      internal/db/errors/user_mail.go
  46. 0 0
      internal/db/errors/webhook.go
  47. 4 4
      internal/db/git_diff.go
  48. 1 1
      internal/db/git_diff_test.go
  49. 5 5
      internal/db/issue.go
  50. 2 2
      internal/db/issue_label.go
  51. 4 4
      internal/db/issue_mail.go
  52. 6 6
      internal/db/login_source.go
  53. 2 2
      internal/db/migrations/migrations.go
  54. 0 0
      internal/db/migrations/v13.go
  55. 0 0
      internal/db/migrations/v14.go
  56. 1 1
      internal/db/migrations/v15.go
  57. 1 1
      internal/db/migrations/v16.go
  58. 0 0
      internal/db/migrations/v17.go
  59. 1 1
      internal/db/migrations/v18.go
  60. 0 0
      internal/db/migrations/v19.go
  61. 3 3
      internal/db/milestone.go
  62. 6 6
      internal/db/mirror.go
  63. 1 1
      internal/db/mirror_test.go
  64. 7 7
      internal/db/models.go
  65. 1 1
      internal/db/models_sqlite.go
  66. 1 1
      internal/db/models_test.go
  67. 1 1
      internal/db/org.go
  68. 2 2
      internal/db/org_team.go
  69. 6 6
      internal/db/pull.go
  70. 4 4
      internal/db/release.go
  71. 13 13
      internal/db/repo.go
  72. 4 4
      internal/db/repo_branch.go
  73. 1 1
      internal/db/repo_collaboration.go
  74. 6 6
      internal/db/repo_editor.go
  75. 1 1
      internal/db/repo_editor_test.go
  76. 5 5
      internal/db/repo_test.go
  77. 4 4
      internal/db/ssh_key.go
  78. 2 2
      internal/db/ssh_key_test.go
  79. 5 4
      internal/db/token.go
  80. 6 6
      internal/db/two_factor.go
  81. 1 1
      internal/db/update.go
  82. 7 7
      internal/db/user.go
  83. 1 1
      internal/db/user_cache.go
  84. 2 2
      internal/db/user_mail.go
  85. 6 6
      internal/db/webhook.go
  86. 1 1
      internal/db/webhook_dingtalk.go
  87. 2 2
      internal/db/webhook_discord.go
  88. 2 2
      internal/db/webhook_slack.go
  89. 3 3
      internal/db/wiki.go
  90. 0 0
      internal/form/admin.go
  91. 0 0
      internal/form/auth.go
  92. 0 0
      internal/form/form.go
  93. 0 0
      internal/form/org.go
  94. 6 6
      internal/form/repo.go
  95. 0 0
      internal/form/user.go
  96. 0 0
      internal/httplib/httplib.go
  97. 2 2
      internal/mailer/mail.go
  98. 2 2
      internal/mailer/mailer.go
  99. 2 2
      internal/markup/markdown.go
  100. 2 2
      internal/markup/markdown_test.go

+ 5 - 5
Makefile

@@ -1,9 +1,9 @@
-LDFLAGS += -X "github.com/gogs/gogs/pkg/setting.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')"
-LDFLAGS += -X "github.com/gogs/gogs/pkg/setting.BuildGitHash=$(shell git rev-parse HEAD)"
+LDFLAGS += -X "gogs.io/gogs/internal/setting.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')"
+LDFLAGS += -X "gogs.io/gogs/internal/setting.BuildGitHash=$(shell git rev-parse HEAD)"
 
 DATA_FILES := $(shell find conf | sed 's/ /\\ /g')
 LESS_FILES := $(wildcard public/less/gogs.less public/less/_*.less)
-GENERATED  := pkg/bindata/bindata.go public/css/gogs.css
+GENERATED  := internal/bindata/bindata.go public/css/gogs.css
 
 OS := $(shell uname)
 
@@ -51,9 +51,9 @@ pack:
 
 release: build pack
 
-bindata: pkg/bindata/bindata.go
+bindata: internal/bindata/bindata.go
 
-pkg/bindata/bindata.go: $(DATA_FILES)
+internal/bindata/bindata.go: $(DATA_FILES)
 	go-bindata -o=$@ -ignore="\\.DS_Store|README.md|TRANSLATORS|auth.d" -pkg=bindata conf/...
 
 less: public/css/gogs.css

+ 3 - 3
gogs.go

@@ -12,11 +12,11 @@ import (
 
 	"github.com/urfave/cli"
 
-	"gogs.io/gogs/cmd"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/cmd"
+	"gogs.io/gogs/internal/setting"
 )
 
-const Version = "0.11.95.1023"
+const Version = "0.11.95.1024"
 
 func init() {
 	setting.AppVer = Version

+ 16 - 16
pkg/auth/auth.go → internal/auth/auth.go

@@ -13,10 +13,10 @@ import (
 	log "gopkg.in/clog.v1"
 	"gopkg.in/macaron.v1"
 
-	"gogs.io/gogs/models"
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/tool"
 )
 
 func IsAPIPath(url string) bool {
@@ -26,7 +26,7 @@ func IsAPIPath(url string) bool {
 // SignedInID returns the id of signed in user, along with one bool value which indicates whether user uses token
 // authentication.
 func SignedInID(c *macaron.Context, sess session.Store) (_ int64, isTokenAuth bool) {
-	if !models.HasEngine {
+	if !db.HasEngine {
 		return 0, false
 	}
 
@@ -49,15 +49,15 @@ func SignedInID(c *macaron.Context, sess session.Store) (_ int64, isTokenAuth bo
 
 		// Let's see if token is valid.
 		if len(tokenSHA) > 0 {
-			t, err := models.GetAccessTokenBySHA(tokenSHA)
+			t, err := db.GetAccessTokenBySHA(tokenSHA)
 			if err != nil {
-				if !models.IsErrAccessTokenNotExist(err) && !models.IsErrAccessTokenEmpty(err) {
+				if !db.IsErrAccessTokenNotExist(err) && !db.IsErrAccessTokenEmpty(err) {
 					log.Error(2, "GetAccessTokenBySHA: %v", err)
 				}
 				return 0, false
 			}
 			t.Updated = time.Now()
-			if err = models.UpdateAccessToken(t); err != nil {
+			if err = db.UpdateAccessToken(t); err != nil {
 				log.Error(2, "UpdateAccessToken: %v", err)
 			}
 			return t.UID, true
@@ -69,7 +69,7 @@ func SignedInID(c *macaron.Context, sess session.Store) (_ int64, isTokenAuth bo
 		return 0, false
 	}
 	if id, ok := uid.(int64); ok {
-		if _, err := models.GetUserByID(id); err != nil {
+		if _, err := db.GetUserByID(id); err != nil {
 			if !errors.IsUserNotExist(err) {
 				log.Error(2, "GetUserByID: %v", err)
 			}
@@ -82,8 +82,8 @@ func SignedInID(c *macaron.Context, sess session.Store) (_ int64, isTokenAuth bo
 
 // SignedInUser returns the user object of signed in user, along with two bool values,
 // which indicate whether user uses HTTP Basic Authentication or token authentication respectively.
-func SignedInUser(ctx *macaron.Context, sess session.Store) (_ *models.User, isBasicAuth bool, isTokenAuth bool) {
-	if !models.HasEngine {
+func SignedInUser(ctx *macaron.Context, sess session.Store) (_ *db.User, isBasicAuth bool, isTokenAuth bool) {
+	if !db.HasEngine {
 		return nil, false, false
 	}
 
@@ -93,7 +93,7 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (_ *models.User, isB
 		if setting.Service.EnableReverseProxyAuth {
 			webAuthUser := ctx.Req.Header.Get(setting.ReverseProxyAuthUser)
 			if len(webAuthUser) > 0 {
-				u, err := models.GetUserByName(webAuthUser)
+				u, err := db.GetUserByName(webAuthUser)
 				if err != nil {
 					if !errors.IsUserNotExist(err) {
 						log.Error(2, "GetUserByName: %v", err)
@@ -102,13 +102,13 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (_ *models.User, isB
 
 					// Check if enabled auto-registration.
 					if setting.Service.EnableReverseProxyAutoRegister {
-						u := &models.User{
+						u := &db.User{
 							Name:     webAuthUser,
 							Email:    gouuid.NewV4().String() + "@localhost",
 							Passwd:   webAuthUser,
 							IsActive: true,
 						}
-						if err = models.CreateUser(u); err != nil {
+						if err = db.CreateUser(u); err != nil {
 							// FIXME: should I create a system notice?
 							log.Error(2, "CreateUser: %v", err)
 							return nil, false, false
@@ -128,7 +128,7 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (_ *models.User, isB
 			if len(auths) == 2 && auths[0] == "Basic" {
 				uname, passwd, _ := tool.BasicAuthDecode(auths[1])
 
-				u, err := models.UserLogin(uname, passwd, -1)
+				u, err := db.UserLogin(uname, passwd, -1)
 				if err != nil {
 					if !errors.IsUserNotExist(err) {
 						log.Error(2, "UserLogin: %v", err)
@@ -142,7 +142,7 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (_ *models.User, isB
 		return nil, false, false
 	}
 
-	u, err := models.GetUserByID(uid)
+	u, err := db.GetUserByID(uid)
 	if err != nil {
 		log.Error(2, "GetUserByID: %v", err)
 		return nil, false, false

+ 0 - 0
pkg/auth/github/github.go → internal/auth/github/github.go


+ 0 - 0
pkg/auth/ldap/README.md → internal/auth/ldap/README.md


+ 0 - 0
pkg/auth/ldap/ldap.go → internal/auth/ldap/ldap.go


+ 0 - 0
pkg/auth/pam/pam.go → internal/auth/pam/pam.go


+ 0 - 0
pkg/auth/pam/pam_stub.go → internal/auth/pam/pam_stub.go


+ 0 - 0
pkg/avatar/avatar.go → internal/avatar/avatar.go


+ 0 - 0
pkg/avatar/avatar_test.go → internal/avatar/avatar_test.go


+ 0 - 0
pkg/bindata/bindata.go → internal/bindata/bindata.go


+ 14 - 14
cmd/admin.go → internal/cmd/admin.go

@@ -11,8 +11,8 @@ import (
 
 	"github.com/urfave/cli"
 
-	"gogs.io/gogs/models"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/setting"
 )
 
 var (
@@ -50,7 +50,7 @@ to make automatic initialization process more smoothly`,
 		Name:  "delete-inactive-users",
 		Usage: "Delete all inactive accounts",
 		Action: adminDashboardOperation(
-			models.DeleteInactivateUsers,
+			db.DeleteInactivateUsers,
 			"All inactivate accounts have been deleted successfully",
 		),
 		Flags: []cli.Flag{
@@ -62,7 +62,7 @@ to make automatic initialization process more smoothly`,
 		Name:  "delete-repository-archives",
 		Usage: "Delete all repositories archives",
 		Action: adminDashboardOperation(
-			models.DeleteRepositoryArchives,
+			db.DeleteRepositoryArchives,
 			"All repositories archives have been deleted successfully",
 		),
 		Flags: []cli.Flag{
@@ -74,7 +74,7 @@ to make automatic initialization process more smoothly`,
 		Name:  "delete-missing-repositories",
 		Usage: "Delete all repository records that lost Git files",
 		Action: adminDashboardOperation(
-			models.DeleteMissingRepositories,
+			db.DeleteMissingRepositories,
 			"All repositories archives have been deleted successfully",
 		),
 		Flags: []cli.Flag{
@@ -86,7 +86,7 @@ to make automatic initialization process more smoothly`,
 		Name:  "collect-garbage",
 		Usage: "Do garbage collection on repositories",
 		Action: adminDashboardOperation(
-			models.GitGcRepos,
+			db.GitGcRepos,
 			"All repositories have done garbage collection successfully",
 		),
 		Flags: []cli.Flag{
@@ -98,7 +98,7 @@ to make automatic initialization process more smoothly`,
 		Name:  "rewrite-authorized-keys",
 		Usage: "Rewrite '.ssh/authorized_keys' file (caution: non-Gogs keys will be lost)",
 		Action: adminDashboardOperation(
-			models.RewriteAuthorizedKeys,
+			db.RewriteAuthorizedKeys,
 			"All public keys have been rewritten successfully",
 		),
 		Flags: []cli.Flag{
@@ -110,7 +110,7 @@ to make automatic initialization process more smoothly`,
 		Name:  "resync-hooks",
 		Usage: "Resync pre-receive, update and post-receive hooks",
 		Action: adminDashboardOperation(
-			models.SyncRepositoryHooks,
+			db.SyncRepositoryHooks,
 			"All repositories' pre-receive, update and post-receive hooks have been resynced successfully",
 		),
 		Flags: []cli.Flag{
@@ -122,7 +122,7 @@ to make automatic initialization process more smoothly`,
 		Name:  "reinit-missing-repositories",
 		Usage: "Reinitialize all repository records that lost Git files",
 		Action: adminDashboardOperation(
-			models.ReinitMissingRepositories,
+			db.ReinitMissingRepositories,
 			"All repository records that lost Git files have been reinitialized successfully",
 		),
 		Flags: []cli.Flag{
@@ -145,10 +145,10 @@ func runCreateUser(c *cli.Context) error {
 	}
 
 	setting.NewContext()
-	models.LoadConfigs()
-	models.SetEngine()
+	db.LoadConfigs()
+	db.SetEngine()
 
-	if err := models.CreateUser(&models.User{
+	if err := db.CreateUser(&db.User{
 		Name:     c.String("name"),
 		Email:    c.String("email"),
 		Passwd:   c.String("password"),
@@ -169,8 +169,8 @@ func adminDashboardOperation(operation func() error, successMessage string) func
 		}
 
 		setting.NewContext()
-		models.LoadConfigs()
-		models.SetEngine()
+		db.LoadConfigs()
+		db.SetEngine()
 
 		if err := operation(); err != nil {
 			functionName := runtime.FuncForPC(reflect.ValueOf(operation).Pointer()).Name()

+ 5 - 5
cmd/backup.go → internal/cmd/backup.go

@@ -17,8 +17,8 @@ import (
 	log "gopkg.in/clog.v1"
 	"gopkg.in/ini.v1"
 
-	"gogs.io/gogs/models"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/setting"
 )
 
 var Backup = cli.Command{
@@ -48,8 +48,8 @@ func runBackup(c *cli.Context) error {
 		setting.CustomConf = c.String("config")
 	}
 	setting.NewContext()
-	models.LoadConfigs()
-	models.SetEngine()
+	db.LoadConfigs()
+	db.SetEngine()
 
 	tmpDir := c.String("tempdir")
 	if !com.IsExist(tmpDir) {
@@ -84,7 +84,7 @@ func runBackup(c *cli.Context) error {
 
 	// Database
 	dbDir := path.Join(rootDir, "db")
-	if err = models.DumpDatabase(dbDir); err != nil {
+	if err = db.DumpDatabase(dbDir); err != nil {
 		log.Fatal(0, "Fail to dump database: %v", err)
 	}
 	if err = z.AddDir(_ARCHIVE_ROOT_DIR+"/db", dbDir); err != nil {

+ 0 - 0
cmd/cert.go → internal/cmd/cert.go


+ 0 - 0
cmd/cert_stub.go → internal/cmd/cert_stub.go


+ 0 - 0
cmd/cmd.go → internal/cmd/cmd.go


+ 27 - 27
cmd/hook.go → internal/cmd/hook.go

@@ -21,12 +21,12 @@ import (
 
 	"github.com/gogs/git-module"
 
-	"gogs.io/gogs/models"
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/httplib"
-	"gogs.io/gogs/pkg/mailer"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/template"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/httplib"
+	"gogs.io/gogs/internal/mailer"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/template"
 )
 
 var (
@@ -70,7 +70,7 @@ func runHookPreReceive(c *cli.Context) error {
 	}
 	setup(c, "hooks/pre-receive.log", true)
 
-	isWiki := strings.Contains(os.Getenv(models.ENV_REPO_CUSTOM_HOOKS_PATH), ".wiki.git/")
+	isWiki := strings.Contains(os.Getenv(db.ENV_REPO_CUSTOM_HOOKS_PATH), ".wiki.git/")
 
 	buf := bytes.NewBuffer(nil)
 	scanner := bufio.NewScanner(os.Stdin)
@@ -91,8 +91,8 @@ func runHookPreReceive(c *cli.Context) error {
 		branchName := strings.TrimPrefix(string(fields[2]), git.BRANCH_PREFIX)
 
 		// Branch protection
-		repoID := com.StrTo(os.Getenv(models.ENV_REPO_ID)).MustInt64()
-		protectBranch, err := models.GetProtectBranchOfRepoByName(repoID, branchName)
+		repoID := com.StrTo(os.Getenv(db.ENV_REPO_ID)).MustInt64()
+		protectBranch, err := db.GetProtectBranchOfRepoByName(repoID, branchName)
 		if err != nil {
 			if errors.IsErrBranchNotExist(err) {
 				continue
@@ -107,9 +107,9 @@ func runHookPreReceive(c *cli.Context) error {
 		bypassRequirePullRequest := false
 
 		// Check if user is in whitelist when enabled
-		userID := com.StrTo(os.Getenv(models.ENV_AUTH_USER_ID)).MustInt64()
+		userID := com.StrTo(os.Getenv(db.ENV_AUTH_USER_ID)).MustInt64()
 		if protectBranch.EnableWhitelist {
-			if !models.IsUserInProtectBranchWhitelist(repoID, userID, branchName) {
+			if !db.IsUserInProtectBranchWhitelist(repoID, userID, branchName) {
 				fail(fmt.Sprintf("Branch '%s' is protected and you are not in the push whitelist", branchName), "")
 			}
 
@@ -128,7 +128,7 @@ func runHookPreReceive(c *cli.Context) error {
 
 		// Check force push
 		output, err := git.NewCommand("rev-list", "--max-count=1", oldCommitID, "^"+newCommitID).
-			RunInDir(models.RepoPath(os.Getenv(models.ENV_REPO_OWNER_NAME), os.Getenv(models.ENV_REPO_NAME)))
+			RunInDir(db.RepoPath(os.Getenv(db.ENV_REPO_OWNER_NAME), os.Getenv(db.ENV_REPO_NAME)))
 		if err != nil {
 			fail("Internal error", "Fail to detect force push: %v", err)
 		} else if len(output) > 0 {
@@ -136,7 +136,7 @@ func runHookPreReceive(c *cli.Context) error {
 		}
 	}
 
-	customHooksPath := filepath.Join(os.Getenv(models.ENV_REPO_CUSTOM_HOOKS_PATH), "pre-receive")
+	customHooksPath := filepath.Join(os.Getenv(db.ENV_REPO_CUSTOM_HOOKS_PATH), "pre-receive")
 	if !com.IsFile(customHooksPath) {
 		return nil
 	}
@@ -147,7 +147,7 @@ func runHookPreReceive(c *cli.Context) error {
 	} else {
 		hookCmd = exec.Command(customHooksPath)
 	}
-	hookCmd.Dir = models.RepoPath(os.Getenv(models.ENV_REPO_OWNER_NAME), os.Getenv(models.ENV_REPO_NAME))
+	hookCmd.Dir = db.RepoPath(os.Getenv(db.ENV_REPO_OWNER_NAME), os.Getenv(db.ENV_REPO_NAME))
 	hookCmd.Stdout = os.Stdout
 	hookCmd.Stdin = buf
 	hookCmd.Stderr = os.Stderr
@@ -170,7 +170,7 @@ func runHookUpdate(c *cli.Context) error {
 		fail("First argument 'refName' is empty", "First argument 'refName' is empty")
 	}
 
-	customHooksPath := filepath.Join(os.Getenv(models.ENV_REPO_CUSTOM_HOOKS_PATH), "update")
+	customHooksPath := filepath.Join(os.Getenv(db.ENV_REPO_CUSTOM_HOOKS_PATH), "update")
 	if !com.IsFile(customHooksPath) {
 		return nil
 	}
@@ -181,7 +181,7 @@ func runHookUpdate(c *cli.Context) error {
 	} else {
 		hookCmd = exec.Command(customHooksPath, args...)
 	}
-	hookCmd.Dir = models.RepoPath(os.Getenv(models.ENV_REPO_OWNER_NAME), os.Getenv(models.ENV_REPO_NAME))
+	hookCmd.Dir = db.RepoPath(os.Getenv(db.ENV_REPO_OWNER_NAME), os.Getenv(db.ENV_REPO_NAME))
 	hookCmd.Stdout = os.Stdout
 	hookCmd.Stdin = os.Stdin
 	hookCmd.Stderr = os.Stderr
@@ -204,7 +204,7 @@ func runHookPostReceive(c *cli.Context) error {
 	mailer.InitMailRender(path.Join(setting.StaticRootPath, "templates/mail"),
 		path.Join(setting.CustomPath, "templates/mail"), template.NewFuncMap())
 
-	isWiki := strings.Contains(os.Getenv(models.ENV_REPO_CUSTOM_HOOKS_PATH), ".wiki.git/")
+	isWiki := strings.Contains(os.Getenv(db.ENV_REPO_CUSTOM_HOOKS_PATH), ".wiki.git/")
 
 	buf := bytes.NewBuffer(nil)
 	scanner := bufio.NewScanner(os.Stdin)
@@ -222,24 +222,24 @@ func runHookPostReceive(c *cli.Context) error {
 			continue
 		}
 
-		options := models.PushUpdateOptions{
+		options := db.PushUpdateOptions{
 			OldCommitID:  string(fields[0]),
 			NewCommitID:  string(fields[1]),
 			RefFullName:  string(fields[2]),
-			PusherID:     com.StrTo(os.Getenv(models.ENV_AUTH_USER_ID)).MustInt64(),
-			PusherName:   os.Getenv(models.ENV_AUTH_USER_NAME),
-			RepoUserName: os.Getenv(models.ENV_REPO_OWNER_NAME),
-			RepoName:     os.Getenv(models.ENV_REPO_NAME),
+			PusherID:     com.StrTo(os.Getenv(db.ENV_AUTH_USER_ID)).MustInt64(),
+			PusherName:   os.Getenv(db.ENV_AUTH_USER_NAME),
+			RepoUserName: os.Getenv(db.ENV_REPO_OWNER_NAME),
+			RepoName:     os.Getenv(db.ENV_REPO_NAME),
 		}
-		if err := models.PushUpdate(options); err != nil {
+		if err := db.PushUpdate(options); err != nil {
 			log.Error(2, "PushUpdate: %v", err)
 		}
 
 		// Ask for running deliver hook and test pull request tasks
 		reqURL := setting.LocalURL + options.RepoUserName + "/" + options.RepoName + "/tasks/trigger?branch=" +
 			template.EscapePound(strings.TrimPrefix(options.RefFullName, git.BRANCH_PREFIX)) +
-			"&secret=" + os.Getenv(models.ENV_REPO_OWNER_SALT_MD5) +
-			"&pusher=" + os.Getenv(models.ENV_AUTH_USER_ID)
+			"&secret=" + os.Getenv(db.ENV_REPO_OWNER_SALT_MD5) +
+			"&pusher=" + os.Getenv(db.ENV_AUTH_USER_ID)
 		log.Trace("Trigger task: %s", reqURL)
 
 		resp, err := httplib.Head(reqURL).SetTLSClientConfig(&tls.Config{
@@ -255,7 +255,7 @@ func runHookPostReceive(c *cli.Context) error {
 		}
 	}
 
-	customHooksPath := filepath.Join(os.Getenv(models.ENV_REPO_CUSTOM_HOOKS_PATH), "post-receive")
+	customHooksPath := filepath.Join(os.Getenv(db.ENV_REPO_CUSTOM_HOOKS_PATH), "post-receive")
 	if !com.IsFile(customHooksPath) {
 		return nil
 	}
@@ -266,7 +266,7 @@ func runHookPostReceive(c *cli.Context) error {
 	} else {
 		hookCmd = exec.Command(customHooksPath)
 	}
-	hookCmd.Dir = models.RepoPath(os.Getenv(models.ENV_REPO_OWNER_NAME), os.Getenv(models.ENV_REPO_NAME))
+	hookCmd.Dir = db.RepoPath(os.Getenv(db.ENV_REPO_OWNER_NAME), os.Getenv(db.ENV_REPO_NAME))
 	hookCmd.Stdout = os.Stdout
 	hookCmd.Stdin = buf
 	hookCmd.Stderr = os.Stderr

+ 1 - 1
cmd/import.go → internal/cmd/import.go

@@ -15,7 +15,7 @@ import (
 	"github.com/unknwon/com"
 	"github.com/urfave/cli"
 
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/setting"
 )
 
 var (

+ 6 - 6
cmd/restore.go → internal/cmd/restore.go

@@ -8,15 +8,15 @@ import (
 	"os"
 	"path"
 
+	"github.com/mcuadros/go-version"
 	"github.com/unknwon/cae/zip"
 	"github.com/unknwon/com"
-	"github.com/mcuadros/go-version"
 	"github.com/urfave/cli"
 	log "gopkg.in/clog.v1"
 	"gopkg.in/ini.v1"
 
-	"gogs.io/gogs/models"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/setting"
 )
 
 var Restore = cli.Command{
@@ -91,12 +91,12 @@ func runRestore(c *cli.Context) error {
 		setting.CustomConf = configFile
 	}
 	setting.NewContext()
-	models.LoadConfigs()
-	models.SetEngine()
+	db.LoadConfigs()
+	db.SetEngine()
 
 	// Database
 	dbDir := path.Join(archivePath, "db")
-	if err = models.ImportDatabase(dbDir, c.Bool("verbose")); err != nil {
+	if err = db.ImportDatabase(dbDir, c.Bool("verbose")); err != nil {
 		log.Fatal(0, "Failed to import database: %v", err)
 	}
 

+ 26 - 26
cmd/serv.go → internal/cmd/serv.go

@@ -16,9 +16,9 @@ import (
 	"github.com/urfave/cli"
 	log "gopkg.in/clog.v1"
 
-	"gogs.io/gogs/models"
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/setting"
 )
 
 const (
@@ -76,14 +76,14 @@ func setup(c *cli.Context, logPath string, connectDB bool) {
 		return
 	}
 
-	models.LoadConfigs()
+	db.LoadConfigs()
 
 	if setting.UseSQLite3 {
 		workDir, _ := setting.WorkDir()
 		os.Chdir(workDir)
 	}
 
-	if err := models.SetEngine(); err != nil {
+	if err := db.SetEngine(); err != nil {
 		fail("Internal error", "SetEngine: %v", err)
 	}
 }
@@ -96,29 +96,29 @@ func parseSSHCmd(cmd string) (string, string) {
 	return ss[0], strings.Replace(ss[1], "'/", "'", 1)
 }
 
-func checkDeployKey(key *models.PublicKey, repo *models.Repository) {
+func checkDeployKey(key *db.PublicKey, repo *db.Repository) {
 	// Check if this deploy key belongs to current repository.
-	if !models.HasDeployKey(key.ID, repo.ID) {
+	if !db.HasDeployKey(key.ID, repo.ID) {
 		fail("Key access denied", "Deploy key access denied: [key_id: %d, repo_id: %d]", key.ID, repo.ID)
 	}
 
 	// Update deploy key activity.
-	deployKey, err := models.GetDeployKeyByRepo(key.ID, repo.ID)
+	deployKey, err := db.GetDeployKeyByRepo(key.ID, repo.ID)
 	if err != nil {
 		fail("Internal error", "GetDeployKey: %v", err)
 	}
 
 	deployKey.Updated = time.Now()
-	if err = models.UpdateDeployKey(deployKey); err != nil {
+	if err = db.UpdateDeployKey(deployKey); err != nil {
 		fail("Internal error", "UpdateDeployKey: %v", err)
 	}
 }
 
 var (
-	allowedCommands = map[string]models.AccessMode{
-		"git-upload-pack":    models.ACCESS_MODE_READ,
-		"git-upload-archive": models.ACCESS_MODE_READ,
-		"git-receive-pack":   models.ACCESS_MODE_WRITE,
+	allowedCommands = map[string]db.AccessMode{
+		"git-upload-pack":    db.ACCESS_MODE_READ,
+		"git-upload-archive": db.ACCESS_MODE_READ,
+		"git-receive-pack":   db.ACCESS_MODE_WRITE,
 	}
 )
 
@@ -151,7 +151,7 @@ func runServ(c *cli.Context) error {
 	repoName := strings.TrimSuffix(strings.ToLower(repoFields[1]), ".git")
 	repoName = strings.TrimSuffix(repoName, ".wiki")
 
-	owner, err := models.GetUserByName(ownerName)
+	owner, err := db.GetUserByName(ownerName)
 	if err != nil {
 		if errors.IsUserNotExist(err) {
 			fail("Repository owner does not exist", "Unregistered owner: %s", ownerName)
@@ -159,7 +159,7 @@ func runServ(c *cli.Context) error {
 		fail("Internal error", "Fail to get repository owner '%s': %v", ownerName, err)
 	}
 
-	repo, err := models.GetRepositoryByName(owner.ID, repoName)
+	repo, err := db.GetRepositoryByName(owner.ID, repoName)
 	if err != nil {
 		if errors.IsRepoNotExist(err) {
 			fail(_ACCESS_DENIED_MESSAGE, "Repository does not exist: %s/%s", owner.Name, repoName)
@@ -174,19 +174,19 @@ func runServ(c *cli.Context) error {
 	}
 
 	// Prohibit push to mirror repositories.
-	if requestMode > models.ACCESS_MODE_READ && repo.IsMirror {
+	if requestMode > db.ACCESS_MODE_READ && repo.IsMirror {
 		fail("Mirror repository is read-only", "")
 	}
 
 	// Allow anonymous (user is nil) clone for public repositories.
-	var user *models.User
+	var user *db.User
 
-	key, err := models.GetPublicKeyByID(com.StrTo(strings.TrimPrefix(c.Args()[0], "key-")).MustInt64())
+	key, err := db.GetPublicKeyByID(com.StrTo(strings.TrimPrefix(c.Args()[0], "key-")).MustInt64())
 	if err != nil {
 		fail("Invalid key ID", "Invalid key ID '%s': %v", c.Args()[0], err)
 	}
 
-	if requestMode == models.ACCESS_MODE_WRITE || repo.IsPrivate {
+	if requestMode == db.ACCESS_MODE_WRITE || repo.IsPrivate {
 		// Check deploy key or user key.
 		if key.IsDeployKey() {
 			if key.Mode < requestMode {
@@ -194,19 +194,19 @@ func runServ(c *cli.Context) error {
 			}
 			checkDeployKey(key, repo)
 		} else {
-			user, err = models.GetUserByKeyID(key.ID)
+			user, err = db.GetUserByKeyID(key.ID)
 			if err != nil {
 				fail("Internal error", "Fail to get user by key ID '%d': %v", key.ID, err)
 			}
 
-			mode, err := models.UserAccessMode(user.ID, repo)
+			mode, err := db.UserAccessMode(user.ID, repo)
 			if err != nil {
 				fail("Internal error", "Fail to check access: %v", err)
 			}
 
 			if mode < requestMode {
 				clientMessage := _ACCESS_DENIED_MESSAGE
-				if mode >= models.ACCESS_MODE_READ {
+				if mode >= db.ACCESS_MODE_READ {
 					clientMessage = "You do not have sufficient authorization for this action"
 				}
 				fail(clientMessage,
@@ -227,13 +227,13 @@ func runServ(c *cli.Context) error {
 
 	// Update user key activity.
 	if key.ID > 0 {
-		key, err := models.GetPublicKeyByID(key.ID)
+		key, err := db.GetPublicKeyByID(key.ID)
 		if err != nil {
 			fail("Internal error", "GetPublicKeyByID: %v", err)
 		}
 
 		key.Updated = time.Now()
-		if err = models.UpdatePublicKey(key); err != nil {
+		if err = db.UpdatePublicKey(key); err != nil {
 			fail("Internal error", "UpdatePublicKey: %v", err)
 		}
 	}
@@ -250,8 +250,8 @@ func runServ(c *cli.Context) error {
 	} else {
 		gitCmd = exec.Command(verb, repoFullName)
 	}
-	if requestMode == models.ACCESS_MODE_WRITE {
-		gitCmd.Env = append(os.Environ(), models.ComposeHookEnvs(models.ComposeHookEnvsOptions{
+	if requestMode == db.ACCESS_MODE_WRITE {
+		gitCmd.Env = append(os.Environ(), db.ComposeHookEnvs(db.ComposeHookEnvsOptions{
 			AuthUser:  user,
 			OwnerName: owner.Name,
 			OwnerSalt: owner.Salt,

+ 30 - 30
cmd/web.go → internal/cmd/web.go

@@ -15,7 +15,6 @@ import (
 	"path"
 	"strings"
 
-	"github.com/unknwon/com"
 	"github.com/go-macaron/binding"
 	"github.com/go-macaron/cache"
 	"github.com/go-macaron/captcha"
@@ -26,24 +25,25 @@ import (
 	"github.com/go-macaron/toolbox"
 	"github.com/mcuadros/go-version"
 	"github.com/prometheus/client_golang/prometheus/promhttp"
+	"github.com/unknwon/com"
 	"github.com/urfave/cli"
 	log "gopkg.in/clog.v1"
 	"gopkg.in/macaron.v1"
 
-	"gogs.io/gogs/models"
-	"gogs.io/gogs/pkg/bindata"
-	"gogs.io/gogs/pkg/context"
-	"gogs.io/gogs/pkg/form"
-	"gogs.io/gogs/pkg/mailer"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/template"
-	"gogs.io/gogs/routes"
-	"gogs.io/gogs/routes/admin"
-	apiv1 "gogs.io/gogs/routes/api/v1"
-	"gogs.io/gogs/routes/dev"
-	"gogs.io/gogs/routes/org"
-	"gogs.io/gogs/routes/repo"
-	"gogs.io/gogs/routes/user"
+	"gogs.io/gogs/internal/bindata"
+	"gogs.io/gogs/internal/context"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/form"
+	"gogs.io/gogs/internal/mailer"
+	"gogs.io/gogs/internal/route"
+	"gogs.io/gogs/internal/route/admin"
+	apiv1 "gogs.io/gogs/internal/route/api/v1"
+	"gogs.io/gogs/internal/route/dev"
+	"gogs.io/gogs/internal/route/org"
+	"gogs.io/gogs/internal/route/repo"
+	"gogs.io/gogs/internal/route/user"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/template"
 )
 
 var Web = cli.Command{
@@ -97,14 +97,14 @@ func newMacaron() *macaron.Macaron {
 	m.Use(macaron.Static(
 		setting.AvatarUploadPath,
 		macaron.StaticOptions{
-			Prefix:      models.USER_AVATAR_URL_PREFIX,
+			Prefix:      db.USER_AVATAR_URL_PREFIX,
 			SkipLogging: setting.DisableRouterLog,
 		},
 	))
 	m.Use(macaron.Static(
 		setting.RepositoryAvatarUploadPath,
 		macaron.StaticOptions{
-			Prefix:      models.REPO_AVATAR_URL_PREFIX,
+			Prefix:      db.REPO_AVATAR_URL_PREFIX,
 			SkipLogging: setting.DisableRouterLog,
 		},
 	))
@@ -156,7 +156,7 @@ func newMacaron() *macaron.Macaron {
 		HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
 			&toolbox.HealthCheckFuncDesc{
 				Desc: "Database connection",
-				Func: models.Ping,
+				Func: db.Ping,
 			},
 		},
 	}))
@@ -168,7 +168,7 @@ func runWeb(c *cli.Context) error {
 	if c.IsSet("config") {
 		setting.CustomConf = c.String("config")
 	}
-	routes.GlobalInit()
+	route.GlobalInit()
 	checkVersion()
 
 	m := newMacaron()
@@ -182,20 +182,20 @@ func runWeb(c *cli.Context) error {
 
 	m.SetAutoHead(true)
 
-	// FIXME: not all routes need go through same middlewares.
+	// FIXME: not all route need go through same middlewares.
 	// Especially some AJAX requests, we can reduce middleware number to improve performance.
 	// Routers.
-	m.Get("/", ignSignIn, routes.Home)
+	m.Get("/", ignSignIn, route.Home)
 	m.Group("/explore", func() {
 		m.Get("", func(c *context.Context) {
 			c.Redirect(setting.AppSubURL + "/explore/repos")
 		})
-		m.Get("/repos", routes.ExploreRepos)
-		m.Get("/users", routes.ExploreUsers)
-		m.Get("/organizations", routes.ExploreOrganizations)
+		m.Get("/repos", route.ExploreRepos)
+		m.Get("/users", route.ExploreUsers)
+		m.Get("/organizations", route.ExploreOrganizations)
 	}, ignSignIn)
-	m.Combo("/install", routes.InstallInit).Get(routes.Install).
-		Post(bindIgnErr(form.Install{}), routes.InstallPost)
+	m.Combo("/install", route.InstallInit).Get(route.Install).
+		Post(bindIgnErr(form.Install{}), route.InstallPost)
 	m.Get("/^:type(issues|pulls)$", reqSignIn, user.Issues)
 
 	// ***** START: User *****
@@ -311,9 +311,9 @@ func runWeb(c *cli.Context) error {
 		}, context.InjectParamsUser())
 
 		m.Get("/attachments/:uuid", func(c *context.Context) {
-			attach, err := models.GetAttachmentByUUID(c.Params(":uuid"))
+			attach, err := db.GetAttachmentByUUID(c.Params(":uuid"))
 			if err != nil {
-				c.NotFoundOrServerError("GetAttachmentByUUID", models.IsErrAttachmentNotExist, err)
+				c.NotFoundOrServerError("GetAttachmentByUUID", db.IsErrAttachmentNotExist, err)
 				return
 			} else if !com.IsFile(attach.LocalPath()) {
 				c.NotFound()
@@ -644,7 +644,7 @@ func runWeb(c *cli.Context) error {
 			m.Head("/tasks/trigger", repo.TriggerTask)
 		})
 		// Use the regexp to match the repository name
-		// Duplicated routes to enable different ways of accessing same set of URLs,
+		// Duplicated route to enable different ways of accessing same set of URLs,
 		// e.g. with or without ".git" suffix.
 		m.Group("/:reponame([\\d\\w-_\\.]+\\.git$)", func() {
 			m.Get("", ignSignIn, context.RepoAssignment(), context.RepoRef(), repo.Home)
@@ -682,7 +682,7 @@ func runWeb(c *cli.Context) error {
 	})
 
 	// Not found handler.
-	m.NotFound(routes.NotFound)
+	m.NotFound(route.NotFound)
 
 	// Flag for port number in case first time run conflict.
 	if c.IsSet("port") {

+ 1 - 1
pkg/context/api.go → internal/context/api.go

@@ -13,7 +13,7 @@ import (
 	log "gopkg.in/clog.v1"
 	"gopkg.in/macaron.v1"
 
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/setting"
 )
 
 type APIContext struct {

+ 3 - 3
pkg/context/api_org.go → internal/context/api_org.go

@@ -5,10 +5,10 @@
 package context
 
 import (
-	"gogs.io/gogs/models"
+	"gogs.io/gogs/internal/db"
 )
 
 type APIOrganization struct {
-	Organization *models.User
-	Team         *models.Team
+	Organization *db.User
+	Team         *db.Team
 }

+ 3 - 3
pkg/context/auth.go → internal/context/auth.go

@@ -12,9 +12,9 @@ import (
 	"github.com/go-macaron/csrf"
 	"gopkg.in/macaron.v1"
 
-	"gogs.io/gogs/pkg/auth"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/auth"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/tool"
 )
 
 type ToggleOptions struct {

+ 11 - 11
pkg/context/context.go → internal/context/context.go

@@ -12,20 +12,20 @@ import (
 	"strings"
 	"time"
 
-	"github.com/unknwon/com"
 	"github.com/go-macaron/cache"
 	"github.com/go-macaron/csrf"
 	"github.com/go-macaron/i18n"
 	"github.com/go-macaron/session"
+	"github.com/unknwon/com"
 	log "gopkg.in/clog.v1"
 	"gopkg.in/macaron.v1"
 
-	"gogs.io/gogs/models"
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/auth"
-	"gogs.io/gogs/pkg/form"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/template"
+	"gogs.io/gogs/internal/auth"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/form"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/template"
 )
 
 // Context represents context of a request.
@@ -37,7 +37,7 @@ type Context struct {
 	Session session.Store
 
 	Link        string // Current request URL
-	User        *models.User
+	User        *db.User
 	IsLogged    bool
 	IsBasicAuth bool
 	IsTokenAuth bool
@@ -252,13 +252,13 @@ func Contexter() macaron.Handler {
 			repoName := c.Params(":reponame")
 			branchName := "master"
 
-			owner, err := models.GetUserByName(ownerName)
+			owner, err := db.GetUserByName(ownerName)
 			if err != nil {
 				c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 				return
 			}
 
-			repo, err := models.GetRepositoryByName(owner.ID, repoName)
+			repo, err := db.GetRepositoryByName(owner.ID, repoName)
 			if err == nil && len(repo.DefaultBranch) > 0 {
 				branchName = repo.DefaultBranch
 			}
@@ -280,7 +280,7 @@ func Contexter() macaron.Handler {
 </html>
 `, map[string]string{
 				"GoGetImport":    path.Join(setting.HostAddress, setting.AppSubURL, repo.FullName()),
-				"CloneLink":      models.ComposeHTTPSCloneURL(ownerName, repoName),
+				"CloneLink":      db.ComposeHTTPSCloneURL(ownerName, repoName),
 				"GoDocDirectory": prefix + "{/dir}",
 				"GoDocFile":      prefix + "{/dir}/{file}#L{line}",
 				"InsecureFlag":   insecureFlag,

+ 3 - 3
pkg/context/notice.go → internal/context/notice.go

@@ -11,9 +11,9 @@ import (
 	"github.com/unknwon/com"
 	log "gopkg.in/clog.v1"
 
-	"gogs.io/gogs/pkg/markup"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/markup"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/tool"
 )
 
 // renderNoticeBanner checks if a notice banner file exists and loads the message to display

+ 8 - 8
pkg/context/org.go → internal/context/org.go

@@ -9,9 +9,9 @@ import (
 
 	"gopkg.in/macaron.v1"
 
-	"gogs.io/gogs/models"
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/setting"
 )
 
 type Organization struct {
@@ -19,10 +19,10 @@ type Organization struct {
 	IsMember     bool
 	IsTeamMember bool // Is member of team.
 	IsTeamAdmin  bool // In owner team or team that has admin permission level.
-	Organization *models.User
+	Organization *db.User
 	OrgLink      string
 
-	Team *models.Team
+	Team *db.Team
 }
 
 func HandleOrgAssignment(c *Context, args ...bool) {
@@ -48,7 +48,7 @@ func HandleOrgAssignment(c *Context, args ...bool) {
 	orgName := c.Params(":org")
 
 	var err error
-	c.Org.Organization, err = models.GetUserByName(orgName)
+	c.Org.Organization, err = db.GetUserByName(orgName)
 	if err != nil {
 		c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 		return
@@ -81,7 +81,7 @@ func HandleOrgAssignment(c *Context, args ...bool) {
 		}
 	} else {
 		// Fake data.
-		c.Data["SignedUser"] = &models.User{}
+		c.Data["SignedUser"] = &db.User{}
 	}
 	if (requireMember && !c.Org.IsMember) ||
 		(requireOwner && !c.Org.IsOwner) {
@@ -134,7 +134,7 @@ func HandleOrgAssignment(c *Context, args ...bool) {
 			return
 		}
 
-		c.Org.IsTeamAdmin = c.Org.Team.IsOwnerTeam() || c.Org.Team.Authorize >= models.ACCESS_MODE_ADMIN
+		c.Org.IsTeamAdmin = c.Org.Team.IsOwnerTeam() || c.Org.Team.Authorize >= db.ACCESS_MODE_ADMIN
 		c.Data["IsTeamAdmin"] = c.Org.IsTeamAdmin
 		if requireTeamAdmin && !c.Org.IsTeamAdmin {
 			c.Handle(404, "OrgAssignment", err)

+ 24 - 24
pkg/context/repo.go → internal/context/repo.go

@@ -14,26 +14,26 @@ import (
 
 	"github.com/gogs/git-module"
 
-	"gogs.io/gogs/models"
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/setting"
 )
 
 type PullRequest struct {
-	BaseRepo *models.Repository
+	BaseRepo *db.Repository
 	Allowed  bool
 	SameRepo bool
 	HeadInfo string // [<user>:]<branch>
 }
 
 type Repository struct {
-	AccessMode   models.AccessMode
+	AccessMode   db.AccessMode
 	IsWatching   bool
 	IsViewBranch bool
 	IsViewTag    bool
 	IsViewCommit bool
-	Repository   *models.Repository
-	Owner        *models.User
+	Repository   *db.Repository
+	Owner        *db.User
 	Commit       *git.Commit
 	Tag          *git.Tag
 	GitRepo      *git.Repository
@@ -42,31 +42,31 @@ type Repository struct {
 	TreePath     string
 	CommitID     string
 	RepoLink     string
-	CloneLink    models.CloneLink
+	CloneLink    db.CloneLink
 	CommitsCount int64
-	Mirror       *models.Mirror
+	Mirror       *db.Mirror
 
 	PullRequest *PullRequest
 }
 
 // IsOwner returns true if current user is the owner of repository.
 func (r *Repository) IsOwner() bool {
-	return r.AccessMode >= models.ACCESS_MODE_OWNER
+	return r.AccessMode >= db.ACCESS_MODE_OWNER
 }
 
 // IsAdmin returns true if current user has admin or higher access of repository.
 func (r *Repository) IsAdmin() bool {
-	return r.AccessMode >= models.ACCESS_MODE_ADMIN
+	return r.AccessMode >= db.ACCESS_MODE_ADMIN
 }
 
 // IsWriter returns true if current user has write or higher access of repository.
 func (r *Repository) IsWriter() bool {
-	return r.AccessMode >= models.ACCESS_MODE_WRITE
+	return r.AccessMode >= db.ACCESS_MODE_WRITE
 }
 
 // HasAccess returns true if the current user has at least read access for this repository
 func (r *Repository) HasAccess() bool {
-	return r.AccessMode >= models.ACCESS_MODE_READ
+	return r.AccessMode >= db.ACCESS_MODE_READ
 }
 
 // CanEnableEditor returns true if repository is editable and user has proper access level.
@@ -110,7 +110,7 @@ func (r *Repository) PullRequestURL(baseBranch, headBranch string) string {
 func RepoAssignment(pages ...bool) macaron.Handler {
 	return func(c *Context) {
 		var (
-			owner        *models.User
+			owner        *db.User
 			err          error
 			isIssuesPage bool
 			isWikiPage   bool
@@ -134,7 +134,7 @@ func RepoAssignment(pages ...bool) macaron.Handler {
 		if c.IsLogged && c.User.LowerName == strings.ToLower(ownerName) {
 			owner = c.User
 		} else {
-			owner, err = models.GetUserByName(ownerName)
+			owner, err = db.GetUserByName(ownerName)
 			if err != nil {
 				c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 				return
@@ -143,7 +143,7 @@ func RepoAssignment(pages ...bool) macaron.Handler {
 		c.Repo.Owner = owner
 		c.Data["Username"] = c.Repo.Owner.Name
 
-		repo, err := models.GetRepositoryByName(owner.ID, repoName)
+		repo, err := db.GetRepositoryByName(owner.ID, repoName)
 		if err != nil {
 			c.NotFoundOrServerError("GetRepositoryByName", errors.IsRepoNotExist, err)
 			return
@@ -158,9 +158,9 @@ func RepoAssignment(pages ...bool) macaron.Handler {
 
 		// Admin has super access.
 		if c.IsLogged && c.User.IsAdmin {
-			c.Repo.AccessMode = models.ACCESS_MODE_OWNER
+			c.Repo.AccessMode = db.ACCESS_MODE_OWNER
 		} else {
-			mode, err := models.UserAccessMode(c.UserID(), repo)
+			mode, err := db.UserAccessMode(c.UserID(), repo)
 			if err != nil {
 				c.ServerError("UserAccessMode", err)
 				return
@@ -169,7 +169,7 @@ func RepoAssignment(pages ...bool) macaron.Handler {
 		}
 
 		// Check access
-		if c.Repo.AccessMode == models.ACCESS_MODE_NONE {
+		if c.Repo.AccessMode == db.ACCESS_MODE_NONE {
 			// Redirect to any accessible page if not yet on it
 			if repo.IsPartialPublic() &&
 				(!(isIssuesPage || isWikiPage) ||
@@ -199,7 +199,7 @@ func RepoAssignment(pages ...bool) macaron.Handler {
 		}
 
 		if repo.IsMirror {
-			c.Repo.Mirror, err = models.GetMirrorByRepoID(repo.ID)
+			c.Repo.Mirror, err = db.GetMirrorByRepoID(repo.ID)
 			if err != nil {
 				c.ServerError("GetMirror", err)
 				return
@@ -209,7 +209,7 @@ func RepoAssignment(pages ...bool) macaron.Handler {
 			c.Data["Mirror"] = c.Repo.Mirror
 		}
 
-		gitRepo, err := git.OpenRepository(models.RepoPath(ownerName, repoName))
+		gitRepo, err := git.OpenRepository(db.RepoPath(ownerName, repoName))
 		if err != nil {
 			c.ServerError(fmt.Sprintf("RepoAssignment Invalid repo '%s'", c.Repo.Repository.RepoPath()), err)
 			return
@@ -237,8 +237,8 @@ func RepoAssignment(pages ...bool) macaron.Handler {
 		c.Data["WikiCloneLink"] = repo.WikiCloneLink()
 
 		if c.IsLogged {
-			c.Data["IsWatchingRepo"] = models.IsWatching(c.User.ID, repo.ID)
-			c.Data["IsStaringRepo"] = models.IsStaring(c.User.ID, repo.ID)
+			c.Data["IsWatchingRepo"] = db.IsWatching(c.User.ID, repo.ID)
+			c.Data["IsStaringRepo"] = db.IsStaring(c.User.ID, repo.ID)
 		}
 
 		// repo is bare and display enable
@@ -286,7 +286,7 @@ func RepoRef() macaron.Handler {
 
 		// For API calls.
 		if c.Repo.GitRepo == nil {
-			repoPath := models.RepoPath(c.Repo.Owner.Name, c.Repo.Repository.Name)
+			repoPath := db.RepoPath(c.Repo.Owner.Name, c.Repo.Repository.Name)
 			c.Repo.GitRepo, err = git.OpenRepository(repoPath)
 			if err != nil {
 				c.Handle(500, "RepoRef Invalid repo "+repoPath, err)

+ 4 - 4
pkg/context/user.go → internal/context/user.go

@@ -7,20 +7,20 @@ package context
 import (
 	"gopkg.in/macaron.v1"
 
-	"gogs.io/gogs/models"
-	"gogs.io/gogs/models/errors"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/db/errors"
 )
 
 // ParamsUser is the wrapper type of the target user defined by URL parameter, namely ':username'.
 type ParamsUser struct {
-	*models.User
+	*db.User
 }
 
 // InjectParamsUser returns a handler that retrieves target user based on URL parameter ':username',
 // and injects it as *ParamsUser.
 func InjectParamsUser() macaron.Handler {
 	return func(c *Context) {
-		user, err := models.GetUserByName(c.Params(":username"))
+		user, err := db.GetUserByName(c.Params(":username"))
 		if err != nil {
 			c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 			return

+ 10 - 10
pkg/cron/cron.go → internal/cron/cron.go

@@ -11,8 +11,8 @@ import (
 
 	"github.com/gogs/cron"
 
-	"gogs.io/gogs/models"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/setting"
 )
 
 var c = cron.New()
@@ -23,47 +23,47 @@ func NewContext() {
 		err   error
 	)
 	if setting.Cron.UpdateMirror.Enabled {
-		entry, err = c.AddFunc("Update mirrors", setting.Cron.UpdateMirror.Schedule, models.MirrorUpdate)
+		entry, err = c.AddFunc("Update mirrors", setting.Cron.UpdateMirror.Schedule, db.MirrorUpdate)
 		if err != nil {
 			log.Fatal(2, "Cron.(update mirrors): %v", err)
 		}
 		if setting.Cron.UpdateMirror.RunAtStart {
 			entry.Prev = time.Now()
 			entry.ExecTimes++
-			go models.MirrorUpdate()
+			go db.MirrorUpdate()
 		}
 	}
 	if setting.Cron.RepoHealthCheck.Enabled {
-		entry, err = c.AddFunc("Repository health check", setting.Cron.RepoHealthCheck.Schedule, models.GitFsck)
+		entry, err = c.AddFunc("Repository health check", setting.Cron.RepoHealthCheck.Schedule, db.GitFsck)
 		if err != nil {
 			log.Fatal(2, "Cron.(repository health check): %v", err)
 		}
 		if setting.Cron.RepoHealthCheck.RunAtStart {
 			entry.Prev = time.Now()
 			entry.ExecTimes++
-			go models.GitFsck()
+			go db.GitFsck()
 		}
 	}
 	if setting.Cron.CheckRepoStats.Enabled {
-		entry, err = c.AddFunc("Check repository statistics", setting.Cron.CheckRepoStats.Schedule, models.CheckRepoStats)
+		entry, err = c.AddFunc("Check repository statistics", setting.Cron.CheckRepoStats.Schedule, db.CheckRepoStats)
 		if err != nil {
 			log.Fatal(2, "Cron.(check repository statistics): %v", err)
 		}
 		if setting.Cron.CheckRepoStats.RunAtStart {
 			entry.Prev = time.Now()
 			entry.ExecTimes++
-			go models.CheckRepoStats()
+			go db.CheckRepoStats()
 		}
 	}
 	if setting.Cron.RepoArchiveCleanup.Enabled {
-		entry, err = c.AddFunc("Repository archive cleanup", setting.Cron.RepoArchiveCleanup.Schedule, models.DeleteOldRepositoryArchives)
+		entry, err = c.AddFunc("Repository archive cleanup", setting.Cron.RepoArchiveCleanup.Schedule, db.DeleteOldRepositoryArchives)
 		if err != nil {
 			log.Fatal(2, "Cron.(repository archive cleanup): %v", err)
 		}
 		if setting.Cron.RepoArchiveCleanup.RunAtStart {
 			entry.Prev = time.Now()
 			entry.ExecTimes++
-			go models.DeleteOldRepositoryArchives()
+			go db.DeleteOldRepositoryArchives()
 		}
 	}
 	c.Start()

+ 2 - 2
models/access.go → internal/db/access.go

@@ -2,14 +2,14 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
 
 	log "gopkg.in/clog.v1"
 
-	"gogs.io/gogs/models/errors"
+	"gogs.io/gogs/internal/db/errors"
 )
 
 type AccessMode int

+ 6 - 6
models/action.go → internal/db/action.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -12,17 +12,17 @@ import (
 	"time"
 	"unicode"
 
-	"github.com/unknwon/com"
-	"xorm.io/xorm"
 	"github.com/json-iterator/go"
+	"github.com/unknwon/com"
 	log "gopkg.in/clog.v1"
+	"xorm.io/xorm"
 
 	"github.com/gogs/git-module"
 	api "github.com/gogs/go-gogs-client"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/tool"
 )
 
 type ActionType int

+ 3 - 3
models/admin.go → internal/db/admin.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -11,10 +11,10 @@ import (
 	"time"
 
 	"github.com/unknwon/com"
-	"xorm.io/xorm"
 	log "gopkg.in/clog.v1"
+	"xorm.io/xorm"
 
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/tool"
 )
 
 type NoticeType int

+ 3 - 3
models/attachment.go → internal/db/attachment.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -12,10 +12,10 @@ import (
 	"path"
 	"time"
 
-	"xorm.io/xorm"
 	gouuid "github.com/satori/go.uuid"
+	"xorm.io/xorm"
 
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/setting"
 )
 
 // Attachment represent a attachment of issue/comment/release.

+ 4 - 4
models/comment.go → internal/db/comment.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -10,13 +10,13 @@ import (
 	"time"
 
 	"github.com/unknwon/com"
-	"xorm.io/xorm"
 	log "gopkg.in/clog.v1"
+	"xorm.io/xorm"
 
 	api "github.com/gogs/go-gogs-client"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/markup"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/markup"
 )
 
 // CommentType defines whether a comment is just a simple comment, an action (like close) or a reference.

+ 1 - 1
models/error.go → internal/db/error.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"

+ 0 - 0
models/errors/errors.go → internal/db/errors/errors.go


+ 0 - 0
models/errors/issue.go → internal/db/errors/issue.go


+ 0 - 0
models/errors/login_source.go → internal/db/errors/login_source.go


+ 0 - 0
models/errors/org.go → internal/db/errors/org.go


+ 0 - 0
models/errors/repo.go → internal/db/errors/repo.go


+ 0 - 0
models/errors/token.go → internal/db/errors/token.go


+ 0 - 0
models/errors/two_factor.go → internal/db/errors/two_factor.go


+ 0 - 0
models/errors/user.go → internal/db/errors/user.go


+ 0 - 0
models/errors/user_mail.go → internal/db/errors/user_mail.go


+ 0 - 0
models/errors/webhook.go → internal/db/errors/webhook.go


+ 4 - 4
models/git_diff.go → internal/db/git_diff.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"bytes"
@@ -17,9 +17,9 @@ import (
 
 	"github.com/gogs/git-module"
 
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/template/highlight"
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/template/highlight"
+	"gogs.io/gogs/internal/tool"
 )
 
 type DiffSection struct {

+ 1 - 1
models/git_diff_test.go → internal/db/git_diff_test.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"html/template"

+ 5 - 5
models/issue.go → internal/db/issue.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -10,14 +10,14 @@ import (
 	"time"
 
 	"github.com/unknwon/com"
-	"xorm.io/xorm"
 	log "gopkg.in/clog.v1"
+	"xorm.io/xorm"
 
 	api "github.com/gogs/go-gogs-client"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/tool"
 )
 
 var (

+ 2 - 2
models/issue_label.go → internal/db/issue_label.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -15,7 +15,7 @@ import (
 
 	api "github.com/gogs/go-gogs-client"
 
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/tool"
 )
 
 var labelColorPattern = regexp.MustCompile("#([a-fA-F0-9]{6})")

+ 4 - 4
models/issue_mail.go → internal/db/issue_mail.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -10,9 +10,9 @@ import (
 	"github.com/unknwon/com"
 	log "gopkg.in/clog.v1"
 
-	"gogs.io/gogs/pkg/mailer"
-	"gogs.io/gogs/pkg/markup"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/mailer"
+	"gogs.io/gogs/internal/markup"
+	"gogs.io/gogs/internal/setting"
 )
 
 func (issue *Issue) MailSubject() string {

+ 6 - 6
models/login_source.go → internal/db/login_source.go

@@ -3,7 +3,7 @@
 // license that can be found in the LICENSE file.
 
 // FIXME: Put this file into its own package and separate into different files based on login sources.
-package models
+package db
 
 import (
 	"crypto/tls"
@@ -24,11 +24,11 @@ import (
 	"xorm.io/core"
 	"xorm.io/xorm"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/auth/github"
-	"gogs.io/gogs/pkg/auth/ldap"
-	"gogs.io/gogs/pkg/auth/pam"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/auth/github"
+	"gogs.io/gogs/internal/auth/ldap"
+	"gogs.io/gogs/internal/auth/pam"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/setting"
 )
 
 type LoginType int

+ 2 - 2
models/migrations/migrations.go → internal/db/migrations/migrations.go

@@ -10,10 +10,10 @@ import (
 	"time"
 
 	"github.com/unknwon/com"
-	"xorm.io/xorm"
 	log "gopkg.in/clog.v1"
+	"xorm.io/xorm"
 
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/tool"
 )
 
 const _MIN_DB_VER = 10

+ 0 - 0
models/migrations/v13.go → internal/db/migrations/v13.go


+ 0 - 0
models/migrations/v14.go → internal/db/migrations/v14.go


+ 1 - 1
models/migrations/v15.go → internal/db/migrations/v15.go

@@ -15,7 +15,7 @@ import (
 	"xorm.io/xorm"
 	log "gopkg.in/clog.v1"
 
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/setting"
 )
 
 func generateAndMigrateGitHooks(x *xorm.Engine) (err error) {

+ 1 - 1
models/migrations/v16.go → internal/db/migrations/v16.go

@@ -14,7 +14,7 @@ import (
 
 	"github.com/gogs/git-module"
 
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/setting"
 )
 
 func updateRepositorySizes(x *xorm.Engine) (err error) {

+ 0 - 0
models/migrations/v17.go → internal/db/migrations/v17.go


+ 1 - 1
models/migrations/v18.go → internal/db/migrations/v18.go

@@ -9,7 +9,7 @@ import (
 
 	"xorm.io/xorm"
 
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/setting"
 )
 
 func updateRepositoryDescriptionField(x *xorm.Engine) error {

+ 0 - 0
models/migrations/v19.go → internal/db/migrations/v19.go


+ 3 - 3
models/milestone.go → internal/db/milestone.go

@@ -2,18 +2,18 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
 	"time"
 
-	"xorm.io/xorm"
 	log "gopkg.in/clog.v1"
+	"xorm.io/xorm"
 
 	api "github.com/gogs/go-gogs-client"
 
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/setting"
 )
 
 // Milestone represents a milestone of repository.

+ 6 - 6
models/mirror.go → internal/db/mirror.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"container/list"
@@ -12,16 +12,16 @@ import (
 	"time"
 
 	"github.com/unknwon/com"
-	"xorm.io/xorm"
 	log "gopkg.in/clog.v1"
 	"gopkg.in/ini.v1"
+	"xorm.io/xorm"
 
 	"github.com/gogs/git-module"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/process"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/sync"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/process"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/sync"
 )
 
 var MirrorQueue = sync.NewUniqueQueue(setting.Repository.MirrorQueueLength)

+ 1 - 1
models/mirror_test.go → internal/db/mirror_test.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"testing"

+ 7 - 7
models/models.go → internal/db/models.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"bufio"
@@ -17,15 +17,15 @@ import (
 
 	_ "github.com/denisenkom/go-mssqldb"
 	_ "github.com/go-sql-driver/mysql"
-	"xorm.io/core"
-	"xorm.io/xorm"
 	"github.com/json-iterator/go"
 	_ "github.com/lib/pq"
 	"github.com/unknwon/com"
 	log "gopkg.in/clog.v1"
+	"xorm.io/core"
+	"xorm.io/xorm"
 
-	"gogs.io/gogs/models/migrations"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/db/migrations"
+	"gogs.io/gogs/internal/setting"
 )
 
 // Engine represents a XORM engine or session.
@@ -283,7 +283,7 @@ func DumpDatabase(dirPath string) (err error) {
 	// Purposely create a local variable to not modify global variable
 	tables := append(tables, new(Version))
 	for _, table := range tables {
-		tableName := strings.TrimPrefix(fmt.Sprintf("%T", table), "*models.")
+		tableName := strings.TrimPrefix(fmt.Sprintf("%T", table), "*db.")
 		tableFile := path.Join(dirPath, tableName+".json")
 		f, err := os.Create(tableFile)
 		if err != nil {
@@ -313,7 +313,7 @@ func ImportDatabase(dirPath string, verbose bool) (err error) {
 	// Purposely create a local variable to not modify global variable
 	tables := append(tables, new(Version))
 	for _, table := range tables {
-		tableName := strings.TrimPrefix(fmt.Sprintf("%T", table), "*models.")
+		tableName := strings.TrimPrefix(fmt.Sprintf("%T", table), "*db.")
 		tableFile := path.Join(dirPath, tableName+".json")
 		if !com.IsExist(tableFile) {
 			continue

+ 1 - 1
models/models_sqlite.go → internal/db/models_sqlite.go

@@ -4,7 +4,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	_ "github.com/mattn/go-sqlite3"

+ 1 - 1
models/models_test.go → internal/db/models_test.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"testing"

+ 1 - 1
models/org.go → internal/db/org.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"errors"

+ 2 - 2
models/org_team.go → internal/db/org_team.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -10,7 +10,7 @@ import (
 
 	"xorm.io/xorm"
 
-	"gogs.io/gogs/models/errors"
+	"gogs.io/gogs/internal/db/errors"
 )
 
 const OWNER_TEAM = "Owners"

+ 6 - 6
models/pull.go → internal/db/pull.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -12,16 +12,16 @@ import (
 	"time"
 
 	"github.com/unknwon/com"
-	"xorm.io/xorm"
 	log "gopkg.in/clog.v1"
+	"xorm.io/xorm"
 
 	"github.com/gogs/git-module"
 	api "github.com/gogs/go-gogs-client"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/process"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/sync"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/process"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/sync"
 )
 
 var PullRequestQueue = sync.NewUniqueQueue(setting.Repository.PullRequestQueueLength)

+ 4 - 4
models/release.go → internal/db/release.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -10,14 +10,14 @@ import (
 	"strings"
 	"time"
 
-	"xorm.io/xorm"
 	log "gopkg.in/clog.v1"
+	"xorm.io/xorm"
 
 	"github.com/gogs/git-module"
 	api "github.com/gogs/go-gogs-client"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/process"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/process"
 )
 
 // Release represents a release of repository.

+ 13 - 13
models/repo.go → internal/db/repo.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"bytes"
@@ -19,24 +19,24 @@ import (
 	"strings"
 	"time"
 
-	"github.com/unknwon/cae/zip"
-	"github.com/unknwon/com"
-	"xorm.io/xorm"
 	"github.com/mcuadros/go-version"
 	"github.com/nfnt/resize"
+	"github.com/unknwon/cae/zip"
+	"github.com/unknwon/com"
 	log "gopkg.in/clog.v1"
 	"gopkg.in/ini.v1"
+	"xorm.io/xorm"
 
-	git "github.com/gogs/git-module"
+	"github.com/gogs/git-module"
 	api "github.com/gogs/go-gogs-client"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/avatar"
-	"gogs.io/gogs/pkg/bindata"
-	"gogs.io/gogs/pkg/markup"
-	"gogs.io/gogs/pkg/process"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/sync"
+	"gogs.io/gogs/internal/avatar"
+	"gogs.io/gogs/internal/bindata"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/markup"
+	"gogs.io/gogs/internal/process"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/sync"
 )
 
 // REPO_AVATAR_URL_PREFIX is used to identify a URL is to access repository avatar.
@@ -219,7 +219,7 @@ func (repo *Repository) BeforeUpdate() {
 func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
 	switch colName {
 	case "default_branch":
-		// FIXME: use models migration to solve all at once.
+		// FIXME: use db migration to solve all at once.
 		if len(repo.DefaultBranch) == 0 {
 			repo.DefaultBranch = "master"
 		}

+ 4 - 4
models/repo_branch.go → internal/db/repo_branch.go

@@ -2,17 +2,17 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
 	"strings"
 
-	"github.com/unknwon/com"
 	"github.com/gogs/git-module"
+	"github.com/unknwon/com"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/tool"
 )
 
 type Branch struct {

+ 1 - 1
models/repo_collaboration.go → internal/db/repo_collaboration.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"

+ 6 - 6
models/repo_editor.go → internal/db/repo_editor.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -16,15 +16,15 @@ import (
 	"strings"
 	"time"
 
-	"github.com/unknwon/com"
 	gouuid "github.com/satori/go.uuid"
+	"github.com/unknwon/com"
 
 	"github.com/gogs/git-module"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/process"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/process"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/tool"
 )
 
 const (

+ 1 - 1
models/repo_editor_test.go → internal/db/repo_editor_test.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"os"

+ 5 - 5
models/repo_test.go → internal/db/repo_test.go

@@ -1,19 +1,19 @@
-package models_test
+package db_test
 
 import (
 	"testing"
 
 	. "github.com/smartystreets/goconvey/convey"
 
-	. "gogs.io/gogs/models"
-	"gogs.io/gogs/pkg/markup"
+	"gogs.io/gogs/internal/db"
+	"gogs.io/gogs/internal/markup"
 )
 
 func TestRepo(t *testing.T) {
 	Convey("The metas map", t, func() {
-		var repo = new(Repository)
+		var repo = new(db.Repository)
 		repo.Name = "testrepo"
-		repo.Owner = new(User)
+		repo.Owner = new(db.User)
 		repo.Owner.Name = "testuser"
 		repo.ExternalTrackerFormat = "https://someurl.com/{user}/{repo}/{issue}"
 

+ 4 - 4
models/ssh_key.go → internal/db/ssh_key.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"encoding/base64"
@@ -19,12 +19,12 @@ import (
 	"time"
 
 	"github.com/unknwon/com"
-	"xorm.io/xorm"
 	"golang.org/x/crypto/ssh"
 	log "gopkg.in/clog.v1"
+	"xorm.io/xorm"
 
-	"gogs.io/gogs/pkg/process"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/process"
+	"gogs.io/gogs/internal/setting"
 )
 
 const (

+ 2 - 2
models/ssh_key_test.go → internal/db/ssh_key_test.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -11,7 +11,7 @@ import (
 
 	. "github.com/smartystreets/goconvey/convey"
 
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/setting"
 )
 
 func init() {

+ 5 - 4
models/token.go → internal/db/token.go

@@ -2,15 +2,16 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"time"
 
-	"xorm.io/xorm"
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/tool"
 	gouuid "github.com/satori/go.uuid"
+	"xorm.io/xorm"
+
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/tool"
 )
 
 // AccessToken represents a personal access token.

+ 6 - 6
models/two_factor.go → internal/db/two_factor.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"encoding/base64"
@@ -10,14 +10,14 @@ import (
 	"strings"
 	"time"
 
-	"github.com/unknwon/com"
-	"xorm.io/xorm"
 	"github.com/pquerna/otp/totp"
+	"github.com/unknwon/com"
 	log "gopkg.in/clog.v1"
+	"xorm.io/xorm"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/tool"
 )
 
 // TwoFactor represents a two-factor authentication token.

+ 1 - 1
models/update.go → internal/db/update.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"container/list"

+ 7 - 7
models/user.go → internal/db/user.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"bytes"
@@ -20,19 +20,19 @@ import (
 	"time"
 	"unicode/utf8"
 
-	"github.com/unknwon/com"
-	"xorm.io/xorm"
 	"github.com/nfnt/resize"
+	"github.com/unknwon/com"
 	"golang.org/x/crypto/pbkdf2"
 	log "gopkg.in/clog.v1"
+	"xorm.io/xorm"
 
 	"github.com/gogs/git-module"
 	api "github.com/gogs/go-gogs-client"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/avatar"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/avatar"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/tool"
 )
 
 // USER_AVATAR_URL_PREFIX is used to identify a URL is to access user avatar.

+ 1 - 1
models/user_cache.go → internal/db/user_cache.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 // MailResendCacheKey returns key used for cache mail resend.
 func (u *User) MailResendCacheKey() string {

+ 2 - 2
models/user_mail.go → internal/db/user_mail.go

@@ -2,13 +2,13 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
 	"strings"
 
-	"gogs.io/gogs/models/errors"
+	"gogs.io/gogs/internal/db/errors"
 )
 
 // EmailAdresses is the list of all email addresses of a user. Can contain the

+ 6 - 6
models/webhook.go → internal/db/webhook.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"crypto/hmac"
@@ -14,17 +14,17 @@ import (
 	"strings"
 	"time"
 
-	"xorm.io/xorm"
 	"github.com/json-iterator/go"
 	gouuid "github.com/satori/go.uuid"
 	log "gopkg.in/clog.v1"
+	"xorm.io/xorm"
 
 	api "github.com/gogs/go-gogs-client"
 
-	"gogs.io/gogs/models/errors"
-	"gogs.io/gogs/pkg/httplib"
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/sync"
+	"gogs.io/gogs/internal/db/errors"
+	"gogs.io/gogs/internal/httplib"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/sync"
 )
 
 var HookQueue = sync.NewUniqueQueue(setting.Webhook.QueueLength)

+ 1 - 1
models/webhook_dingtalk.go → internal/db/webhook_dingtalk.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"

+ 2 - 2
models/webhook_discord.go → internal/db/webhook_discord.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -14,7 +14,7 @@ import (
 	"github.com/gogs/git-module"
 	api "github.com/gogs/go-gogs-client"
 
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/setting"
 )
 
 type DiscordEmbedFooterObject struct {

+ 2 - 2
models/webhook_slack.go → internal/db/webhook_slack.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -13,7 +13,7 @@ import (
 	"github.com/gogs/git-module"
 	api "github.com/gogs/go-gogs-client"
 
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/setting"
 )
 
 type SlackMeta struct {

+ 3 - 3
models/wiki.go → internal/db/wiki.go

@@ -2,7 +2,7 @@
 // Use of this source code is governed by a MIT-style
 // license that can be found in the LICENSE file.
 
-package models
+package db
 
 import (
 	"fmt"
@@ -17,8 +17,8 @@ import (
 
 	"github.com/gogs/git-module"
 
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/sync"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/sync"
 )
 
 var wikiWorkingPool = sync.NewExclusivePool()

+ 0 - 0
pkg/form/admin.go → internal/form/admin.go


+ 0 - 0
pkg/form/auth.go → internal/form/auth.go


+ 0 - 0
pkg/form/form.go → internal/form/form.go


+ 0 - 0
pkg/form/org.go → internal/form/org.go


+ 6 - 6
pkg/form/repo.go → internal/form/repo.go

@@ -8,11 +8,11 @@ import (
 	"net/url"
 	"strings"
 
-	"github.com/unknwon/com"
 	"github.com/go-macaron/binding"
+	"github.com/unknwon/com"
 	"gopkg.in/macaron.v1"
 
-	"gogs.io/gogs/models"
+	"gogs.io/gogs/internal/db"
 )
 
 // _______________________________________    _________.______________________ _______________.___.
@@ -56,7 +56,7 @@ func (f *MigrateRepo) Validate(ctx *macaron.Context, errs binding.Errors) bindin
 // and returns composed URL with needed username and password.
 // It also checks if given user has permission when remote address
 // is actually a local path.
-func (f MigrateRepo) ParseRemoteAddr(user *models.User) (string, error) {
+func (f MigrateRepo) ParseRemoteAddr(user *db.User) (string, error) {
 	remoteAddr := strings.TrimSpace(f.CloneAddr)
 
 	// Remote address can be HTTP/HTTPS/Git URL or local path.
@@ -65,16 +65,16 @@ func (f MigrateRepo) ParseRemoteAddr(user *models.User) (string, error) {
 		strings.HasPrefix(remoteAddr, "git://") {
 		u, err := url.Parse(remoteAddr)
 		if err != nil {
-			return "", models.ErrInvalidCloneAddr{IsURLError: true}
+			return "", db.ErrInvalidCloneAddr{IsURLError: true}
 		}
 		if len(f.AuthUsername)+len(f.AuthPassword) > 0 {
 			u.User = url.UserPassword(f.AuthUsername, f.AuthPassword)
 		}
 		remoteAddr = u.String()
 	} else if !user.CanImportLocal() {
-		return "", models.ErrInvalidCloneAddr{IsPermissionDenied: true}
+		return "", db.ErrInvalidCloneAddr{IsPermissionDenied: true}
 	} else if !com.IsDir(remoteAddr) {
-		return "", models.ErrInvalidCloneAddr{IsInvalidPath: true}
+		return "", db.ErrInvalidCloneAddr{IsInvalidPath: true}
 	}
 
 	return remoteAddr, nil

+ 0 - 0
pkg/form/user.go → internal/form/user.go


+ 0 - 0
pkg/httplib/httplib.go → internal/httplib/httplib.go


+ 2 - 2
pkg/mailer/mail.go → internal/mailer/mail.go

@@ -12,8 +12,8 @@ import (
 	"gopkg.in/gomail.v2"
 	"gopkg.in/macaron.v1"
 
-	"gogs.io/gogs/pkg/markup"
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/markup"
+	"gogs.io/gogs/internal/setting"
 )
 
 const (

+ 2 - 2
pkg/mailer/mailer.go → internal/mailer/mailer.go

@@ -18,7 +18,7 @@ import (
 	log "gopkg.in/clog.v1"
 	"gopkg.in/gomail.v2"
 
-	"gogs.io/gogs/pkg/setting"
+	"gogs.io/gogs/internal/setting"
 )
 
 type Message struct {
@@ -52,7 +52,7 @@ func NewMessageFrom(to []string, from, subject, htmlBody string) *Message {
 	}
 	msg.SetBody(contentType, body)
 	if switchedToPlaintext && setting.MailService.AddPlainTextAlt && !setting.MailService.UsePlainText {
-		// The AddAlternative method name is confusing - adding html as an "alternative" will actually cause mail 
+		// The AddAlternative method name is confusing - adding html as an "alternative" will actually cause mail
 		// clients to show it as first priority, and the text "main body" is the 2nd priority fallback.
 		// See: https://godoc.org/gopkg.in/gomail.v2#Message.AddAlternative
 		msg.AddAlternative("text/html", htmlBody)

+ 2 - 2
pkg/markup/markdown.go → internal/markup/markdown.go

@@ -14,8 +14,8 @@ import (
 
 	"github.com/russross/blackfriday"
 
-	"gogs.io/gogs/pkg/setting"
-	"gogs.io/gogs/pkg/tool"
+	"gogs.io/gogs/internal/setting"
+	"gogs.io/gogs/internal/tool"
 )
 
 // IsMarkdownFile reports whether name looks like a Markdown file based on its extension.

+ 2 - 2
pkg/markup/markdown_test.go → internal/markup/markdown_test.go

@@ -12,8 +12,8 @@ import (
 	"github.com/russross/blackfriday"
 	. "github.com/smartystreets/goconvey/convey"
 
-	. "gogs.io/gogs/pkg/markup"
-	"gogs.io/gogs/pkg/setting"
+	. "gogs.io/gogs/internal/markup"
+	"gogs.io/gogs/internal/setting"
 )
 
 func Test_IsMarkdownFile(t *testing.T) {

Some files were not shown because too many files changed in this diff