`)
- if err != nil {
- return
- }
- } else {
- _, err := w.WriteString(``)
- if err != nil {
- return
- }
+ _, err := w.WriteString(``)
+ if err != nil {
+ return
}
// include language-x class as part of commonmark spec
- _, err := w.WriteString(``)
+ _, err = w.WriteString(``)
if err != nil {
return
}
diff --git a/modules/markup/sanitizer.go b/modules/markup/sanitizer.go
index c8f9de33b5fb..5ff26a310942 100644
--- a/modules/markup/sanitizer.go
+++ b/modules/markup/sanitizer.go
@@ -52,8 +52,11 @@ func InitializeSanitizer() {
func createDefaultPolicy() *bluemonday.Policy {
policy := bluemonday.UGCPolicy()
+
+ // For JS code copy and Mermaid loading state
+ policy.AllowAttrs("class").Matching(regexp.MustCompile(`^code-block( is-loading)?$`)).OnElements("pre")
+
// For Chroma markdown plugin
- policy.AllowAttrs("class").Matching(regexp.MustCompile(`^is-loading$`)).OnElements("pre")
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^(chroma )?language-[\w-]+$`)).OnElements("code")
// Checkboxes
diff --git a/modules/migrations/base/comment.go b/modules/migration/comment.go
similarity index 96%
rename from modules/migrations/base/comment.go
rename to modules/migration/comment.go
index 3c32e63b8293..234fea3e82a7 100644
--- a/modules/migrations/base/comment.go
+++ b/modules/migration/comment.go
@@ -3,7 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
-package base
+package migration
import "time"
diff --git a/modules/migrations/base/downloader.go b/modules/migration/downloader.go
similarity index 98%
rename from modules/migrations/base/downloader.go
rename to modules/migration/downloader.go
index 3c581b869900..90e149fb1a40 100644
--- a/modules/migrations/base/downloader.go
+++ b/modules/migration/downloader.go
@@ -3,7 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
-package base
+package migration
import (
"context"
diff --git a/modules/migrations/base/error.go b/modules/migration/error.go
similarity index 97%
rename from modules/migrations/base/error.go
rename to modules/migration/error.go
index 40ddcf4b75e9..b2608aa09fea 100644
--- a/modules/migrations/base/error.go
+++ b/modules/migration/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 base
+package migration
import "fmt"
diff --git a/modules/migrations/base/issue.go b/modules/migration/issue.go
similarity index 98%
rename from modules/migrations/base/issue.go
rename to modules/migration/issue.go
index 7addd1336a28..26812633f9be 100644
--- a/modules/migrations/base/issue.go
+++ b/modules/migration/issue.go
@@ -3,7 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
-package base
+package migration
import "time"
diff --git a/modules/migrations/base/label.go b/modules/migration/label.go
similarity index 95%
rename from modules/migrations/base/label.go
rename to modules/migration/label.go
index 5a66e7620f62..1a04a1dd3a57 100644
--- a/modules/migrations/base/label.go
+++ b/modules/migration/label.go
@@ -3,7 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
-package base
+package migration
// Label defines a standard label information
type Label struct {
diff --git a/modules/migrations/base/messenger.go b/modules/migration/messenger.go
similarity index 95%
rename from modules/migrations/base/messenger.go
rename to modules/migration/messenger.go
index a92f59ef7fae..fa8218cf938e 100644
--- a/modules/migrations/base/messenger.go
+++ b/modules/migration/messenger.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 base
+package migration
// Messenger is a formatting function similar to i18n.Tr
type Messenger func(key string, args ...interface{})
diff --git a/modules/migrations/base/milestone.go b/modules/migration/milestone.go
similarity index 96%
rename from modules/migrations/base/milestone.go
rename to modules/migration/milestone.go
index 921968fcb5b9..209aafe6a732 100644
--- a/modules/migrations/base/milestone.go
+++ b/modules/migration/milestone.go
@@ -3,7 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
-package base
+package migration
import "time"
diff --git a/modules/migrations/base/null_downloader.go b/modules/migration/null_downloader.go
similarity index 99%
rename from modules/migrations/base/null_downloader.go
rename to modules/migration/null_downloader.go
index c64d0e263379..05daf721089a 100644
--- a/modules/migrations/base/null_downloader.go
+++ b/modules/migration/null_downloader.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 base
+package migration
import (
"context"
diff --git a/modules/migrations/base/options.go b/modules/migration/options.go
similarity index 98%
rename from modules/migrations/base/options.go
rename to modules/migration/options.go
index b12e1f94aa4a..1e92a1b0b35f 100644
--- a/modules/migrations/base/options.go
+++ b/modules/migration/options.go
@@ -3,7 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
-package base
+package migration
import "code.gitea.io/gitea/modules/structs"
diff --git a/modules/migrations/base/pullrequest.go b/modules/migration/pullrequest.go
similarity index 99%
rename from modules/migrations/base/pullrequest.go
rename to modules/migration/pullrequest.go
index b51a14e47c52..9ca9a70b7d88 100644
--- a/modules/migrations/base/pullrequest.go
+++ b/modules/migration/pullrequest.go
@@ -3,7 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
-package base
+package migration
import (
"fmt"
diff --git a/modules/migrations/base/reaction.go b/modules/migration/reaction.go
similarity index 94%
rename from modules/migrations/base/reaction.go
rename to modules/migration/reaction.go
index 151949913475..004cff2f94f4 100644
--- a/modules/migrations/base/reaction.go
+++ b/modules/migration/reaction.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 base
+package migration
// Reaction represents a reaction to an issue/pr/comment.
type Reaction struct {
diff --git a/modules/migrations/base/release.go b/modules/migration/release.go
similarity index 98%
rename from modules/migrations/base/release.go
rename to modules/migration/release.go
index 8b4339928bf6..a83f5502cb95 100644
--- a/modules/migrations/base/release.go
+++ b/modules/migration/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 base
+package migration
import (
"io"
diff --git a/modules/migrations/base/repo.go b/modules/migration/repo.go
similarity index 96%
rename from modules/migrations/base/repo.go
rename to modules/migration/repo.go
index 693a96314dc1..d0d62de8da9c 100644
--- a/modules/migrations/base/repo.go
+++ b/modules/migration/repo.go
@@ -3,7 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
-package base
+package migration
// Repository defines a standard repository information
type Repository struct {
diff --git a/modules/migrations/base/retry_downloader.go b/modules/migration/retry_downloader.go
similarity index 99%
rename from modules/migrations/base/retry_downloader.go
rename to modules/migration/retry_downloader.go
index 623bfc86b526..1f034ab0c765 100644
--- a/modules/migrations/base/retry_downloader.go
+++ b/modules/migration/retry_downloader.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 base
+package migration
import (
"context"
diff --git a/modules/migrations/base/review.go b/modules/migration/review.go
similarity index 98%
rename from modules/migrations/base/review.go
rename to modules/migration/review.go
index 6344f0384d64..d6d15002af36 100644
--- a/modules/migrations/base/review.go
+++ b/modules/migration/review.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 base
+package migration
import "time"
diff --git a/modules/migrations/base/uploader.go b/modules/migration/uploader.go
similarity index 97%
rename from modules/migrations/base/uploader.go
rename to modules/migration/uploader.go
index 4d0257df37b0..57571861aaad 100644
--- a/modules/migrations/base/uploader.go
+++ b/modules/migration/uploader.go
@@ -3,7 +3,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
-package base
+package migration
// Uploader uploads all the information of one repository
type Uploader interface {
diff --git a/modules/notification/action/action_test.go b/modules/notification/action/action_test.go
index 705a4fb2f49a..3adcae83fdaa 100644
--- a/modules/notification/action/action_test.go
+++ b/modules/notification/action/action_test.go
@@ -10,19 +10,19 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", "..", ".."))
+ unittest.MainTest(m, filepath.Join("..", "..", ".."))
}
func TestRenameRepoAction(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID}).(*models.Repository)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID}).(*models.Repository)
repo.Owner = user
oldRepoName := repo.Name
@@ -39,10 +39,10 @@ func TestRenameRepoAction(t *testing.T) {
IsPrivate: repo.IsPrivate,
Content: oldRepoName,
}
- db.AssertNotExistsBean(t, actionBean)
+ unittest.AssertNotExistsBean(t, actionBean)
NewNotifier().NotifyRenameRepository(user, repo, oldRepoName)
- db.AssertExistsAndLoadBean(t, actionBean)
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, actionBean)
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
diff --git a/modules/repofiles/action_test.go b/modules/repofiles/action_test.go
index c29cfd686d42..d320413dbbc4 100644
--- a/modules/repofiles/action_test.go
+++ b/modules/repofiles/action_test.go
@@ -8,7 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -16,7 +16,7 @@ import (
)
func TestUpdateIssuesCommit(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
pushCommits := []*repository.PushCommit{
{
Sha1: "abcdef1",
@@ -44,8 +44,8 @@ func TestUpdateIssuesCommit(t *testing.T) {
},
}
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
repo.Owner = user
commentBean := &models.Comment{
@@ -56,12 +56,12 @@ func TestUpdateIssuesCommit(t *testing.T) {
}
issueBean := &models.Issue{RepoID: repo.ID, Index: 4}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
- db.AssertExistsAndLoadBean(t, commentBean)
- db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, commentBean)
+ unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
// Test that push to a non-default branch closes no issue.
pushCommits = []*repository.PushCommit{
@@ -74,7 +74,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
Message: "close #1",
},
}
- repo = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
+ repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
commentBean = &models.Comment{
Type: models.CommentTypeCommitRef,
CommitSHA: "abcdef1",
@@ -83,12 +83,12 @@ func TestUpdateIssuesCommit(t *testing.T) {
}
issueBean = &models.Issue{RepoID: repo.ID, Index: 1}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, "non-existing-branch"))
- db.AssertExistsAndLoadBean(t, commentBean)
- db.AssertNotExistsBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
pushCommits = []*repository.PushCommit{
{
@@ -100,7 +100,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
Message: "close " + setting.AppURL + repo.FullName() + "/pulls/1",
},
}
- repo = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
+ repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
commentBean = &models.Comment{
Type: models.CommentTypeCommitRef,
CommitSHA: "abcdef3",
@@ -109,16 +109,16 @@ func TestUpdateIssuesCommit(t *testing.T) {
}
issueBean = &models.Issue{RepoID: repo.ID, Index: 1}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
- db.AssertExistsAndLoadBean(t, commentBean)
- db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, commentBean)
+ unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
func TestUpdateIssuesCommit_Colon(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
pushCommits := []*repository.PushCommit{
{
Sha1: "abcdef2",
@@ -130,21 +130,21 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
},
}
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
repo.Owner = user
issueBean := &models.Issue{RepoID: repo.ID, Index: 4}
- db.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
+ unittest.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
- db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Test that push to a non-default branch closes an issue.
pushCommits := []*repository.PushCommit{
@@ -158,7 +158,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
},
}
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
commentBean := &models.Comment{
Type: models.CommentTypeCommitRef,
CommitSHA: "abcdef1",
@@ -168,17 +168,17 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
issueBean := &models.Issue{RepoID: repo.ID, Index: 2, ID: 7}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, issueBean, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, "non-existing-branch"))
- db.AssertExistsAndLoadBean(t, commentBean)
- db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, commentBean)
+ unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Test that a push to default branch closes issue in another repo
// If the user also has push permissions to that repo
@@ -193,7 +193,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
},
}
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
commentBean := &models.Comment{
Type: models.CommentTypeCommitRef,
CommitSHA: "abcdef1",
@@ -203,17 +203,17 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
issueBean := &models.Issue{RepoID: 1, Index: 1, ID: 1}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, issueBean, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
- db.AssertExistsAndLoadBean(t, commentBean)
- db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, commentBean)
+ unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Test that a push to default branch closes issue in another repo
// If the user also has push permissions to that repo
@@ -228,7 +228,7 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
},
}
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
commentBean := &models.Comment{
Type: models.CommentTypeCommitRef,
CommitSHA: "abcdef1",
@@ -238,17 +238,17 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
issueBean := &models.Issue{RepoID: 1, Index: 1, ID: 1}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, issueBean, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
- db.AssertExistsAndLoadBean(t, commentBean)
- db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertExistsAndLoadBean(t, commentBean)
+ unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 10}).(*models.User)
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 10}).(*models.User)
// Test that a push with close reference *can not* close issue
// If the committer doesn't have push rights in that repo
@@ -271,7 +271,7 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
},
}
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 6}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 6}).(*models.Repository)
commentBean := &models.Comment{
Type: models.CommentTypeCommitRef,
CommitSHA: "abcdef3",
@@ -287,12 +287,12 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
issueBean := &models.Issue{RepoID: 3, Index: 1, ID: 6}
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, commentBean2)
- db.AssertNotExistsBean(t, issueBean, "is_closed=1")
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, commentBean2)
+ unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
- db.AssertNotExistsBean(t, commentBean)
- db.AssertNotExistsBean(t, commentBean2)
- db.AssertNotExistsBean(t, issueBean, "is_closed=1")
- models.CheckConsistencyFor(t, &models.Action{})
+ unittest.AssertNotExistsBean(t, commentBean)
+ unittest.AssertNotExistsBean(t, commentBean2)
+ unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
+ unittest.CheckConsistencyFor(t, &models.Action{})
}
diff --git a/modules/repofiles/blob_test.go b/modules/repofiles/blob_test.go
index 5238dd6e74f4..c219892aec8e 100644
--- a/modules/repofiles/blob_test.go
+++ b/modules/repofiles/blob_test.go
@@ -7,7 +7,8 @@ package repofiles
import (
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
+
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
@@ -15,7 +16,7 @@ import (
)
func TestGetBlobBySHA(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
test.LoadRepo(t, ctx, 1)
test.LoadRepoCommit(t, ctx)
diff --git a/modules/repofiles/content_test.go b/modules/repofiles/content_test.go
index f68460d7ec3f..e3230698bcec 100644
--- a/modules/repofiles/content_test.go
+++ b/modules/repofiles/content_test.go
@@ -8,7 +8,8 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
+
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
@@ -16,7 +17,7 @@ import (
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
func getExpectedReadmeContentsResponse() *api.ContentsResponse {
@@ -49,7 +50,7 @@ func getExpectedReadmeContentsResponse() *api.ContentsResponse {
}
func TestGetContents(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -77,7 +78,7 @@ func TestGetContents(t *testing.T) {
}
func TestGetContentsOrListForDir(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -112,7 +113,7 @@ func TestGetContentsOrListForDir(t *testing.T) {
}
func TestGetContentsOrListForFile(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -140,7 +141,7 @@ func TestGetContentsOrListForFile(t *testing.T) {
}
func TestGetContentsErrors(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -171,7 +172,7 @@ func TestGetContentsErrors(t *testing.T) {
}
func TestGetContentsOrListErrors(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -202,7 +203,7 @@ func TestGetContentsOrListErrors(t *testing.T) {
}
func TestGetContentsOrListOfEmptyRepos(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo15")
ctx.SetParams(":id", "15")
test.LoadRepo(t, ctx, 15)
diff --git a/modules/repofiles/diff_test.go b/modules/repofiles/diff_test.go
index aeb4f76a4576..463ce4ec6744 100644
--- a/modules/repofiles/diff_test.go
+++ b/modules/repofiles/diff_test.go
@@ -8,7 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/services/gitdiff"
@@ -16,7 +16,7 @@ import (
)
func TestGetDiffPreview(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -129,7 +129,7 @@ func TestGetDiffPreview(t *testing.T) {
}
func TestGetDiffPreviewErrors(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
diff --git a/modules/repofiles/file_test.go b/modules/repofiles/file_test.go
index 2974056549e3..54205a89c7e6 100644
--- a/modules/repofiles/file_test.go
+++ b/modules/repofiles/file_test.go
@@ -7,7 +7,7 @@ package repofiles
import (
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -81,7 +81,7 @@ func getExpectedFileResponse() *api.FileResponse {
}
func TestGetFileResponseFromCommit(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
diff --git a/modules/repofiles/tree_test.go b/modules/repofiles/tree_test.go
index 9e2efa4216fa..512313c43b36 100644
--- a/modules/repofiles/tree_test.go
+++ b/modules/repofiles/tree_test.go
@@ -7,7 +7,8 @@ package repofiles
import (
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
+
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
@@ -15,7 +16,7 @@ import (
)
func TestGetTreeBySHA(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
test.LoadRepo(t, ctx, 1)
test.LoadRepoCommit(t, ctx)
diff --git a/modules/repository/commits_test.go b/modules/repository/commits_test.go
index c62ad584496d..0d6c2e4c5ce6 100644
--- a/modules/repository/commits_test.go
+++ b/modules/repository/commits_test.go
@@ -11,13 +11,13 @@ import (
"time"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
"github.com/stretchr/testify/assert"
)
func TestPushCommits_ToAPIPayloadCommits(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
pushCommits := NewPushCommits()
pushCommits.Commits = []*PushCommit{
@@ -48,7 +48,7 @@ func TestPushCommits_ToAPIPayloadCommits(t *testing.T) {
}
pushCommits.HeadCommit = &PushCommit{Sha1: "69554a6"}
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
payloadCommits, headCommit, err := pushCommits.ToAPIPayloadCommits(repo.RepoPath(), "/user2/repo16")
assert.NoError(t, err)
assert.Len(t, payloadCommits, 3)
@@ -100,7 +100,7 @@ func TestPushCommits_ToAPIPayloadCommits(t *testing.T) {
}
func TestPushCommits_AvatarLink(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
pushCommits := NewPushCommits()
pushCommits.Commits = []*PushCommit{
diff --git a/modules/repository/create_test.go b/modules/repository/create_test.go
index 040c061d9209..2e27ab0d7d71 100644
--- a/modules/repository/create_test.go
+++ b/modules/repository/create_test.go
@@ -9,17 +9,17 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
)
func TestIncludesAllRepositoriesTeams(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
testTeamRepositories := func(teamID int64, repoIds []int64) {
- team := db.AssertExistsAndLoadBean(t, &models.Team{ID: teamID}).(*models.Team)
+ team := unittest.AssertExistsAndLoadBean(t, &models.Team{ID: teamID}).(*models.Team)
assert.NoError(t, team.GetRepositories(&models.SearchTeamOptions{}), "%s: GetRepositories", team.Name)
assert.Len(t, team.Repos, team.NumRepos, "%s: len repo", team.Name)
assert.Len(t, team.Repos, len(repoIds), "%s: repo count", team.Name)
diff --git a/modules/repository/init.go b/modules/repository/init.go
index 5a1ff7e98bc6..076dbf748e68 100644
--- a/modules/repository/init.go
+++ b/modules/repository/init.go
@@ -196,92 +196,6 @@ func checkInitRepository(owner, name string) (err error) {
return nil
}
-func adoptRepository(ctx context.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
- isExist, err := util.IsExist(repoPath)
- if err != nil {
- log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
- return err
- }
- if !isExist {
- return fmt.Errorf("adoptRepository: path does not already exist: %s", repoPath)
- }
-
- if err := createDelegateHooks(repoPath); err != nil {
- return fmt.Errorf("createDelegateHooks: %v", err)
- }
-
- // Re-fetch the repository from database before updating it (else it would
- // override changes that were done earlier with sql)
- if repo, err = models.GetRepositoryByIDCtx(ctx, repo.ID); err != nil {
- return fmt.Errorf("getRepositoryByID: %v", err)
- }
-
- repo.IsEmpty = false
- gitRepo, err := git.OpenRepository(repo.RepoPath())
- if err != nil {
- return fmt.Errorf("openRepository: %v", err)
- }
- defer gitRepo.Close()
- if len(opts.DefaultBranch) > 0 {
- repo.DefaultBranch = opts.DefaultBranch
-
- if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
- return fmt.Errorf("setDefaultBranch: %v", err)
- }
- } else {
- repo.DefaultBranch, err = gitRepo.GetDefaultBranch()
- if err != nil {
- repo.DefaultBranch = setting.Repository.DefaultBranch
- if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
- return fmt.Errorf("setDefaultBranch: %v", err)
- }
- }
-
- repo.DefaultBranch = strings.TrimPrefix(repo.DefaultBranch, git.BranchPrefix)
- }
- branches, _, _ := gitRepo.GetBranches(0, 0)
- found := false
- hasDefault := false
- hasMaster := false
- hasMain := false
- for _, branch := range branches {
- if branch == repo.DefaultBranch {
- found = true
- break
- } else if branch == setting.Repository.DefaultBranch {
- hasDefault = true
- } else if branch == "master" {
- hasMaster = true
- } else if branch == "main" {
- hasMain = true
- }
- }
- if !found {
- if hasDefault {
- repo.DefaultBranch = setting.Repository.DefaultBranch
- } else if hasMaster {
- repo.DefaultBranch = "master"
- } else if hasMain {
- repo.DefaultBranch = "main"
- } else if len(branches) > 0 {
- repo.DefaultBranch = branches[0]
- } else {
- repo.IsEmpty = true
- repo.DefaultBranch = setting.Repository.DefaultBranch
- }
-
- if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
- return fmt.Errorf("setDefaultBranch: %v", err)
- }
- }
-
- if err = models.UpdateRepositoryCtx(ctx, repo, false); err != nil {
- return fmt.Errorf("updateRepository: %v", err)
- }
-
- return nil
-}
-
// InitRepository initializes README and .gitignore if needed.
func initRepository(ctx context.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
if err = checkInitRepository(repo.OwnerName, repo.Name); err != nil {
diff --git a/modules/repository/main_test.go b/modules/repository/main_test.go
index 91d0d36ca026..262d3394818b 100644
--- a/modules/repository/main_test.go
+++ b/modules/repository/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
diff --git a/modules/repository/repo.go b/modules/repository/repo.go
index 05306218de8b..871ba617ad20 100644
--- a/modules/repository/repo.go
+++ b/modules/repository/repo.go
@@ -18,7 +18,7 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
- migration "code.gitea.io/gitea/modules/migrations/base"
+ "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
diff --git a/modules/structs/repo.go b/modules/structs/repo.go
index 313a982f43d6..8482a2128d7f 100644
--- a/modules/structs/repo.go
+++ b/modules/structs/repo.go
@@ -242,13 +242,14 @@ type GitServiceType int
// enumerate all GitServiceType
const (
- NotMigrated GitServiceType = iota // 0 not migrated from external sites
- PlainGitService // 1 plain git service
- GithubService // 2 github.com
- GiteaService // 3 gitea service
- GitlabService // 4 gitlab service
- GogsService // 5 gogs service
- OneDevService // 6 onedev service
+ NotMigrated GitServiceType = iota // 0 not migrated from external sites
+ PlainGitService // 1 plain git service
+ GithubService // 2 github.com
+ GiteaService // 3 gitea service
+ GitlabService // 4 gitlab service
+ GogsService // 5 gogs service
+ OneDevService // 6 onedev service
+ GitBucketService // 7 gitbucket service
)
// Name represents the service type's name
@@ -270,6 +271,8 @@ func (gt GitServiceType) Title() string {
return "Gogs"
case OneDevService:
return "OneDev"
+ case GitBucketService:
+ return "GitBucket"
case PlainGitService:
return "Git"
}
@@ -326,5 +329,6 @@ var (
GiteaService,
GogsService,
OneDevService,
+ GitBucketService,
}
)
diff --git a/modules/task/migrate.go b/modules/task/migrate.go
index 52f4bb91cf72..100aac1967e3 100644
--- a/modules/task/migrate.go
+++ b/modules/task/migrate.go
@@ -14,13 +14,13 @@ import (
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/migrations"
- migration "code.gitea.io/gitea/modules/migrations/base"
+ "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
+ "code.gitea.io/gitea/services/migrations"
)
func handleCreateError(owner *models.User, err error) error {
@@ -58,6 +58,9 @@ func runMigrateTask(t *models.Task) (err error) {
t.EndTime = timeutil.TimeStampNow()
t.Status = structs.TaskStatusFailed
t.Message = err.Error()
+ // Ensure that the repo loaded before we zero out the repo ID from the task - thus ensuring that we can delete it
+ _ = t.LoadRepo()
+
t.RepoID = 0
if err := t.UpdateCols("status", "errors", "repo_id", "end_time"); err != nil {
log.Error("Task UpdateCols failed: %v", err)
diff --git a/modules/task/task.go b/modules/task/task.go
index 4e782869f93f..f538b36efc06 100644
--- a/modules/task/task.go
+++ b/modules/task/task.go
@@ -11,7 +11,7 @@ import (
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/queue"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/secret"
@@ -90,7 +90,7 @@ func CreateMigrateTask(doer, u *models.User, opts base.MigrateOptions) (*models.
return nil, err
}
- var task = models.Task{
+ var task = &models.Task{
DoerID: doer.ID,
OwnerID: u.ID,
Type: structs.TaskTypeMigrateRepo,
@@ -98,7 +98,7 @@ func CreateMigrateTask(doer, u *models.User, opts base.MigrateOptions) (*models.
PayloadContent: string(bs),
}
- if err := models.CreateTask(&task); err != nil {
+ if err := models.CreateTask(task); err != nil {
return nil, err
}
@@ -126,5 +126,5 @@ func CreateMigrateTask(doer, u *models.User, opts base.MigrateOptions) (*models.
return nil, err
}
- return &task, nil
+ return task, nil
}
diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go
index 02723d8c3814..eb1a54d86f88 100644
--- a/modules/test/context_tests.go
+++ b/modules/test/context_tests.go
@@ -14,7 +14,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/web/middleware"
@@ -53,7 +53,7 @@ func MockContext(t *testing.T, path string) *context.Context {
// LoadRepo load a repo into a test context.
func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) {
ctx.Repo = &context.Repository{}
- ctx.Repo.Repository = db.AssertExistsAndLoadBean(t, &models.Repository{ID: repoID}).(*models.Repository)
+ ctx.Repo.Repository = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: repoID}).(*models.Repository)
var err error
ctx.Repo.Owner, err = models.GetUserByID(ctx.Repo.Repository.OwnerID)
assert.NoError(t, err)
@@ -78,7 +78,7 @@ func LoadRepoCommit(t *testing.T, ctx *context.Context) {
// LoadUser load a user into a test context.
func LoadUser(t *testing.T, ctx *context.Context, userID int64) {
- ctx.User = db.AssertExistsAndLoadBean(t, &models.User{ID: userID}).(*models.User)
+ ctx.User = unittest.AssertExistsAndLoadBean(t, &models.User{ID: userID}).(*models.User)
}
// LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has
diff --git a/options/license/BSD-1-Clause b/options/license/BSD-1-Clause
index 8f8d606c656f..4005b63def76 100644
--- a/options/license/BSD-1-Clause
+++ b/options/license/BSD-1-Clause
@@ -1,20 +1,7 @@
-Copyright (c) [Year]
-[Name of Organization]. All rights reserved.
+Copyright (c) . All rights reserved.
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-THIS SOFTWARE IS PROVIDED BY [Name of Organization] ``AS IS'' AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL [Name of Organization] BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
-OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGE.
+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/options/license/COIL-1.0 b/options/license/COIL-1.0
new file mode 100644
index 000000000000..c24c539e3184
--- /dev/null
+++ b/options/license/COIL-1.0
@@ -0,0 +1,30 @@
+# Copyfree Open Innovation License
+
+This is version 1.0 of the Copyfree Open Innovation License.
+
+## Terms and Conditions
+
+Redistributions, modified or unmodified, in whole or in part, must retain
+applicable notices of copyright or other legal privilege, these conditions, and
+the following license terms and disclaimer. Subject to these conditions, each
+holder of copyright or other legal privileges, author or assembler, and
+contributor of this work, henceforth "licensor", hereby grants to any person
+who obtains a copy of this work in any form:
+
+1. Permission to reproduce, modify, distribute, publish, sell, sublicense, use,
+and/or otherwise deal in the licensed material without restriction.
+
+2. A perpetual, worldwide, non-exclusive, royalty-free, gratis, irrevocable
+patent license to make, have made, provide, transfer, import, use, and/or
+otherwise deal in the licensed material without restriction, for any and all
+patents held by such licensor and necessarily infringed by the form of the work
+upon distribution of that licensor's contribution to the work under the terms
+of this license.
+
+NO WARRANTY OF ANY KIND IS IMPLIED BY, OR SHOULD BE INFERRED FROM, THIS LICENSE
+OR THE ACT OF DISTRIBUTION UNDER THE TERMS OF THIS LICENSE, INCLUDING BUT NOT
+LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, ASSEMBLERS, OR HOLDERS OF
+COPYRIGHT OR OTHER LEGAL PRIVILEGE BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
+LIABILITY, WHETHER IN ACTION OF CONTRACT, TORT, OR OTHERWISE ARISING FROM, OUT
+OF, OR IN CONNECTION WITH THE WORK OR THE USE OF OR OTHER DEALINGS IN THE WORK.
diff --git a/options/license/Community-Spec-1.0 b/options/license/Community-Spec-1.0
new file mode 100644
index 000000000000..cdf7c64c07cd
--- /dev/null
+++ b/options/license/Community-Spec-1.0
@@ -0,0 +1,293 @@
+Community Specification License 1.0
+
+The Purpose of this License. This License sets forth the terms under which
+1) Contributor will participate in and contribute to the development
+of specifications, standards, best practices, guidelines, and other
+similar materials under this Working Group, and 2) how the materials
+developed under this License may be used. It is not intended for source
+code. Capitalized terms are defined in the License’s last section.
+
+1. Copyright.
+
+1.1. Copyright License. Contributor grants everyone a non-sublicensable,
+perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+(except as expressly stated in this License) copyright license, without
+any obligation for accounting, to reproduce, prepare derivative works
+of, publicly display, publicly perform, and distribute any materials
+it submits to the full extent of its copyright interest in those
+materials. Contributor also acknowledges that the Working Group may
+exercise copyright rights in the Specification, including the rights to
+submit the Specification to another standards organization.
+
+1.2. Copyright Attribution. As a condition, anyone exercising this
+copyright license must include attribution to the Working Group in any
+derivative work based on materials developed by the Working Group.
+That attribution must include, at minimum, the material’s name,
+version number, and source from where the materials were retrieved.
+Attribution is not required for implementations of the Specification.
+
+2. Patents.
+
+2.1. Patent License.
+
+2.1.1. As a Result of Contributions.
+
+2.1.1.1. As a Result of Contributions to Draft Specifications.
+Contributor grants Licensee a non-sublicensable, perpetual, worldwide,
+non-exclusive, no-charge, royalty-free, irrevocable (except as
+expressly stated in this License) license to its Necessary Claims in 1)
+Contributor’s Contributions and 2) to the Draft Specification that
+is within Scope as of the date of that Contribution, in both cases for
+Licensee’s Implementation of the Draft Specification, except for those
+patent claims excluded by Contributor under Section 3.
+
+2.1.1.2. For Approved Specifications. Contributor grants Licensee a
+non-sublicensable, perpetual, worldwide, non-exclusive, no-charge,
+royalty-free, irrevocable (except as expressly stated in this License)
+license to its Necessary Claims included the Approved Specification
+that are within Scope for Licensee’s Implementation of the Approved
+Specification, except for those patent claims excluded by Contributor
+under Section 3.
+
+2.1.2. Patent Grant from Licensee. Licensee grants each other Licensee
+a non-sublicensable, perpetual, worldwide, non-exclusive, no-charge,
+royalty-free, irrevocable (except as expressly stated in this License)
+license to its Necessary Claims for its Implementation, except for those
+patent claims excluded under Section 3.
+
+2.1.3. Licensee Acceptance. The patent grants set forth in Section 2.1
+extend only to Licensees that have indicated their agreement to this
+License as follows:
+
+2.1.3.1. Source Code Distributions. For distribution in source code,
+by including this License in the root directory of the source code with
+the Implementation;
+
+2.1.3.2. Non-Source Code Distributions. For distribution in any form
+other than source code, by including this License in the documentation,
+legal notices, via notice in the software, and/or other written materials
+provided with the Implementation; or
+
+2.1.3.3. Via Notices.md. By issuing pull request or commit to the
+Specification’s repository’s Notices.md file by the Implementer’s
+authorized representative, including the Implementer’s name, authorized
+individual and system identifier, and Specification version.
+
+2.1.4. Defensive Termination. If any Licensee files or maintains a
+claim in a court asserting that a Necessary Claim is infringed by an
+Implementation, any licenses granted under this License to the Licensee
+are immediately terminated unless 1) that claim is directly in response
+to a claim against Licensee regarding an Implementation, or 2) that claim
+was brought to enforce the terms of this License, including intervention
+in a third-party action by a Licensee.
+
+2.1.5. Additional Conditions. This License is not an assurance (i)
+that any of Contributor’s copyrights or issued patent claims cover
+an Implementation of the Specification or are enforceable or (ii) that
+an Implementation of the Specification would not infringe intellectual
+property rights of any third party.
+
+2.2. Patent Licensing Commitment. In addition to the rights granted
+in Section 2.1, Contributor agrees to grant everyone a no charge,
+royalty-free license on reasonable and non-discriminatory terms
+to Contributor’s Necessary Claims that are within Scope for:
+1) Implementations of a Draft Specification, where such license
+applies only to those Necessary Claims infringed by implementing
+Contributor's Contribution(s) included in that Draft Specification,
+and 2) Implementations of the Approved Specification.
+
+This patent licensing commitment does not apply to those claims subject
+to Contributor’s Exclusion Notice under Section 3.
+
+2.3. Effect of Withdrawal. Contributor may withdraw from the Working Group
+by issuing a pull request or commit providing notice of withdrawal to
+the Working Group repository’s Notices.md file. All of Contributor’s
+existing commitments and obligations with respect to the Working Group
+up to the date of that withdrawal notice will remain in effect, but no
+new obligations will be incurred.
+
+2.4. Binding Encumbrance. This License is binding on any future owner,
+assignee, or party who has been given the right to enforce any Necessary
+Claims against third parties.
+
+3. Patent Exclusion.
+
+3.1. As a Result of Contributions. Contributor may exclude Necessary
+Claims from its licensing commitments incurred under Section 2.1.1
+by issuing an Exclusion Notice within 45 days of the date of that
+Contribution. Contributor may not issue an Exclusion Notice for any
+material that has been included in a Draft Deliverable for more than 45
+days prior to the date of that Contribution.
+
+3.2. As a Result of a Draft Specification Becoming an Approved
+Specification. Prior to the adoption of a Draft Specification as an
+Approved Specification, Contributor may exclude Necessary Claims from
+its licensing commitments under this Agreement by issuing an Exclusion
+Notice. Contributor may not issue an Exclusion Notice for patents that
+were eligible to have been excluded pursuant to Section 3.1.
+
+4. Source Code License. Any source code developed by the Working Group is
+solely subject the source code license included in the Working Group’s
+repository for that code. If no source code license is included, the
+source code will be subject to the MIT License.
+
+5. No Other Rights. Except as specifically set forth in this License, no
+other express or implied patent, trademark, copyright, or other rights are
+granted under this License, including by implication, waiver, or estoppel.
+
+6. Antitrust Compliance. Contributor acknowledge that it may compete
+with other participants in various lines of business and that it is
+therefore imperative that they and their respective representatives
+act in a manner that does not violate any applicable antitrust laws and
+regulations. This License does not restrict any Contributor from engaging
+in similar specification development projects. Each Contributor may
+design, develop, manufacture, acquire or market competitive deliverables,
+products, and services, and conduct its business, in whatever way it
+chooses. No Contributor is obligated to announce or market any products
+or services. Without limiting the generality of the foregoing, the
+Contributors agree not to have any discussion relating to any product
+pricing, methods or channels of product distribution, division of markets,
+allocation of customers or any other topic that should not be discussed
+among competitors under the auspices of the Working Group.
+
+7. Non-Circumvention. Contributor agrees that it will not intentionally
+take or willfully assist any third party to take any action for the
+purpose of circumventing any obligations under this License.
+
+8. Representations, Warranties and Disclaimers.
+
+8.1. Representations, Warranties and Disclaimers. Contributor and Licensee
+represents and warrants that 1) it is legally entitled to grant the
+rights set forth in this License and 2) it will not intentionally include
+any third party materials in any Contribution unless those materials are
+available under terms that do not conflict with this License. IN ALL OTHER
+RESPECTS ITS CONTRIBUTIONS ARE PROVIDED "AS IS." The entire risk as to
+implementing or otherwise using the Contribution or the Specification
+is assumed by the implementer and user. Except as stated herein,
+CONTRIBUTOR AND LICENSEE EXPRESSLY DISCLAIM ANY WARRANTIES (EXPRESS,
+IMPLIED, OR OTHERWISE), INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY,
+NON-INFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, CONDITIONS OF QUALITY,
+OR TITLE, RELATED TO THE CONTRIBUTION OR THE SPECIFICATION. IN NO EVENT
+WILL ANY PARTY BE LIABLE TO ANY OTHER PARTY FOR LOST PROFITS OR ANY
+FORM OF INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF
+ANY CHARACTER FROM ANY CAUSES OF ACTION OF ANY KIND WITH RESPECT TO
+THIS AGREEMENT, WHETHER BASED ON BREACH OF CONTRACT, TORT (INCLUDING
+NEGLIGENCE), OR OTHERWISE, AND WHETHER OR NOT THE OTHER PARTY HAS BEEN
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Any obligations regarding
+the transfer, successors in interest, or assignment of Necessary Claims
+will be satisfied if Contributor or Licensee notifies the transferee
+or assignee of any patent that it knows contains Necessary Claims or
+necessary claims under this License. Nothing in this License requires
+Contributor to undertake a patent search. If Contributor is 1) employed by
+or acting on behalf of an employer, 2) is making a Contribution under the
+direction or control of a third party, or 3) is making the Contribution
+as a consultant, contractor, or under another similar relationship with
+a third party, Contributor represents that they have been authorized by
+that party to enter into this License on its behalf.
+
+8.2. Distribution Disclaimer. Any distributions of technical
+information to third parties must include a notice materially similar
+to the following: “THESE MATERIALS ARE PROVIDED “AS IS.” The
+Contributors and Licensees expressly disclaim any warranties (express,
+implied, or otherwise), including implied warranties of merchantability,
+non-infringement, fitness for a particular purpose, or title, related to
+the materials. The entire risk as to implementing or otherwise using the
+materials is assumed by the implementer and user. IN NO EVENT WILL THE
+CONTRIBUTORS OR LICENSEES BE LIABLE TO ANY OTHER PARTY FOR LOST PROFITS
+OR ANY FORM OF INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+OF ANY CHARACTER FROM ANY CAUSES OF ACTION OF ANY KIND WITH RESPECT TO
+THIS DELIVERABLE OR ITS GOVERNING AGREEMENT, WHETHER BASED ON BREACH OF
+CONTRACT, TORT (INCLUDING NEGLIGENCE), OR OTHERWISE, AND WHETHER OR NOT
+THE OTHER MEMBER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.”
+
+9. Definitions.
+
+9.1. Affiliate. “Affiliate” means an entity that directly or
+indirectly Controls, is Controlled by, or is under common Control of
+that party.
+
+9.2. Approved Specification. “Approved Specification” means the final
+version and contents of any Draft Specification designated as an Approved
+Specification as set forth in the accompanying Governance.md file.
+
+9.3. Contribution. “Contribution” means any original work of
+authorship, including any modifications or additions to an existing
+work, that Contributor submits for inclusion in a Draft Specification,
+which is included in a Draft Specification or Approved Specification.
+
+9.4. Contributor. “Contributor” means any person or entity that has
+indicated its acceptance of the License 1) by making a Contribution to
+the Specification, or 2) by entering into the Community Specification
+Contributor License Agreement for the Specification. Contributor includes
+its Affiliates, assigns, agents, and successors in interest.
+
+9.5. Control. “Control” means direct or indirect control of more
+than 50% of the voting power to elect directors of that corporation,
+or for any other entity, the power to direct management of such entity.
+
+9.6. Draft Specification. “Draft Specification” means all versions
+of the material (except an Approved Specification) developed by this
+Working Group for the purpose of creating, commenting on, revising,
+updating, modifying, or adding to any document that is to be considered
+for inclusion in the Approved Specification.
+
+9.7. Exclusion Notice. “Exclusion Notice” means a written notice
+made by making a pull request or commit to the repository’s Notices.md
+file that identifies patents that Contributor is excluding from its
+patent licensing commitments under this License. The Exclusion Notice
+for issued patents and published applications must include the Draft
+Specification’s name, patent number(s) or title and application
+number(s), as the case may be, for each of the issued patent(s) or
+pending patent application(s) that the Contributor is excluding from the
+royalty-free licensing commitment set forth in this License. If an issued
+patent or pending patent application that may contain Necessary Claims
+is not set forth in the Exclusion Notice, those Necessary Claims shall
+continue to be subject to the licensing commitments under this License.
+The Exclusion Notice for unpublished patent applications must provide
+either: (i) the text of the filed application; or (ii) identification
+of the specific part(s) of the Draft Specification whose implementation
+makes the excluded claim a Necessary Claim. If (ii) is chosen, the
+effect of the exclusion will be limited to the identified part(s) of
+the Draft Specification.
+
+9.8. Implementation. “Implementation” means making, using, selling,
+offering for sale, importing or distributing any implementation of the
+Specification 1) only to the extent it implements the Specification and 2)
+so long as all required portions of the Specification are implemented.
+
+9.9. License. “License” means this Community Specification License.
+
+9.10. Licensee. “Licensee” means any person or entity that has
+indicated its acceptance of the License as set forth in Section 2.1.3.
+Licensee includes its Affiliates, assigns, agents, and successors in
+interest.
+
+9.11. Necessary Claims. “Necessary Claims” are those patent claims, if
+any, that a party owns or controls, including those claims later acquired,
+that are necessary to implement the required portions (including the
+required elements of optional portions) of the Specification that are
+described in detail and not merely referenced in the Specification.
+
+9.12. Specification. “Specification” means a Draft Specification
+or Approved Specification included in the Working Group’s repository
+subject to this License, and the version of the Specification implemented
+by the Licensee.
+
+9.13. Scope. “Scope” has the meaning as set forth in the accompanying
+Scope.md file included in this Specification’s repository. Changes
+to Scope do not apply retroactively. If no Scope is provided, each
+Contributor’s Necessary Claims are limited to that Contributor’s
+Contributions.
+
+9.14. Working Group. “Working Group” means this project to develop
+specifications, standards, best practices, guidelines, and other similar
+materials under this License.
+
+
+
+The text of this Community Specification License is Copyright 2020
+Joint Development Foundation and is licensed under the Creative
+Commons Attribution 4.0 International License available at
+https://creativecommons.org/licenses/by/4.0/.
+
+SPDX-License-Identifier: CC-BY-4.0
diff --git a/options/license/FDK-AAC b/options/license/FDK-AAC
new file mode 100644
index 000000000000..e506d69d5eea
--- /dev/null
+++ b/options/license/FDK-AAC
@@ -0,0 +1,79 @@
+Software License for The Fraunhofer FDK AAC Codec Library for Android
+
+© Copyright 1995 - 2012 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
+ All rights reserved.
+
+1. INTRODUCTION
+The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
+the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
+This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
+
+AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
+audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
+independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
+of the MPEG specifications.
+
+Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
+may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
+individually for the purpose of encoding or decoding bit streams in products that are compliant with
+the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
+these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
+software may already be covered under those patent licenses when it is used for those licensed purposes only.
+
+Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
+are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
+applications information and documentation.
+
+2. COPYRIGHT LICENSE
+
+Redistribution and use in source and binary forms, with or without modification, are permitted without
+payment of copyright license fees provided that you satisfy the following conditions:
+
+You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
+your modifications thereto in source code form.
+
+You must retain the complete text of this software license in the documentation and/or other materials
+provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
+You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
+modifications thereto to recipients of copies in binary form.
+
+The name of Fraunhofer may not be used to endorse or promote products derived from this library without
+prior written permission.
+
+You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
+software or your modifications thereto.
+
+Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
+and the date of any change. For modified versions of the FDK AAC Codec, the term
+"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
+"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
+
+3. NO PATENT LICENSE
+
+NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
+ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
+respect to this software.
+
+You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
+by appropriate patent licenses.
+
+4. DISCLAIMER
+
+This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
+"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
+of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
+including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
+or business interruption, however caused and on any theory of liability, whether in contract, strict
+liability, or tort (including negligence), arising in any way out of the use of this software, even if
+advised of the possibility of such damage.
+
+5. CONTACT INFORMATION
+
+Fraunhofer Institute for Integrated Circuits IIS
+Attention: Audio and Multimedia Departments - FDK AAC LL
+Am Wolfsmantel 33
+91058 Erlangen, Germany
+
+www.iis.fraunhofer.de/amm
+amm-info@iis.fraunhofer.de
diff --git a/options/license/Linux-man-pages-copyleft b/options/license/Linux-man-pages-copyleft
index 8a10d8e6840d..764635ae5c8d 100644
--- a/options/license/Linux-man-pages-copyleft
+++ b/options/license/Linux-man-pages-copyleft
@@ -1,4 +1,4 @@
-Copyright (c) 0000, Obelix the Gaul .
+Copyright (c) All rights reserved.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index cb343e46d27c..c39063e46e75 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -85,6 +85,12 @@ remove = Remove
remove_all = Remove All
edit = Edit
+copy = Copy
+copy_url = Copy URL
+copy_branch = Copy branch name
+copy_success = Copied!
+copy_error = Copy failed
+
write = Write
preview = Preview
loading = Loading…
@@ -904,12 +910,14 @@ migrate.migrate = Migrate From %s
migrate.migrating = Migrating from %s ...
migrate.migrating_failed = Migrating from %s failed.
migrate.migrating_failed.error = Error: %s
+migrate.migrating_failed_no_addr = Migration failed.
migrate.github.description = Migrate data from github.com or other Github instances.
migrate.git.description = Migrate a repository only from any Git service.
migrate.gitlab.description = Migrate data from gitlab.com or other GitLab instances.
migrate.gitea.description = Migrate data from gitea.com or other Gitea instances.
migrate.gogs.description = Migrate data from notabug.org or other Gogs instances.
migrate.onedev.description = Migrate data from code.onedev.io or other OneDev instances.
+migrate.gitbucket.description = Migrate data from GitBucket instances.
migrate.migrating_git = Migrating Git Data
migrate.migrating_topics = Migrating Topics
migrate.migrating_milestones = Migrating Milestones
@@ -925,13 +933,6 @@ fork_from_self = You cannot fork a repository you own.
fork_guest_user = Sign in to fork this repository.
watch_guest_user = Sign in to watch this repository.
star_guest_user = Sign in to star this repository.
-copy_link = Copy
-copy_link_success = Link has been copied
-copy_link_error = Use ⌘C or Ctrl-C to copy
-copy_branch = Copy
-copy_branch_success = Branch name has been copied
-copy_branch_error = Use ⌘C or Ctrl-C to copy
-copied = Copied OK
unwatch = Unwatch
watch = Watch
unstar = Unstar
@@ -987,6 +988,7 @@ commit_graph.hide_pr_refs = Hide Pull Requests
commit_graph.monochrome = Mono
commit_graph.color = Color
blame = Blame
+download_file = Download file
normal_view = Normal View
line = line
lines = lines
diff --git a/options/locale/locale_fi-FI.ini b/options/locale/locale_fi-FI.ini
index a44d99a9bf21..4065b4acf7b0 100644
--- a/options/locale/locale_fi-FI.ini
+++ b/options/locale/locale_fi-FI.ini
@@ -494,7 +494,6 @@ delete_prompt=Tämä toiminto poistaa käyttäjätilisi pysyvästi. Toimintoa %s 遷移...
migrate.migrating_failed=從 %s 遷移失敗
migrate.migrating_failed.error=錯誤:%s
+migrate.migrating_failed_no_addr=遷移失敗。
migrate.github.description=從 github.com 或其他 Github 實例遷移資料。
migrate.git.description=從任何 Git 服務遷移儲存庫。
migrate.gitlab.description=從 gitlab.com 或其他 GitLab 實例遷移資料。
migrate.gitea.description=從 gitea.com 或其他 Gitea 實例遷移資料。
migrate.gogs.description=從 notabug.org 或其他 Gogs 實例遷移資料。
migrate.onedev.description=從 code.onedev.io 或其他 OneDev 實例遷移資料。
+migrate.gitbucket.description=從 GitBucket 實例遷移資料。
migrate.migrating_git=正在遷移 Git 資料
migrate.migrating_topics=正在遷移主題
migrate.migrating_milestones=正在遷移里程碑
diff --git a/package-lock.json b/package-lock.json
index df4c575469fa..2ebeff0f305d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -51,6 +51,7 @@
"eslint-plugin-vue": "8.0.3",
"jest": "27.3.1",
"jest-extended": "1.1.0",
+ "jest-raw-loader": "1.0.1",
"postcss-less": "5.0.0",
"stylelint": "14.0.1",
"stylelint-config-standard": "23.0.0",
@@ -6221,6 +6222,12 @@
}
}
},
+ "node_modules/jest-raw-loader": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/jest-raw-loader/-/jest-raw-loader-1.0.1.tgz",
+ "integrity": "sha1-zp9W1UZQ8VfEp9FtIkul1hO81iY=",
+ "dev": true
+ },
"node_modules/jest-regex-util": {
"version": "27.0.6",
"resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-27.0.6.tgz",
@@ -14693,6 +14700,12 @@
"dev": true,
"requires": {}
},
+ "jest-raw-loader": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/jest-raw-loader/-/jest-raw-loader-1.0.1.tgz",
+ "integrity": "sha1-zp9W1UZQ8VfEp9FtIkul1hO81iY=",
+ "dev": true
+ },
"jest-regex-util": {
"version": "27.0.6",
"resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-27.0.6.tgz",
diff --git a/package.json b/package.json
index 71c9ab40fd4f..3c63141922f0 100644
--- a/package.json
+++ b/package.json
@@ -51,6 +51,7 @@
"eslint-plugin-vue": "8.0.3",
"jest": "27.3.1",
"jest-extended": "1.1.0",
+ "jest-raw-loader": "1.0.1",
"postcss-less": "5.0.0",
"stylelint": "14.0.1",
"stylelint-config-standard": "23.0.0",
diff --git a/public/img/svg/gitea-gitbucket.svg b/public/img/svg/gitea-gitbucket.svg
new file mode 100644
index 000000000000..3d07adebdd00
--- /dev/null
+++ b/public/img/svg/gitea-gitbucket.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/public/img/svg/gitea-vscode.svg b/public/img/svg/gitea-vscode.svg
new file mode 100644
index 000000000000..4ef94dec3b63
--- /dev/null
+++ b/public/img/svg/gitea-vscode.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/routers/api/v1/admin/adopt.go b/routers/api/v1/admin/adopt.go
index 9c1b9fc0f864..184a2941a871 100644
--- a/routers/api/v1/admin/adopt.go
+++ b/routers/api/v1/admin/adopt.go
@@ -9,9 +9,9 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/api/v1/utils"
+ repo_service "code.gitea.io/gitea/services/repository"
)
// ListUnadoptedRepositories lists the unadopted repositories that match the provided names
@@ -41,7 +41,7 @@ func ListUnadoptedRepositories(ctx *context.APIContext) {
// "$ref": "#/responses/forbidden"
listOptions := utils.GetListOptions(ctx)
- repoNames, count, err := repository.ListUnadoptedRepositories(ctx.FormString("query"), &listOptions)
+ repoNames, count, err := repo_service.ListUnadoptedRepositories(ctx.FormString("query"), &listOptions)
if err != nil {
ctx.InternalServerError(err)
}
@@ -104,7 +104,7 @@ func AdoptRepository(ctx *context.APIContext) {
ctx.NotFound()
return
}
- if _, err := repository.AdoptRepository(ctx.User, ctxUser, models.CreateRepoOptions{
+ if _, err := repo_service.AdoptRepository(ctx.User, ctxUser, models.CreateRepoOptions{
Name: repoName,
IsPrivate: true,
}); err != nil {
@@ -167,7 +167,7 @@ func DeleteUnadoptedRepository(ctx *context.APIContext) {
return
}
- if err := repository.DeleteUnadoptedRepository(ctx.User, ctxUser, repoName); err != nil {
+ if err := repo_service.DeleteUnadoptedRepository(ctx.User, ctxUser, repoName); err != nil {
ctx.InternalServerError(err)
return
}
diff --git a/routers/api/v1/admin/cron.go b/routers/api/v1/admin/cron.go
index 970fad83880c..1476872a905a 100644
--- a/routers/api/v1/admin/cron.go
+++ b/routers/api/v1/admin/cron.go
@@ -8,11 +8,11 @@ import (
"net/http"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/cron"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/api/v1/utils"
+ "code.gitea.io/gitea/services/cron"
)
// ListCronTasks api for getting cron tasks
diff --git a/routers/api/v1/repo/hook_test.go b/routers/api/v1/repo/hook_test.go
index 60fa6cead31c..07f1532f82d6 100644
--- a/routers/api/v1/repo/hook_test.go
+++ b/routers/api/v1/repo/hook_test.go
@@ -8,7 +8,7 @@ import (
"net/http"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/test"
@@ -17,7 +17,7 @@ import (
)
func TestTestHook(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/_pages")
ctx.SetParams(":id", "1")
@@ -27,8 +27,8 @@ func TestTestHook(t *testing.T) {
TestHook(&context.APIContext{Context: ctx, Org: nil})
assert.EqualValues(t, http.StatusNoContent, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &webhook.HookTask{
+ unittest.AssertExistsAndLoadBean(t, &webhook.HookTask{
RepoID: 1,
HookID: 1,
- }, db.Cond("is_delivered=?", false))
+ }, unittest.Cond("is_delivered=?", false))
}
diff --git a/routers/api/v1/repo/main_test.go b/routers/api/v1/repo/main_test.go
index 7a66370e05b2..f9ed886999c9 100644
--- a/routers/api/v1/repo/main_test.go
+++ b/routers/api/v1/repo/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", "..", "..", ".."))
+ unittest.MainTest(m, filepath.Join("..", "..", "..", ".."))
}
diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go
index 87ceb547c60b..00390dfb5f54 100644
--- a/routers/api/v1/repo/migrate.go
+++ b/routers/api/v1/repo/migrate.go
@@ -17,8 +17,7 @@ import (
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/migrations"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/notification"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -26,6 +25,7 @@ import (
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/forms"
+ "code.gitea.io/gitea/services/migrations"
)
// Migrate migrate remote git repository to gitea
diff --git a/routers/api/v1/repo/repo_test.go b/routers/api/v1/repo/repo_test.go
index e4fd4f94240e..4d4093582b08 100644
--- a/routers/api/v1/repo/repo_test.go
+++ b/routers/api/v1/repo/repo_test.go
@@ -9,7 +9,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
@@ -19,7 +19,7 @@ import (
)
func TestRepoEdit(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
test.LoadRepo(t, ctx, 1)
@@ -60,13 +60,13 @@ func TestRepoEdit(t *testing.T) {
Edit(apiCtx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.Repository{
+ unittest.AssertExistsAndLoadBean(t, &models.Repository{
ID: 1,
- }, db.Cond("name = ? AND is_archived = 1", *opts.Name))
+ }, unittest.Cond("name = ? AND is_archived = 1", *opts.Name))
}
func TestRepoEditNameChange(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
test.LoadRepo(t, ctx, 1)
@@ -82,7 +82,7 @@ func TestRepoEditNameChange(t *testing.T) {
Edit(apiCtx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.Repository{
+ unittest.AssertExistsAndLoadBean(t, &models.Repository{
ID: 1,
- }, db.Cond("name = ?", opts.Name))
+ }, unittest.Cond("name = ?", opts.Name))
}
diff --git a/routers/init.go b/routers/init.go
index 80e2fec09592..0f19e7f732d8 100644
--- a/routers/init.go
+++ b/routers/init.go
@@ -15,7 +15,6 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/appstate"
"code.gitea.io/gitea/modules/cache"
- "code.gitea.io/gitea/modules/cron"
"code.gitea.io/gitea/modules/eventsource"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/highlight"
@@ -25,7 +24,6 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/external"
- repo_migrations "code.gitea.io/gitea/modules/migrations"
"code.gitea.io/gitea/modules/notification"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -42,7 +40,9 @@ import (
"code.gitea.io/gitea/services/archiver"
"code.gitea.io/gitea/services/auth"
"code.gitea.io/gitea/services/auth/source/oauth2"
+ "code.gitea.io/gitea/services/cron"
"code.gitea.io/gitea/services/mailer"
+ repo_migrations "code.gitea.io/gitea/services/migrations"
mirror_service "code.gitea.io/gitea/services/mirror"
pull_service "code.gitea.io/gitea/services/pull"
"code.gitea.io/gitea/services/repository"
diff --git a/routers/private/restore_repo.go b/routers/private/restore_repo.go
index b7f7ed176f7c..85aada192f40 100644
--- a/routers/private/restore_repo.go
+++ b/routers/private/restore_repo.go
@@ -10,8 +10,8 @@ import (
myCtx "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/json"
- "code.gitea.io/gitea/modules/migrations"
"code.gitea.io/gitea/modules/private"
+ "code.gitea.io/gitea/services/migrations"
)
// RestoreRepo restore a repository from data
diff --git a/routers/web/admin/admin.go b/routers/web/admin/admin.go
index 223114dae1cc..8cbe85271852 100644
--- a/routers/web/admin/admin.go
+++ b/routers/web/admin/admin.go
@@ -18,7 +18,6 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/cron"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
@@ -28,6 +27,7 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/updatechecker"
"code.gitea.io/gitea/modules/web"
+ "code.gitea.io/gitea/services/cron"
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/mailer"
diff --git a/routers/web/admin/main_test.go b/routers/web/admin/main_test.go
index cfdefdb1b4af..e41d8fea75c3 100644
--- a/routers/web/admin/main_test.go
+++ b/routers/web/admin/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", "..", ".."))
+ unittest.MainTest(m, filepath.Join("..", "..", ".."))
}
diff --git a/routers/web/admin/repos.go b/routers/web/admin/repos.go
index 19f111165ac9..432dd2f6ae60 100644
--- a/routers/web/admin/repos.go
+++ b/routers/web/admin/repos.go
@@ -14,7 +14,6 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/routers/web/explore"
@@ -95,7 +94,7 @@ func UnadoptedRepos(ctx *context.Context) {
}
ctx.Data["Keyword"] = q
- repoNames, count, err := repository.ListUnadoptedRepositories(q, &opts)
+ repoNames, count, err := repo_service.ListUnadoptedRepositories(q, &opts)
if err != nil {
ctx.ServerError("ListUnadoptedRepositories", err)
}
@@ -147,7 +146,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
if has || !isDir {
// Fallthrough to failure mode
} else if action == "adopt" {
- if _, err := repository.AdoptRepository(ctx.User, ctxUser, models.CreateRepoOptions{
+ if _, err := repo_service.AdoptRepository(ctx.User, ctxUser, models.CreateRepoOptions{
Name: dirSplit[1],
IsPrivate: true,
}); err != nil {
@@ -156,7 +155,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
}
ctx.Flash.Success(ctx.Tr("repo.adopt_preexisting_success", dir))
} else if action == "delete" {
- if err := repository.DeleteUnadoptedRepository(ctx.User, ctxUser, dirSplit[1]); err != nil {
+ if err := repo_service.DeleteUnadoptedRepository(ctx.User, ctxUser, dirSplit[1]); err != nil {
ctx.ServerError("repository.AdoptRepository", err)
return
}
diff --git a/routers/web/admin/users_test.go b/routers/web/admin/users_test.go
index 022d8f662c8f..607ef2ea6634 100644
--- a/routers/web/admin/users_test.go
+++ b/routers/web/admin/users_test.go
@@ -8,7 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
@@ -20,10 +20,10 @@ import (
func TestNewUserPost_MustChangePassword(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := db.AssertExistsAndLoadBean(t, &models.User{
+ u := unittest.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
@@ -57,10 +57,10 @@ func TestNewUserPost_MustChangePassword(t *testing.T) {
}
func TestNewUserPost_MustChangePasswordFalse(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := db.AssertExistsAndLoadBean(t, &models.User{
+ u := unittest.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
@@ -94,10 +94,10 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) {
}
func TestNewUserPost_InvalidEmail(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := db.AssertExistsAndLoadBean(t, &models.User{
+ u := unittest.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
@@ -124,10 +124,10 @@ func TestNewUserPost_InvalidEmail(t *testing.T) {
}
func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := db.AssertExistsAndLoadBean(t, &models.User{
+ u := unittest.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
@@ -162,10 +162,10 @@ func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) {
}
func TestNewUserPost_VisibilityPrivate(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := db.AssertExistsAndLoadBean(t, &models.User{
+ u := unittest.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
diff --git a/routers/web/base.go b/routers/web/base.go
index 16d3192da21d..98713bc8818f 100644
--- a/routers/web/base.go
+++ b/routers/web/base.go
@@ -130,14 +130,6 @@ func Recovery() func(next http.Handler) http.Handler {
log.Error("%v", combinedErr)
sessionStore := session.GetSession(req)
- if sessionStore == nil {
- if setting.IsProd {
- http.Error(w, http.StatusText(500), 500)
- } else {
- http.Error(w, combinedErr, 500)
- }
- return
- }
var lc = middleware.Locale(w, req)
var store = dataStore{
diff --git a/routers/web/repo/editor_test.go b/routers/web/repo/editor_test.go
index 8ab1fe1ee892..77f94ff5501e 100644
--- a/routers/web/repo/editor_test.go
+++ b/routers/web/repo/editor_test.go
@@ -7,7 +7,7 @@ package repo
import (
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/test"
@@ -15,7 +15,7 @@ import (
)
func TestCleanUploadName(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
var kases = map[string]string{
".git/refs/master": "",
@@ -41,7 +41,7 @@ func TestCleanUploadName(t *testing.T) {
}
func TestGetUniquePatchBranchName(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
@@ -56,7 +56,7 @@ func TestGetUniquePatchBranchName(t *testing.T) {
}
func TestGetClosestParentWithFiles(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1")
ctx.SetParams(":id", "1")
test.LoadRepo(t, ctx, 1)
diff --git a/routers/web/repo/issue_label_test.go b/routers/web/repo/issue_label_test.go
index 8c3caabe17cf..baa34530fabd 100644
--- a/routers/web/repo/issue_label_test.go
+++ b/routers/web/repo/issue_label_test.go
@@ -10,7 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/forms"
@@ -30,14 +30,14 @@ func int64SliceToCommaSeparated(a []int64) string {
}
func TestInitializeLabels(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/labels/initialize")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 2)
web.SetForm(ctx, &forms.InitializeLabelsForm{TemplateName: "Default"})
InitializeLabels(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.Label{
+ unittest.AssertExistsAndLoadBean(t, &models.Label{
RepoID: 2,
Name: "enhancement",
Color: "#84b6eb",
@@ -46,7 +46,7 @@ func TestInitializeLabels(t *testing.T) {
}
func TestRetrieveLabels(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
for _, testCase := range []struct {
RepoID int64
Sort string
@@ -73,7 +73,7 @@ func TestRetrieveLabels(t *testing.T) {
}
func TestNewLabel(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/labels/edit")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
@@ -83,7 +83,7 @@ func TestNewLabel(t *testing.T) {
})
NewLabel(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.Label{
+ unittest.AssertExistsAndLoadBean(t, &models.Label{
Name: "newlabel",
Color: "#abcdef",
})
@@ -91,7 +91,7 @@ func TestNewLabel(t *testing.T) {
}
func TestUpdateLabel(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/labels/edit")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
@@ -102,7 +102,7 @@ func TestUpdateLabel(t *testing.T) {
})
UpdateLabel(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.Label{
+ unittest.AssertExistsAndLoadBean(t, &models.Label{
ID: 2,
Name: "newnameforlabel",
Color: "#abcdef",
@@ -111,20 +111,20 @@ func TestUpdateLabel(t *testing.T) {
}
func TestDeleteLabel(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/labels/delete")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
ctx.Req.Form.Set("id", "2")
DeleteLabel(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- db.AssertNotExistsBean(t, &models.Label{ID: 2})
- db.AssertNotExistsBean(t, &models.IssueLabel{LabelID: 2})
+ unittest.AssertNotExistsBean(t, &models.Label{ID: 2})
+ unittest.AssertNotExistsBean(t, &models.IssueLabel{LabelID: 2})
assert.Equal(t, ctx.Tr("repo.issues.label_deletion_success"), ctx.Flash.SuccessMsg)
}
func TestUpdateIssueLabel_Clear(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/issues/labels")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
@@ -132,9 +132,9 @@ func TestUpdateIssueLabel_Clear(t *testing.T) {
ctx.Req.Form.Set("action", "clear")
UpdateIssueLabel(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- db.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 1})
- db.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 3})
- models.CheckConsistencyFor(t, &models.Label{})
+ unittest.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 1})
+ unittest.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 3})
+ unittest.CheckConsistencyFor(t, &models.Label{})
}
func TestUpdateIssueLabel_Toggle(t *testing.T) {
@@ -149,7 +149,7 @@ func TestUpdateIssueLabel_Toggle(t *testing.T) {
{"toggle", []int64{1, 3}, 1, false},
{"toggle", []int64{1, 2}, 2, true},
} {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/issues/labels")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
@@ -159,11 +159,11 @@ func TestUpdateIssueLabel_Toggle(t *testing.T) {
UpdateIssueLabel(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
for _, issueID := range testCase.IssueIDs {
- db.AssertExistsIf(t, testCase.ExpectedAdd, &models.IssueLabel{
+ unittest.AssertExistsIf(t, testCase.ExpectedAdd, &models.IssueLabel{
IssueID: issueID,
LabelID: testCase.LabelID,
})
}
- models.CheckConsistencyFor(t, &models.Label{})
+ unittest.CheckConsistencyFor(t, &models.Label{})
}
}
diff --git a/routers/web/repo/main_test.go b/routers/web/repo/main_test.go
index 832256724987..81e3a8e28135 100644
--- a/routers/web/repo/main_test.go
+++ b/routers/web/repo/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", "..", ".."))
+ unittest.MainTest(m, filepath.Join("..", "..", ".."))
}
diff --git a/routers/web/repo/migrate.go b/routers/web/repo/migrate.go
index f62f396239d0..f91c344e94b8 100644
--- a/routers/web/repo/migrate.go
+++ b/routers/web/repo/migrate.go
@@ -15,13 +15,13 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/migrations"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/task"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/forms"
+ "code.gitea.io/gitea/services/migrations"
)
const (
diff --git a/routers/web/repo/projects_test.go b/routers/web/repo/projects_test.go
index d3b78cc77587..62fb0457400b 100644
--- a/routers/web/repo/projects_test.go
+++ b/routers/web/repo/projects_test.go
@@ -7,14 +7,14 @@ package repo
import (
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/test"
"github.com/stretchr/testify/assert"
)
func TestCheckProjectBoardChangePermissions(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/projects/1/2")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
diff --git a/routers/web/repo/release_test.go b/routers/web/repo/release_test.go
index 7ac49c012fef..33cf54cdc96e 100644
--- a/routers/web/repo/release_test.go
+++ b/routers/web/repo/release_test.go
@@ -8,7 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/forms"
@@ -44,7 +44,7 @@ func TestNewReleasePost(t *testing.T) {
},
},
} {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/releases/new")
test.LoadUser(t, ctx, 2)
@@ -52,14 +52,14 @@ func TestNewReleasePost(t *testing.T) {
test.LoadGitRepo(t, ctx)
web.SetForm(ctx, &testCase.Form)
NewReleasePost(ctx)
- db.AssertExistsAndLoadBean(t, &models.Release{
+ unittest.AssertExistsAndLoadBean(t, &models.Release{
RepoID: 1,
PublisherID: 2,
TagName: testCase.Form.TagName,
Target: testCase.Form.Target,
Title: testCase.Form.Title,
Note: testCase.Form.Content,
- }, db.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
+ }, unittest.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
ctx.Repo.GitRepo.Close()
}
}
diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go
index cad5536e70cd..641052316c26 100644
--- a/routers/web/repo/setting.go
+++ b/routers/web/repo/setting.go
@@ -22,7 +22,6 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/migrations"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
@@ -34,6 +33,7 @@ import (
"code.gitea.io/gitea/routers/utils"
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/mailer"
+ "code.gitea.io/gitea/services/migrations"
mirror_service "code.gitea.io/gitea/services/mirror"
repo_service "code.gitea.io/gitea/services/repository"
wiki_service "code.gitea.io/gitea/services/wiki"
@@ -557,7 +557,7 @@ func SettingsPost(ctx *context.Context) {
return
}
- if err := repository.ConvertForkToNormalRepository(repo); err != nil {
+ if err := repo_service.ConvertForkToNormalRepository(repo); err != nil {
log.Error("Unable to convert repository %-v from fork. Error: %v", repo, err)
ctx.ServerError("Convert Fork", err)
return
diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go
index a3ed271cce6c..3e8ae2b07e92 100644
--- a/routers/web/repo/settings_test.go
+++ b/routers/web/repo/settings_test.go
@@ -10,7 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
@@ -43,7 +43,7 @@ func TestAddReadOnlyDeployKey(t *testing.T) {
} else {
return
}
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/settings/keys")
@@ -58,7 +58,7 @@ func TestAddReadOnlyDeployKey(t *testing.T) {
DeployKeysPost(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.DeployKey{
+ unittest.AssertExistsAndLoadBean(t, &models.DeployKey{
Name: addKeyForm.Title,
Content: addKeyForm.Content,
Mode: models.AccessModeRead,
@@ -72,7 +72,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) {
return
}
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/settings/keys")
@@ -88,7 +88,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) {
DeployKeysPost(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.DeployKey{
+ unittest.AssertExistsAndLoadBean(t, &models.DeployKey{
Name: addKeyForm.Title,
Content: addKeyForm.Content,
Mode: models.AccessModeWrite,
@@ -97,7 +97,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) {
func TestCollaborationPost(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/issues/labels")
test.LoadUser(t, ctx, 2)
test.LoadUser(t, ctx, 4)
@@ -133,7 +133,7 @@ func TestCollaborationPost(t *testing.T) {
func TestCollaborationPost_InactiveUser(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/issues/labels")
test.LoadUser(t, ctx, 2)
test.LoadUser(t, ctx, 9)
@@ -157,7 +157,7 @@ func TestCollaborationPost_InactiveUser(t *testing.T) {
func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/issues/labels")
test.LoadUser(t, ctx, 2)
test.LoadUser(t, ctx, 4)
@@ -199,7 +199,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) {
func TestCollaborationPost_NonExistentUser(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/issues/labels")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
@@ -221,7 +221,7 @@ func TestCollaborationPost_NonExistentUser(t *testing.T) {
}
func TestAddTeamPost(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "org26/repo43")
ctx.Req.Form.Set("team", "team11")
@@ -261,7 +261,7 @@ func TestAddTeamPost(t *testing.T) {
}
func TestAddTeamPost_NotAllowed(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "org26/repo43")
ctx.Req.Form.Set("team", "team11")
@@ -302,7 +302,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) {
}
func TestAddTeamPost_AddTeamTwice(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "org26/repo43")
ctx.Req.Form.Set("team", "team11")
@@ -343,7 +343,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) {
}
func TestAddTeamPost_NonExistentTeam(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "org26/repo43")
ctx.Req.Form.Set("team", "team-non-existent")
@@ -376,7 +376,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) {
}
func TestDeleteTeam(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "org3/team1/repo3")
ctx.Req.Form.Set("id", "2")
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index d463bb601555..12b3aef505ea 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -583,6 +583,13 @@ func checkHomeCodeViewable(ctx *context.Context) {
if ctx.Repo.Repository.IsBeingCreated() {
task, err := models.GetMigratingTask(ctx.Repo.Repository.ID)
if err != nil {
+ if models.IsErrTaskDoesNotExist(err) {
+ ctx.Data["Repo"] = ctx.Repo
+ ctx.Data["CloneAddr"] = ""
+ ctx.Data["Failed"] = true
+ ctx.HTML(http.StatusOK, tplMigrating)
+ return
+ }
ctx.ServerError("models.GetMigratingTask", err)
return
}
diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go
index 436cb2cf046f..87f2779c1a84 100644
--- a/routers/web/repo/wiki_test.go
+++ b/routers/web/repo/wiki_test.go
@@ -10,7 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
@@ -74,7 +74,7 @@ func assertPagesMetas(t *testing.T, expectedNames []string, metas interface{}) {
}
func TestWiki(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/?action=_pages")
ctx.SetParams("*", "Home")
@@ -86,7 +86,7 @@ func TestWiki(t *testing.T) {
}
func TestWikiPages(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/?action=_pages")
test.LoadRepo(t, ctx, 1)
@@ -96,7 +96,7 @@ func TestWikiPages(t *testing.T) {
}
func TestNewWiki(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/?action=_new")
test.LoadUser(t, ctx, 2)
@@ -111,7 +111,7 @@ func TestNewWikiPost(t *testing.T) {
"New page",
"&&&&",
} {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/?action=_new")
test.LoadUser(t, ctx, 2)
@@ -129,7 +129,7 @@ func TestNewWikiPost(t *testing.T) {
}
func TestNewWikiPost_ReservedName(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/?action=_new")
test.LoadUser(t, ctx, 2)
@@ -146,7 +146,7 @@ func TestNewWikiPost_ReservedName(t *testing.T) {
}
func TestEditWiki(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/Home?action=_edit")
ctx.SetParams("*", "Home")
@@ -163,7 +163,7 @@ func TestEditWikiPost(t *testing.T) {
"Home",
"New/",
} {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/Home?action=_new")
ctx.SetParams("*", "Home")
test.LoadUser(t, ctx, 2)
@@ -184,7 +184,7 @@ func TestEditWikiPost(t *testing.T) {
}
func TestDeleteWikiPagePost(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/Home?action=_delete")
test.LoadUser(t, ctx, 2)
@@ -203,7 +203,7 @@ func TestWikiRaw(t *testing.T) {
"Page With Spaced Name.md": "text/plain; charset=utf-8",
"Page-With-Spaced-Name.md": "text/plain; charset=utf-8",
} {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/wiki/raw/"+filepath)
ctx.SetParams("*", filepath)
diff --git a/routers/web/user/home_test.go b/routers/web/user/home_test.go
index daf473b270c0..cd599abd047e 100644
--- a/routers/web/user/home_test.go
+++ b/routers/web/user/home_test.go
@@ -9,7 +9,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
@@ -19,7 +19,7 @@ import (
func TestArchivedIssues(t *testing.T) {
// Arrange
setting.UI.IssuePagingNum = 1
- assert.NoError(t, db.LoadFixtures())
+ assert.NoError(t, unittest.LoadFixtures())
ctx := test.MockContext(t, "issues")
test.LoadUser(t, ctx, 30)
@@ -52,7 +52,7 @@ func TestArchivedIssues(t *testing.T) {
func TestIssues(t *testing.T) {
setting.UI.IssuePagingNum = 1
- assert.NoError(t, db.LoadFixtures())
+ assert.NoError(t, unittest.LoadFixtures())
ctx := test.MockContext(t, "issues")
test.LoadUser(t, ctx, 2)
@@ -68,7 +68,7 @@ func TestIssues(t *testing.T) {
func TestPulls(t *testing.T) {
setting.UI.IssuePagingNum = 20
- assert.NoError(t, db.LoadFixtures())
+ assert.NoError(t, unittest.LoadFixtures())
ctx := test.MockContext(t, "pulls")
test.LoadUser(t, ctx, 2)
@@ -81,7 +81,7 @@ func TestPulls(t *testing.T) {
func TestMilestones(t *testing.T) {
setting.UI.IssuePagingNum = 1
- assert.NoError(t, db.LoadFixtures())
+ assert.NoError(t, unittest.LoadFixtures())
ctx := test.MockContext(t, "milestones")
test.LoadUser(t, ctx, 2)
@@ -100,7 +100,7 @@ func TestMilestones(t *testing.T) {
func TestMilestonesForSpecificRepo(t *testing.T) {
setting.UI.IssuePagingNum = 1
- assert.NoError(t, db.LoadFixtures())
+ assert.NoError(t, unittest.LoadFixtures())
ctx := test.MockContext(t, "milestones")
test.LoadUser(t, ctx, 2)
diff --git a/routers/web/user/main_test.go b/routers/web/user/main_test.go
index 272e4b8b2111..77b48d89fb86 100644
--- a/routers/web/user/main_test.go
+++ b/routers/web/user/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", "..", ".."))
+ unittest.MainTest(m, filepath.Join("..", "..", ".."))
}
diff --git a/routers/web/user/oauth_test.go b/routers/web/user/oauth_test.go
index 27d339b778ea..dfdaa9a1ed0e 100644
--- a/routers/web/user/oauth_test.go
+++ b/routers/web/user/oauth_test.go
@@ -8,8 +8,8 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/login"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/services/auth/source/oauth2"
"github.com/golang-jwt/jwt"
@@ -41,7 +41,7 @@ func createAndParseToken(t *testing.T, grant *login.OAuth2Grant) *oauth2.OIDCTok
}
func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
grants, err := login.GetOAuth2GrantsByUserID(3)
assert.NoError(t, err)
@@ -58,7 +58,7 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
assert.Empty(t, oidcToken.Email)
assert.False(t, oidcToken.EmailVerified)
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
grants, err = login.GetOAuth2GrantsByUserID(user.ID)
assert.NoError(t, err)
assert.Len(t, grants, 1)
diff --git a/routers/web/user/setting/account_test.go b/routers/web/user/setting/account_test.go
index bfb7ac48726f..cd5c77795ea9 100644
--- a/routers/web/user/setting/account_test.go
+++ b/routers/web/user/setting/account_test.go
@@ -8,7 +8,7 @@ import (
"net/http"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
@@ -81,7 +81,7 @@ func TestChangePassword(t *testing.T) {
PasswordComplexity: pcLU,
},
} {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "user/settings/security")
test.LoadUser(t, ctx, 2)
test.LoadRepo(t, ctx, 1)
diff --git a/routers/web/user/setting/adopt.go b/routers/web/user/setting/adopt.go
index e45a8a132465..948cc1e9366c 100644
--- a/routers/web/user/setting/adopt.go
+++ b/routers/web/user/setting/adopt.go
@@ -9,9 +9,9 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
+ repo_service "code.gitea.io/gitea/services/repository"
)
// AdoptOrDeleteRepository adopts or deletes a repository
@@ -27,7 +27,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
action := ctx.FormString("action")
ctxUser := ctx.User
- root := filepath.Join(models.UserPath(ctxUser.LowerName))
+ root := models.UserPath(ctxUser.LowerName)
// check not a repo
has, err := models.IsRepositoryExist(ctxUser, dir)
@@ -44,7 +44,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
if has || !isDir {
// Fallthrough to failure mode
} else if action == "adopt" && allowAdopt {
- if _, err := repository.AdoptRepository(ctxUser, ctxUser, models.CreateRepoOptions{
+ if _, err := repo_service.AdoptRepository(ctxUser, ctxUser, models.CreateRepoOptions{
Name: dir,
IsPrivate: true,
}); err != nil {
@@ -53,7 +53,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
}
ctx.Flash.Success(ctx.Tr("repo.adopt_preexisting_success", dir))
} else if action == "delete" && allowDelete {
- if err := repository.DeleteUnadoptedRepository(ctxUser, ctxUser, dir); err != nil {
+ if err := repo_service.DeleteUnadoptedRepository(ctxUser, ctxUser, dir); err != nil {
ctx.ServerError("repository.AdoptRepository", err)
return
}
diff --git a/routers/web/user/setting/main_test.go b/routers/web/user/setting/main_test.go
index a0fbe55ee17e..b6ed7f5b1803 100644
--- a/routers/web/user/setting/main_test.go
+++ b/routers/web/user/setting/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", "..", "..", ".."))
+ unittest.MainTest(m, filepath.Join("..", "..", "..", ".."))
}
diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go
index 4a0900615099..d7aa3264c58a 100644
--- a/routers/web/user/setting/profile.go
+++ b/routers/web/user/setting/profile.go
@@ -250,7 +250,7 @@ func Repos(ctx *context.Context) {
repoNames := make([]string, 0, setting.UI.Admin.UserPagingNum)
repos := map[string]*models.Repository{}
// We're going to iterate by pagesize.
- root := filepath.Join(models.UserPath(ctxUser.Name))
+ root := models.UserPath(ctxUser.Name)
if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
if os.IsNotExist(err) {
diff --git a/routers/web/user/task.go b/routers/web/user/task.go
index c71d43523393..4dbd1b8537bf 100644
--- a/routers/web/user/task.go
+++ b/routers/web/user/task.go
@@ -6,6 +6,7 @@ package user
import (
"net/http"
+ "strconv"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
@@ -16,6 +17,12 @@ import (
func TaskStatus(ctx *context.Context) {
task, opts, err := models.GetMigratingTaskByID(ctx.ParamsInt64("task"), ctx.User.ID)
if err != nil {
+ if models.IsErrTaskDoesNotExist(err) {
+ ctx.JSON(http.StatusNotFound, map[string]interface{}{
+ "error": "task `" + strconv.FormatInt(ctx.ParamsInt64("task"), 10) + "` does not exist",
+ })
+ return
+ }
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
"err": err,
})
diff --git a/services/archiver/archiver_test.go b/services/archiver/archiver_test.go
index 94b0423d9bae..67484fdc786a 100644
--- a/services/archiver/archiver_test.go
+++ b/services/archiver/archiver_test.go
@@ -9,14 +9,14 @@ import (
"testing"
"time"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/test"
"github.com/stretchr/testify/assert"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
func waitForCount(t *testing.T, num int) {
@@ -24,7 +24,7 @@ func waitForCount(t *testing.T, num int) {
}
func TestArchive_Basic(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
ctx := test.MockContext(t, "user27/repo49")
firstCommit, secondCommit := "51f84af23134", "aacbdfe9e1c4"
diff --git a/services/attachment/attachment_test.go b/services/attachment/attachment_test.go
index 3e9e55a8f2fe..5bb5db11ec66 100644
--- a/services/attachment/attachment_test.go
+++ b/services/attachment/attachment_test.go
@@ -10,19 +10,19 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
func TestUploadAttachment(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
fPath := "./attachment_test.go"
f, err := os.Open(fPath)
diff --git a/services/auth/basic.go b/services/auth/basic.go
index 0c400b6b5329..d7f889cbdc8e 100644
--- a/services/auth/basic.go
+++ b/services/auth/basic.go
@@ -50,7 +50,7 @@ func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore
}
auths := strings.SplitN(baHead, " ", 2)
- if len(auths) != 2 || (auths[0] != "Basic" && auths[0] != "basic") {
+ if len(auths) != 2 || (strings.ToLower(auths[0]) != "basic") {
return nil
}
diff --git a/modules/cron/cron.go b/services/cron/cron.go
similarity index 100%
rename from modules/cron/cron.go
rename to services/cron/cron.go
diff --git a/modules/cron/setting.go b/services/cron/setting.go
similarity index 100%
rename from modules/cron/setting.go
rename to services/cron/setting.go
diff --git a/modules/cron/tasks.go b/services/cron/tasks.go
similarity index 100%
rename from modules/cron/tasks.go
rename to services/cron/tasks.go
diff --git a/modules/cron/tasks_basic.go b/services/cron/tasks_basic.go
similarity index 98%
rename from modules/cron/tasks_basic.go
rename to services/cron/tasks_basic.go
index a42c031b361f..57fb399d4e19 100644
--- a/modules/cron/tasks_basic.go
+++ b/services/cron/tasks_basic.go
@@ -10,10 +10,10 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/webhook"
- "code.gitea.io/gitea/modules/migrations"
repository_service "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/auth"
+ "code.gitea.io/gitea/services/migrations"
mirror_service "code.gitea.io/gitea/services/mirror"
)
diff --git a/modules/cron/tasks_extended.go b/services/cron/tasks_extended.go
similarity index 97%
rename from modules/cron/tasks_extended.go
rename to services/cron/tasks_extended.go
index 9a37c40fafe7..4ddcd44537ed 100644
--- a/modules/cron/tasks_extended.go
+++ b/services/cron/tasks_extended.go
@@ -12,6 +12,7 @@ import (
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/updatechecker"
+ repo_service "code.gitea.io/gitea/services/repository"
)
func registerDeleteInactiveUsers() {
@@ -34,7 +35,7 @@ func registerDeleteRepositoryArchives() {
RunAtStart: false,
Schedule: "@annually",
}, func(ctx context.Context, _ *models.User, _ Config) error {
- return repo_module.DeleteRepositoryArchives(ctx)
+ return repo_service.DeleteRepositoryArchives(ctx)
})
}
diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go
index 6decb59b64b5..aefd396ebbae 100644
--- a/services/gitdiff/gitdiff_test.go
+++ b/services/gitdiff/gitdiff_test.go
@@ -13,7 +13,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/highlight"
"code.gitea.io/gitea/modules/json"
@@ -493,10 +493,10 @@ func setupDefaultDiff() *Diff {
}
}
func TestDiff_LoadComments(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
- issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
diff := setupDefaultDiff()
assert.NoError(t, diff.LoadComments(issue, user))
assert.Len(t, diff.Files[0].Sections[0].Lines[0].Comments, 2)
diff --git a/services/gitdiff/main_test.go b/services/gitdiff/main_test.go
index 1b83cbd684a0..8c76e7e1530f 100644
--- a/services/gitdiff/main_test.go
+++ b/services/gitdiff/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
diff --git a/services/issue/assignee_test.go b/services/issue/assignee_test.go
index 5684ed6d8997..b0bbe42273d1 100644
--- a/services/issue/assignee_test.go
+++ b/services/issue/assignee_test.go
@@ -8,12 +8,12 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
)
func TestDeleteNotPassedAssignee(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
// Fake issue with assignees
issue, err := models.GetIssueWithAttrsByID(1)
diff --git a/services/issue/label_test.go b/services/issue/label_test.go
index 8a3a77ecb0a6..fa6ad613b694 100644
--- a/services/issue/label_test.go
+++ b/services/issue/label_test.go
@@ -8,7 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
)
@@ -24,16 +24,16 @@ func TestIssue_AddLabels(t *testing.T) {
{2, []int64{}, 1}, // pull-request, empty
}
for _, test := range tests {
- assert.NoError(t, db.PrepareTestDatabase())
- issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
labels := make([]*models.Label, len(test.labelIDs))
for i, labelID := range test.labelIDs {
- labels[i] = db.AssertExistsAndLoadBean(t, &models.Label{ID: labelID}).(*models.Label)
+ labels[i] = unittest.AssertExistsAndLoadBean(t, &models.Label{ID: labelID}).(*models.Label)
}
- doer := db.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
+ doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
assert.NoError(t, AddLabels(issue, doer, labels))
for _, labelID := range test.labelIDs {
- db.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: labelID})
+ unittest.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: labelID})
}
}
}
@@ -50,11 +50,11 @@ func TestIssue_AddLabel(t *testing.T) {
{2, 1, 2}, // pull-request, already-added label
}
for _, test := range tests {
- assert.NoError(t, db.PrepareTestDatabase())
- issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
- label := db.AssertExistsAndLoadBean(t, &models.Label{ID: test.labelID}).(*models.Label)
- doer := db.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ issue := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
+ label := unittest.AssertExistsAndLoadBean(t, &models.Label{ID: test.labelID}).(*models.Label)
+ doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
assert.NoError(t, AddLabel(issue, doer, label))
- db.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
+ unittest.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
}
}
diff --git a/services/issue/main_test.go b/services/issue/main_test.go
index 1349837949d0..cbcfd08a4979 100644
--- a/services/issue/main_test.go
+++ b/services/issue/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go
index cd730a13a445..94ff5a65ae90 100644
--- a/services/mailer/mail_test.go
+++ b/services/mailer/mail_test.go
@@ -11,7 +11,7 @@ import (
texttmpl "text/template"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
@@ -41,7 +41,7 @@ const bodyTpl = `
`
func prepareMailerTest(t *testing.T) (doer *models.User, repo *models.Repository, issue *models.Issue, comment *models.Comment) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
var mailService = setting.Mailer{
From: "test@gitea.com",
}
@@ -49,11 +49,11 @@ func prepareMailerTest(t *testing.T) (doer *models.User, repo *models.Repository
setting.MailService = &mailService
setting.Domain = "localhost"
- doer = db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1, Owner: doer}).(*models.Repository)
- issue = db.AssertExistsAndLoadBean(t, &models.Issue{ID: 1, Repo: repo, Poster: doer}).(*models.Issue)
+ doer = unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1, Owner: doer}).(*models.Repository)
+ issue = unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 1, Repo: repo, Poster: doer}).(*models.Issue)
assert.NoError(t, issue.LoadRepo())
- comment = db.AssertExistsAndLoadBean(t, &models.Comment{ID: 2, Issue: issue}).(*models.Comment)
+ comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 2, Issue: issue}).(*models.Comment)
return
}
@@ -144,8 +144,8 @@ func TestTemplateSelection(t *testing.T) {
Content: "test body", Comment: comment}, recipients, false, "TestTemplateSelection")
expect(t, msg, "issue/default/subject", "issue/default/body")
- pull := db.AssertExistsAndLoadBean(t, &models.Issue{ID: 2, Repo: repo, Poster: doer}).(*models.Issue)
- comment = db.AssertExistsAndLoadBean(t, &models.Comment{ID: 4, Issue: pull}).(*models.Comment)
+ pull := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2, Repo: repo, Poster: doer}).(*models.Issue)
+ comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 4, Issue: pull}).(*models.Comment)
msg = testComposeIssueCommentMessage(t, &mailCommentContext{Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
Content: "test body", Comment: comment}, recipients, false, "TestTemplateSelection")
expect(t, msg, "pull/comment/subject", "pull/comment/body")
diff --git a/services/mailer/main_test.go b/services/mailer/main_test.go
index 2fbe9c54a93c..ae3b2c12b4ca 100644
--- a/services/mailer/main_test.go
+++ b/services/mailer/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
diff --git a/modules/migrations/dump.go b/services/migrations/dump.go
similarity index 99%
rename from modules/migrations/dump.go
rename to services/migrations/dump.go
index 6b995c0dea8c..6e3596230fda 100644
--- a/modules/migrations/dump.go
+++ b/services/migrations/dump.go
@@ -20,7 +20,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/structs"
diff --git a/modules/migrations/error.go b/services/migrations/error.go
similarity index 100%
rename from modules/migrations/error.go
rename to services/migrations/error.go
diff --git a/modules/migrations/git.go b/services/migrations/git.go
similarity index 96%
rename from modules/migrations/git.go
rename to services/migrations/git.go
index 7e4194547499..37ffb674c5c8 100644
--- a/modules/migrations/git.go
+++ b/services/migrations/git.go
@@ -7,7 +7,7 @@ package migrations
import (
"context"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
)
var (
diff --git a/services/migrations/gitbucket.go b/services/migrations/gitbucket.go
new file mode 100644
index 000000000000..27ed584aa239
--- /dev/null
+++ b/services/migrations/gitbucket.go
@@ -0,0 +1,72 @@
+// Copyright 2021 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package migrations
+
+import (
+ "context"
+ "net/url"
+ "strings"
+
+ base "code.gitea.io/gitea/modules/migration"
+ "code.gitea.io/gitea/modules/structs"
+)
+
+var (
+ _ base.Downloader = &GitBucketDownloader{}
+ _ base.DownloaderFactory = &GitBucketDownloaderFactory{}
+)
+
+func init() {
+ RegisterDownloaderFactory(&GitBucketDownloaderFactory{})
+}
+
+// GitBucketDownloaderFactory defines a GitBucket downloader factory
+type GitBucketDownloaderFactory struct {
+}
+
+// New returns a Downloader related to this factory according MigrateOptions
+func (f *GitBucketDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) {
+ u, err := url.Parse(opts.CloneAddr)
+ if err != nil {
+ return nil, err
+ }
+
+ baseURL := u.Scheme + "://" + u.Host
+ fields := strings.Split(u.Path, "/")
+ oldOwner := fields[1]
+ oldName := strings.TrimSuffix(fields[2], ".git")
+
+ return NewGitBucketDownloader(ctx, baseURL, opts.AuthUsername, opts.AuthPassword, opts.AuthToken, oldOwner, oldName), nil
+}
+
+// GitServiceType returns the type of git service
+func (f *GitBucketDownloaderFactory) GitServiceType() structs.GitServiceType {
+ return structs.GitBucketService
+}
+
+// GitBucketDownloader implements a Downloader interface to get repository information
+// from GitBucket via GithubDownloader
+type GitBucketDownloader struct {
+ *GithubDownloaderV3
+}
+
+// NewGitBucketDownloader creates a GitBucket downloader
+func NewGitBucketDownloader(ctx context.Context, baseURL, userName, password, token, repoOwner, repoName string) *GitBucketDownloader {
+ githubDownloader := NewGithubDownloaderV3(ctx, baseURL, userName, password, token, repoOwner, repoName)
+ githubDownloader.SkipReactions = true
+ return &GitBucketDownloader{
+ githubDownloader,
+ }
+}
+
+// SupportGetRepoComments return true if it supports get repo comments
+func (g *GitBucketDownloader) SupportGetRepoComments() bool {
+ return false
+}
+
+// GetReviews is not supported
+func (g *GitBucketDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) {
+ return nil, &base.ErrNotSupported{Entity: "Reviews"}
+}
diff --git a/modules/migrations/gitea_downloader.go b/services/migrations/gitea_downloader.go
similarity index 99%
rename from modules/migrations/gitea_downloader.go
rename to services/migrations/gitea_downloader.go
index d8a3c84678ef..51ef0292df7f 100644
--- a/modules/migrations/gitea_downloader.go
+++ b/services/migrations/gitea_downloader.go
@@ -17,7 +17,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/proxy"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
diff --git a/modules/migrations/gitea_downloader_test.go b/services/migrations/gitea_downloader_test.go
similarity index 99%
rename from modules/migrations/gitea_downloader_test.go
rename to services/migrations/gitea_downloader_test.go
index 71bdecaeaddd..2c70dc421356 100644
--- a/modules/migrations/gitea_downloader_test.go
+++ b/services/migrations/gitea_downloader_test.go
@@ -12,7 +12,7 @@ import (
"testing"
"time"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"github.com/stretchr/testify/assert"
)
diff --git a/modules/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go
similarity index 99%
rename from modules/migrations/gitea_uploader.go
rename to services/migrations/gitea_uploader.go
index d62ce80c77f3..5eecaf6c56e4 100644
--- a/modules/migrations/gitea_uploader.go
+++ b/services/migrations/gitea_uploader.go
@@ -19,7 +19,7 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
diff --git a/modules/migrations/gitea_uploader_test.go b/services/migrations/gitea_uploader_test.go
similarity index 90%
rename from modules/migrations/gitea_uploader_test.go
rename to services/migrations/gitea_uploader_test.go
index b8b947961f4b..9b04004cd73b 100644
--- a/modules/migrations/gitea_uploader_test.go
+++ b/services/migrations/gitea_uploader_test.go
@@ -12,8 +12,9 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/graceful"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
@@ -24,9 +25,9 @@ func TestGiteaUploadRepo(t *testing.T) {
// FIXME: Since no accesskey or user/password will trigger rate limit of github, just skip
t.Skip()
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
var (
downloader = NewGithubDownloaderV3(context.Background(), "https://github.com", "", "", "", "go-xorm", "builder")
@@ -51,7 +52,7 @@ func TestGiteaUploadRepo(t *testing.T) {
}, nil)
assert.NoError(t, err)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID, Name: repoName}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID, Name: repoName}).(*models.Repository)
assert.True(t, repo.HasWiki())
assert.EqualValues(t, models.RepositoryReady, repo.Status)
diff --git a/modules/migrations/github.go b/services/migrations/github.go
similarity index 88%
rename from modules/migrations/github.go
rename to services/migrations/github.go
index 874cd054394f..3043d7cf75ad 100644
--- a/modules/migrations/github.go
+++ b/services/migrations/github.go
@@ -17,7 +17,7 @@ import (
"time"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/proxy"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
@@ -68,15 +68,16 @@ func (f *GithubDownloaderV3Factory) GitServiceType() structs.GitServiceType {
// from github via APIv3
type GithubDownloaderV3 struct {
base.NullDownloader
- ctx context.Context
- clients []*github.Client
- repoOwner string
- repoName string
- userName string
- password string
- rates []*github.Rate
- curClientIdx int
- maxPerPage int
+ ctx context.Context
+ clients []*github.Client
+ repoOwner string
+ repoName string
+ userName string
+ password string
+ rates []*github.Rate
+ curClientIdx int
+ maxPerPage int
+ SkipReactions bool
}
// NewGithubDownloaderV3 creates a github Downloader via github v3 API
@@ -428,25 +429,27 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
// get reactions
var reactions []*base.Reaction
- for i := 1; ; i++ {
- g.waitAndPickClient()
- res, resp, err := g.getClient().Reactions.ListIssueReactions(g.ctx, g.repoOwner, g.repoName, issue.GetNumber(), &github.ListOptions{
- Page: i,
- PerPage: perPage,
- })
- if err != nil {
- return nil, false, err
- }
- g.setRate(&resp.Rate)
- if len(res) == 0 {
- break
- }
- for _, reaction := range res {
- reactions = append(reactions, &base.Reaction{
- UserID: reaction.User.GetID(),
- UserName: reaction.User.GetLogin(),
- Content: reaction.GetContent(),
+ if !g.SkipReactions {
+ for i := 1; ; i++ {
+ g.waitAndPickClient()
+ res, resp, err := g.getClient().Reactions.ListIssueReactions(g.ctx, g.repoOwner, g.repoName, issue.GetNumber(), &github.ListOptions{
+ Page: i,
+ PerPage: perPage,
})
+ if err != nil {
+ return nil, false, err
+ }
+ g.setRate(&resp.Rate)
+ if len(res) == 0 {
+ break
+ }
+ for _, reaction := range res {
+ reactions = append(reactions, &base.Reaction{
+ UserID: reaction.User.GetID(),
+ UserName: reaction.User.GetLogin(),
+ Content: reaction.GetContent(),
+ })
+ }
}
}
@@ -516,25 +519,27 @@ func (g *GithubDownloaderV3) getComments(issueContext base.IssueContext) ([]*bas
for _, comment := range comments {
// get reactions
var reactions []*base.Reaction
- for i := 1; ; i++ {
- g.waitAndPickClient()
- res, resp, err := g.getClient().Reactions.ListIssueCommentReactions(g.ctx, g.repoOwner, g.repoName, comment.GetID(), &github.ListOptions{
- Page: i,
- PerPage: g.maxPerPage,
- })
- if err != nil {
- return nil, err
- }
- g.setRate(&resp.Rate)
- if len(res) == 0 {
- break
- }
- for _, reaction := range res {
- reactions = append(reactions, &base.Reaction{
- UserID: reaction.User.GetID(),
- UserName: reaction.User.GetLogin(),
- Content: reaction.GetContent(),
+ if !g.SkipReactions {
+ for i := 1; ; i++ {
+ g.waitAndPickClient()
+ res, resp, err := g.getClient().Reactions.ListIssueCommentReactions(g.ctx, g.repoOwner, g.repoName, comment.GetID(), &github.ListOptions{
+ Page: i,
+ PerPage: g.maxPerPage,
})
+ if err != nil {
+ return nil, err
+ }
+ g.setRate(&resp.Rate)
+ if len(res) == 0 {
+ break
+ }
+ for _, reaction := range res {
+ reactions = append(reactions, &base.Reaction{
+ UserID: reaction.User.GetID(),
+ UserName: reaction.User.GetLogin(),
+ Content: reaction.GetContent(),
+ })
+ }
}
}
@@ -588,25 +593,27 @@ func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment,
for _, comment := range comments {
// get reactions
var reactions []*base.Reaction
- for i := 1; ; i++ {
- g.waitAndPickClient()
- res, resp, err := g.getClient().Reactions.ListIssueCommentReactions(g.ctx, g.repoOwner, g.repoName, comment.GetID(), &github.ListOptions{
- Page: i,
- PerPage: g.maxPerPage,
- })
- if err != nil {
- return nil, false, err
- }
- g.setRate(&resp.Rate)
- if len(res) == 0 {
- break
- }
- for _, reaction := range res {
- reactions = append(reactions, &base.Reaction{
- UserID: reaction.User.GetID(),
- UserName: reaction.User.GetLogin(),
- Content: reaction.GetContent(),
+ if !g.SkipReactions {
+ for i := 1; ; i++ {
+ g.waitAndPickClient()
+ res, resp, err := g.getClient().Reactions.ListIssueCommentReactions(g.ctx, g.repoOwner, g.repoName, comment.GetID(), &github.ListOptions{
+ Page: i,
+ PerPage: g.maxPerPage,
})
+ if err != nil {
+ return nil, false, err
+ }
+ g.setRate(&resp.Rate)
+ if len(res) == 0 {
+ break
+ }
+ for _, reaction := range res {
+ reactions = append(reactions, &base.Reaction{
+ UserID: reaction.User.GetID(),
+ UserName: reaction.User.GetLogin(),
+ Content: reaction.GetContent(),
+ })
+ }
}
}
idx := strings.LastIndex(*comment.IssueURL, "/")
@@ -656,25 +663,27 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
// get reactions
var reactions []*base.Reaction
- for i := 1; ; i++ {
- g.waitAndPickClient()
- res, resp, err := g.getClient().Reactions.ListIssueReactions(g.ctx, g.repoOwner, g.repoName, pr.GetNumber(), &github.ListOptions{
- Page: i,
- PerPage: perPage,
- })
- if err != nil {
- return nil, false, err
- }
- g.setRate(&resp.Rate)
- if len(res) == 0 {
- break
- }
- for _, reaction := range res {
- reactions = append(reactions, &base.Reaction{
- UserID: reaction.User.GetID(),
- UserName: reaction.User.GetLogin(),
- Content: reaction.GetContent(),
+ if !g.SkipReactions {
+ for i := 1; ; i++ {
+ g.waitAndPickClient()
+ res, resp, err := g.getClient().Reactions.ListIssueReactions(g.ctx, g.repoOwner, g.repoName, pr.GetNumber(), &github.ListOptions{
+ Page: i,
+ PerPage: perPage,
})
+ if err != nil {
+ return nil, false, err
+ }
+ g.setRate(&resp.Rate)
+ if len(res) == 0 {
+ break
+ }
+ for _, reaction := range res {
+ reactions = append(reactions, &base.Reaction{
+ UserID: reaction.User.GetID(),
+ UserName: reaction.User.GetLogin(),
+ Content: reaction.GetContent(),
+ })
+ }
}
}
@@ -737,25 +746,27 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques
for _, c := range cs {
// get reactions
var reactions []*base.Reaction
- for i := 1; ; i++ {
- g.waitAndPickClient()
- res, resp, err := g.getClient().Reactions.ListPullRequestCommentReactions(g.ctx, g.repoOwner, g.repoName, c.GetID(), &github.ListOptions{
- Page: i,
- PerPage: g.maxPerPage,
- })
- if err != nil {
- return nil, err
- }
- g.setRate(&resp.Rate)
- if len(res) == 0 {
- break
- }
- for _, reaction := range res {
- reactions = append(reactions, &base.Reaction{
- UserID: reaction.User.GetID(),
- UserName: reaction.User.GetLogin(),
- Content: reaction.GetContent(),
+ if !g.SkipReactions {
+ for i := 1; ; i++ {
+ g.waitAndPickClient()
+ res, resp, err := g.getClient().Reactions.ListPullRequestCommentReactions(g.ctx, g.repoOwner, g.repoName, c.GetID(), &github.ListOptions{
+ Page: i,
+ PerPage: g.maxPerPage,
})
+ if err != nil {
+ return nil, err
+ }
+ g.setRate(&resp.Rate)
+ if len(res) == 0 {
+ break
+ }
+ for _, reaction := range res {
+ reactions = append(reactions, &base.Reaction{
+ UserID: reaction.User.GetID(),
+ UserName: reaction.User.GetLogin(),
+ Content: reaction.GetContent(),
+ })
+ }
}
}
diff --git a/modules/migrations/github_test.go b/services/migrations/github_test.go
similarity index 99%
rename from modules/migrations/github_test.go
rename to services/migrations/github_test.go
index 4a53f20a76dd..c8249dfdb2ba 100644
--- a/modules/migrations/github_test.go
+++ b/services/migrations/github_test.go
@@ -11,7 +11,7 @@ import (
"testing"
"time"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"github.com/stretchr/testify/assert"
)
diff --git a/modules/migrations/gitlab.go b/services/migrations/gitlab.go
similarity index 99%
rename from modules/migrations/gitlab.go
rename to services/migrations/gitlab.go
index 91ba073d18f4..e285519aa54b 100644
--- a/modules/migrations/gitlab.go
+++ b/services/migrations/gitlab.go
@@ -17,7 +17,7 @@ import (
"time"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/proxy"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
diff --git a/modules/migrations/gitlab_test.go b/services/migrations/gitlab_test.go
similarity index 99%
rename from modules/migrations/gitlab_test.go
rename to services/migrations/gitlab_test.go
index c3ee8118c55d..f6dc7510cbed 100644
--- a/modules/migrations/gitlab_test.go
+++ b/services/migrations/gitlab_test.go
@@ -12,7 +12,7 @@ import (
"testing"
"time"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"github.com/stretchr/testify/assert"
)
diff --git a/modules/migrations/gogs.go b/services/migrations/gogs.go
similarity index 99%
rename from modules/migrations/gogs.go
rename to services/migrations/gogs.go
index 06c944278b43..9473bf8b4874 100644
--- a/modules/migrations/gogs.go
+++ b/services/migrations/gogs.go
@@ -14,7 +14,7 @@ import (
"time"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/proxy"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
diff --git a/modules/migrations/gogs_test.go b/services/migrations/gogs_test.go
similarity index 98%
rename from modules/migrations/gogs_test.go
rename to services/migrations/gogs_test.go
index 8816fab44fbc..57eda59b928f 100644
--- a/modules/migrations/gogs_test.go
+++ b/services/migrations/gogs_test.go
@@ -11,7 +11,7 @@ import (
"testing"
"time"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"github.com/stretchr/testify/assert"
)
diff --git a/modules/migrations/main_test.go b/services/migrations/main_test.go
similarity index 98%
rename from modules/migrations/main_test.go
rename to services/migrations/main_test.go
index 5b29230659aa..660f6dd845ae 100644
--- a/modules/migrations/main_test.go
+++ b/services/migrations/main_test.go
@@ -10,14 +10,14 @@ import (
"testing"
"time"
- "code.gitea.io/gitea/models/db"
- "code.gitea.io/gitea/modules/migrations/base"
+ "code.gitea.io/gitea/models/unittest"
+ base "code.gitea.io/gitea/modules/migration"
"github.com/stretchr/testify/assert"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
func timePtr(t time.Time) *time.Time {
diff --git a/modules/migrations/migrate.go b/services/migrations/migrate.go
similarity index 99%
rename from modules/migrations/migrate.go
rename to services/migrations/migrate.go
index dbe69259f4ec..21be2d3b0ddd 100644
--- a/modules/migrations/migrate.go
+++ b/services/migrations/migrate.go
@@ -16,7 +16,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/matchlist"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
)
diff --git a/modules/migrations/migrate_test.go b/services/migrations/migrate_test.go
similarity index 87%
rename from modules/migrations/migrate_test.go
rename to services/migrations/migrate_test.go
index c050a9abc086..325064697ef8 100644
--- a/modules/migrations/migrate_test.go
+++ b/services/migrations/migrate_test.go
@@ -9,17 +9,17 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
)
func TestMigrateWhiteBlocklist(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
- adminUser := db.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
- nonAdminUser := db.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
+ adminUser := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
+ nonAdminUser := unittest.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
setting.Migrations.AllowedDomains = []string{"github.com"}
assert.NoError(t, Init())
diff --git a/modules/migrations/onedev.go b/services/migrations/onedev.go
similarity index 99%
rename from modules/migrations/onedev.go
rename to services/migrations/onedev.go
index e60265895fbc..1159026892db 100644
--- a/modules/migrations/onedev.go
+++ b/services/migrations/onedev.go
@@ -15,7 +15,7 @@ import (
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/structs"
)
diff --git a/modules/migrations/onedev_test.go b/services/migrations/onedev_test.go
similarity index 98%
rename from modules/migrations/onedev_test.go
rename to services/migrations/onedev_test.go
index 5dabf66bdca2..59b7cae5feff 100644
--- a/modules/migrations/onedev_test.go
+++ b/services/migrations/onedev_test.go
@@ -12,7 +12,7 @@ import (
"testing"
"time"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"github.com/stretchr/testify/assert"
)
diff --git a/modules/migrations/restore.go b/services/migrations/restore.go
similarity index 99%
rename from modules/migrations/restore.go
rename to services/migrations/restore.go
index 5fddf7b50579..87e5316ef610 100644
--- a/modules/migrations/restore.go
+++ b/services/migrations/restore.go
@@ -11,7 +11,7 @@ import (
"path/filepath"
"strconv"
- "code.gitea.io/gitea/modules/migrations/base"
+ base "code.gitea.io/gitea/modules/migration"
"gopkg.in/yaml.v2"
)
diff --git a/modules/migrations/update.go b/services/migrations/update.go
similarity index 100%
rename from modules/migrations/update.go
rename to services/migrations/update.go
diff --git a/services/pull/check_test.go b/services/pull/check_test.go
index 8beea3d56d90..f0ec096ea945 100644
--- a/services/pull/check_test.go
+++ b/services/pull/check_test.go
@@ -11,14 +11,14 @@ import (
"time"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/queue"
"github.com/stretchr/testify/assert"
)
func TestPullRequest_AddToTaskQueue(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
idChan := make(chan int64, 10)
@@ -42,11 +42,11 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
prQueue = q.(queue.UniqueQueue)
- pr := db.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
+ pr := unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
AddToTaskQueue(pr)
assert.Eventually(t, func() bool {
- pr = db.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
+ pr = unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
return pr.Status == models.PullRequestStatusChecking
}, 1*time.Second, 100*time.Millisecond)
@@ -71,7 +71,7 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
assert.False(t, has)
assert.NoError(t, err)
- pr = db.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
+ pr = unittest.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
assert.Equal(t, models.PullRequestStatusChecking, pr.Status)
for _, callback := range queueShutdown {
diff --git a/services/pull/main_test.go b/services/pull/main_test.go
index c8d3394e8e6a..6059a291addd 100644
--- a/services/pull/main_test.go
+++ b/services/pull/main_test.go
@@ -9,9 +9,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
diff --git a/services/pull/merge.go b/services/pull/merge.go
index f59931e1bfd3..e4ed4e38bd9c 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -275,8 +275,8 @@ func rawMerge(pr *models.PullRequest, doer *models.User, mergeStyle models.Merge
filepath.Join(tmpBasePath, ".git", "rebase-merge", "stopped-sha"), // Git >= 2.26
}
for _, failingCommitPath := range failingCommitPaths {
- if _, statErr := os.Stat(filepath.Join(failingCommitPath)); statErr == nil {
- commitShaBytes, readErr := os.ReadFile(filepath.Join(failingCommitPath))
+ if _, statErr := os.Stat(failingCommitPath); statErr == nil {
+ commitShaBytes, readErr := os.ReadFile(failingCommitPath)
if readErr != nil {
// Abandon this attempt to handle the error
log.Error("git rebase staging on to base [%s:%s -> %s:%s]: %v\n%s\n%s", pr.HeadRepo.FullName(), pr.HeadBranch, pr.BaseRepo.FullName(), pr.BaseBranch, err, outbuf.String(), errbuf.String())
diff --git a/services/release/release_test.go b/services/release/release_test.go
index e53e4c935b7c..d720bf996b07 100644
--- a/services/release/release_test.go
+++ b/services/release/release_test.go
@@ -11,7 +11,7 @@ import (
"time"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/services/attachment"
@@ -19,14 +19,14 @@ import (
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
func TestRelease_Create(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
repoPath := models.RepoPath(user.Name, repo.Name)
gitRepo, err := git.OpenRepository(repoPath)
@@ -127,10 +127,10 @@ func TestRelease_Create(t *testing.T) {
}
func TestRelease_Update(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
repoPath := models.RepoPath(user.Name, repo.Name)
gitRepo, err := git.OpenRepository(repoPath)
@@ -269,10 +269,10 @@ func TestRelease_Update(t *testing.T) {
}
func TestRelease_createTag(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
repoPath := models.RepoPath(user.Name, repo.Name)
gitRepo, err := git.OpenRepository(repoPath)
@@ -352,9 +352,9 @@ func TestRelease_createTag(t *testing.T) {
}
func TestCreateNewTag(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
assert.NoError(t, CreateNewTag(user, repo, "master", "v2.0",
"v2.0 is released \n\n BUGFIX: .... \n\n 123"))
diff --git a/modules/repository/adopt.go b/services/repository/adopt.go
similarity index 73%
rename from modules/repository/adopt.go
rename to services/repository/adopt.go
index 21477ab7d771..d48411fbb427 100644
--- a/modules/repository/adopt.go
+++ b/services/repository/adopt.go
@@ -15,12 +15,15 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/notification"
+ repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
+
"github.com/gobwas/glob"
)
-// AdoptRepository adopts a repository for the user/organization.
+// AdoptRepository adopts pre-existing repository files for the user/organization.
func AdoptRepository(doer, u *models.User, opts models.CreateRepoOptions) (*models.Repository, error) {
if !doer.IsAdmin && !u.CanCreateRepo() {
return nil, models.ErrReachLimitOfRepo{
@@ -90,9 +93,97 @@ func AdoptRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mode
return nil, err
}
+ notification.NotifyCreateRepository(doer, u, repo)
+
return repo, nil
}
+func adoptRepository(ctx context.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
+ isExist, err := util.IsExist(repoPath)
+ if err != nil {
+ log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
+ return err
+ }
+ if !isExist {
+ return fmt.Errorf("adoptRepository: path does not already exist: %s", repoPath)
+ }
+
+ if err := repo_module.CreateDelegateHooks(repoPath); err != nil {
+ return fmt.Errorf("createDelegateHooks: %v", err)
+ }
+
+ // Re-fetch the repository from database before updating it (else it would
+ // override changes that were done earlier with sql)
+ if repo, err = models.GetRepositoryByIDCtx(ctx, repo.ID); err != nil {
+ return fmt.Errorf("getRepositoryByID: %v", err)
+ }
+
+ repo.IsEmpty = false
+ gitRepo, err := git.OpenRepository(repo.RepoPath())
+ if err != nil {
+ return fmt.Errorf("openRepository: %v", err)
+ }
+ defer gitRepo.Close()
+ if len(opts.DefaultBranch) > 0 {
+ repo.DefaultBranch = opts.DefaultBranch
+
+ if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
+ return fmt.Errorf("setDefaultBranch: %v", err)
+ }
+ } else {
+ repo.DefaultBranch, err = gitRepo.GetDefaultBranch()
+ if err != nil {
+ repo.DefaultBranch = setting.Repository.DefaultBranch
+ if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
+ return fmt.Errorf("setDefaultBranch: %v", err)
+ }
+ }
+
+ repo.DefaultBranch = strings.TrimPrefix(repo.DefaultBranch, git.BranchPrefix)
+ }
+ branches, _, _ := gitRepo.GetBranches(0, 0)
+ found := false
+ hasDefault := false
+ hasMaster := false
+ hasMain := false
+ for _, branch := range branches {
+ if branch == repo.DefaultBranch {
+ found = true
+ break
+ } else if branch == setting.Repository.DefaultBranch {
+ hasDefault = true
+ } else if branch == "master" {
+ hasMaster = true
+ } else if branch == "main" {
+ hasMain = true
+ }
+ }
+ if !found {
+ if hasDefault {
+ repo.DefaultBranch = setting.Repository.DefaultBranch
+ } else if hasMaster {
+ repo.DefaultBranch = "master"
+ } else if hasMain {
+ repo.DefaultBranch = "main"
+ } else if len(branches) > 0 {
+ repo.DefaultBranch = branches[0]
+ } else {
+ repo.IsEmpty = true
+ repo.DefaultBranch = setting.Repository.DefaultBranch
+ }
+
+ if err = gitRepo.SetDefaultBranch(repo.DefaultBranch); err != nil {
+ return fmt.Errorf("setDefaultBranch: %v", err)
+ }
+ }
+
+ if err = models.UpdateRepositoryCtx(ctx, repo, false); err != nil {
+ return fmt.Errorf("updateRepository: %v", err)
+ }
+
+ return nil
+}
+
// DeleteUnadoptedRepository deletes unadopted repository files from the filesystem
func DeleteUnadoptedRepository(doer, u *models.User, repoName string) error {
if err := models.IsUsableRepoName(repoName); err != nil {
@@ -154,7 +245,7 @@ func ListUnadoptedRepositories(query string, opts *db.ListOptions) ([]string, in
count := 0
// We're going to iterate by pagesize.
- root := filepath.Join(setting.RepoRootPath)
+ root := filepath.Clean(setting.RepoRootPath)
if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
diff --git a/modules/repository/archive.go b/services/repository/archive.go
similarity index 100%
rename from modules/repository/archive.go
rename to services/repository/archive.go
diff --git a/modules/repository/fork.go b/services/repository/fork.go
similarity index 95%
rename from modules/repository/fork.go
rename to services/repository/fork.go
index df1dccc596c5..f052d18a7591 100644
--- a/modules/repository/fork.go
+++ b/services/repository/fork.go
@@ -14,6 +14,8 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/notification"
+ repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
)
@@ -116,7 +118,7 @@ func ForkRepository(doer, owner *models.User, opts models.ForkRepoOptions) (_ *m
return fmt.Errorf("git update-server-info: %v", err)
}
- if err = createDelegateHooks(repoPath); err != nil {
+ if err = repo_module.CreateDelegateHooks(repoPath); err != nil {
return fmt.Errorf("createDelegateHooks: %v", err)
}
return nil
@@ -136,6 +138,8 @@ func ForkRepository(doer, owner *models.User, opts models.ForkRepoOptions) (_ *m
log.Error("Copy language stat from oldRepo failed")
}
+ notification.NotifyForkRepository(doer, opts.BaseRepo, repo)
+
return repo, nil
}
diff --git a/modules/repository/fork_test.go b/services/repository/fork_test.go
similarity index 68%
rename from modules/repository/fork_test.go
rename to services/repository/fork_test.go
index 7a05f9dd97e3..197d76b0561a 100644
--- a/modules/repository/fork_test.go
+++ b/services/repository/fork_test.go
@@ -8,16 +8,16 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"github.com/stretchr/testify/assert"
)
func TestForkRepository(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
// user 13 has already forked repo10
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 13}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 13}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
fork, err := ForkRepository(user, user, models.ForkRepoOptions{
BaseRepo: repo,
diff --git a/services/repository/main_test.go b/services/repository/main_test.go
index 91d0d36ca026..262d3394818b 100644
--- a/services/repository/main_test.go
+++ b/services/repository/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
diff --git a/services/repository/repository.go b/services/repository/repository.go
index cde4af2afa8a..98d160c22390 100644
--- a/services/repository/repository.go
+++ b/services/repository/repository.go
@@ -28,36 +28,6 @@ func CreateRepository(doer, owner *models.User, opts models.CreateRepoOptions) (
return repo, nil
}
-// AdoptRepository adopts pre-existing repository files for the user/organization.
-func AdoptRepository(doer, owner *models.User, opts models.CreateRepoOptions) (*models.Repository, error) {
- repo, err := repo_module.AdoptRepository(doer, owner, opts)
- if err != nil {
- // No need to rollback here we should do this in AdoptRepository...
- return nil, err
- }
-
- notification.NotifyCreateRepository(doer, owner, repo)
-
- return repo, nil
-}
-
-// DeleteUnadoptedRepository adopts pre-existing repository files for the user/organization.
-func DeleteUnadoptedRepository(doer, owner *models.User, name string) error {
- return repo_module.DeleteUnadoptedRepository(doer, owner, name)
-}
-
-// ForkRepository forks a repository
-func ForkRepository(doer, u *models.User, opts models.ForkRepoOptions) (*models.Repository, error) {
- repo, err := repo_module.ForkRepository(doer, u, opts)
- if err != nil {
- return nil, err
- }
-
- notification.NotifyForkRepository(doer, opts.BaseRepo, repo)
-
- return repo, nil
-}
-
// DeleteRepository deletes a repository for a user or organization.
func DeleteRepository(doer *models.User, repo *models.Repository) error {
if err := pull_service.CloseRepoBranchesPulls(doer, repo); err != nil {
diff --git a/services/repository/transfer_test.go b/services/repository/transfer_test.go
index 40ccfdfb52fa..09c9829216a3 100644
--- a/services/repository/transfer_test.go
+++ b/services/repository/transfer_test.go
@@ -9,7 +9,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/notification/action"
"code.gitea.io/gitea/modules/util"
@@ -28,14 +28,14 @@ func registerNotifier() {
func TestTransferOwnership(t *testing.T) {
registerNotifier()
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
- doer := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
- repo.Owner = db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
+ repo.Owner = unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
assert.NoError(t, TransferOwnership(doer, doer, repo, nil))
- transferredRepo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
+ transferredRepo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
assert.EqualValues(t, 2, transferredRepo.OwnerID)
exist, err := util.IsExist(models.RepoPath("user3", "repo3"))
@@ -44,23 +44,23 @@ func TestTransferOwnership(t *testing.T) {
exist, err = util.IsExist(models.RepoPath("user2", "repo3"))
assert.NoError(t, err)
assert.True(t, exist)
- db.AssertExistsAndLoadBean(t, &models.Action{
+ unittest.AssertExistsAndLoadBean(t, &models.Action{
OpType: models.ActionTransferRepo,
ActUserID: 2,
RepoID: 3,
Content: "user3/repo3",
})
- models.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
+ unittest.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
}
func TestStartRepositoryTransferSetPermission(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
- doer := db.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
- recipient := db.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
- repo.Owner = db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
+ recipient := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
+ repo.Owner = unittest.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
hasAccess, err := models.HasAccess(recipient.ID, repo)
assert.NoError(t, err)
@@ -72,5 +72,5 @@ func TestStartRepositoryTransferSetPermission(t *testing.T) {
assert.NoError(t, err)
assert.True(t, hasAccess)
- models.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
+ unittest.CheckConsistencyFor(t, &models.Repository{}, &models.User{}, &models.Team{})
}
diff --git a/services/webhook/main_test.go b/services/webhook/main_test.go
index 7aef4b3a51ef..fc58f72565f9 100644
--- a/services/webhook/main_test.go
+++ b/services/webhook/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
diff --git a/services/webhook/webhook_test.go b/services/webhook/webhook_test.go
index 75f19e50ce98..0a649d36aed8 100644
--- a/services/webhook/webhook_test.go
+++ b/services/webhook/webhook_test.go
@@ -8,7 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
webhook_model "code.gitea.io/gitea/models/webhook"
api "code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -27,52 +27,52 @@ func TestWebhook_GetSlackHook(t *testing.T) {
}
func TestPrepareWebhooks(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
hookTasks := []*webhook_model.HookTask{
{RepoID: repo.ID, HookID: 1, EventType: webhook_model.HookEventPush},
}
for _, hookTask := range hookTasks {
- db.AssertNotExistsBean(t, hookTask)
+ unittest.AssertNotExistsBean(t, hookTask)
}
assert.NoError(t, PrepareWebhooks(repo, webhook_model.HookEventPush, &api.PushPayload{Commits: []*api.PayloadCommit{{}}}))
for _, hookTask := range hookTasks {
- db.AssertExistsAndLoadBean(t, hookTask)
+ unittest.AssertExistsAndLoadBean(t, hookTask)
}
}
func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
hookTasks := []*webhook_model.HookTask{
{RepoID: repo.ID, HookID: 4, EventType: webhook_model.HookEventPush},
}
for _, hookTask := range hookTasks {
- db.AssertNotExistsBean(t, hookTask)
+ unittest.AssertNotExistsBean(t, hookTask)
}
// this test also ensures that * doesn't handle / in any special way (like shell would)
assert.NoError(t, PrepareWebhooks(repo, webhook_model.HookEventPush, &api.PushPayload{Ref: "refs/heads/feature/7791", Commits: []*api.PayloadCommit{{}}}))
for _, hookTask := range hookTasks {
- db.AssertExistsAndLoadBean(t, hookTask)
+ unittest.AssertExistsAndLoadBean(t, hookTask)
}
}
func TestPrepareWebhooksBranchFilterNoMatch(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
hookTasks := []*webhook_model.HookTask{
{RepoID: repo.ID, HookID: 4, EventType: webhook_model.HookEventPush},
}
for _, hookTask := range hookTasks {
- db.AssertNotExistsBean(t, hookTask)
+ unittest.AssertNotExistsBean(t, hookTask)
}
assert.NoError(t, PrepareWebhooks(repo, webhook_model.HookEventPush, &api.PushPayload{Ref: "refs/heads/fix_weird_bug"}))
for _, hookTask := range hookTasks {
- db.AssertNotExistsBean(t, hookTask)
+ unittest.AssertNotExistsBean(t, hookTask)
}
}
diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go
index d6a65cc23a82..ee548d23158c 100644
--- a/services/wiki/wiki_test.go
+++ b/services/wiki/wiki_test.go
@@ -10,7 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
+ "code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/util"
@@ -18,7 +18,7 @@ import (
)
func TestMain(m *testing.M) {
- db.MainTest(m, filepath.Join("..", ".."))
+ unittest.MainTest(m, filepath.Join("..", ".."))
}
func TestWikiNameToSubURL(t *testing.T) {
@@ -110,23 +110,23 @@ func TestWikiNameToFilenameToName(t *testing.T) {
}
func TestRepository_InitWiki(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
// repo1 already has a wiki
- repo1 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
assert.NoError(t, InitWiki(repo1))
// repo2 does not already have a wiki
- repo2 := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
+ repo2 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
assert.NoError(t, InitWiki(repo2))
assert.True(t, repo2.HasWiki())
}
func TestRepository_AddWikiPage(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
const wikiContent = "This is the wiki content"
const commitMsg = "Commit message"
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- doer := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
for _, wikiName := range []string{
"Another page",
"Here's a and a/slash",
@@ -166,18 +166,18 @@ func TestRepository_AddWikiPage(t *testing.T) {
}
func TestRepository_EditWikiPage(t *testing.T) {
- assert.NoError(t, db.PrepareTestDatabase())
+ assert.NoError(t, unittest.PrepareTestDatabase())
const newWikiContent = "This is the new content"
const commitMsg = "Commit message"
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- doer := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
for _, newWikiName := range []string{
"Home", // same name as before
"New home",
"New/name/with/slashes",
} {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
assert.NoError(t, EditWikiPage(doer, repo, "Home", newWikiName, newWikiContent, commitMsg))
// Now need to show that the page has been added:
@@ -199,9 +199,9 @@ func TestRepository_EditWikiPage(t *testing.T) {
}
func TestRepository_DeleteWikiPage(t *testing.T) {
- db.PrepareTestEnv(t)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
- doer := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+ unittest.PrepareTestEnv(t)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ doer := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
assert.NoError(t, DeleteWikiPage(doer, repo, "Home"))
// Now need to show that the page has been added:
@@ -216,8 +216,8 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
}
func TestPrepareWikiFileName(t *testing.T) {
- db.PrepareTestEnv(t)
- repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ unittest.PrepareTestEnv(t)
+ repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
gitRepo, err := git.OpenRepository(repo.WikiPath())
defer gitRepo.Close()
assert.NoError(t, err)
@@ -267,7 +267,7 @@ func TestPrepareWikiFileName(t *testing.T) {
}
func TestPrepareWikiFileName_FirstPage(t *testing.T) {
- db.PrepareTestEnv(t)
+ unittest.PrepareTestEnv(t)
// Now create a temporaryDirectory
tmpDir, err := os.MkdirTemp("", "empty-wiki")
diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl
index f05daaa42120..d529e6bfda76 100644
--- a/templates/base/head.tmpl
+++ b/templates/base/head.tmpl
@@ -46,6 +46,10 @@
]).values()),
{{end}}
mermaidMaxSourceCharacters: {{MermaidMaxSourceCharacters}},
+ i18n: {
+ copy_success: '{{.i18n.Tr "copy_success"}}',
+ copy_error: '{{.i18n.Tr "copy_error"}}',
+ }
};
diff --git a/templates/repo/clone_buttons.tmpl b/templates/repo/clone_buttons.tmpl
index 0a86e586fc9f..37a88af945fc 100644
--- a/templates/repo/clone_buttons.tmpl
+++ b/templates/repo/clone_buttons.tmpl
@@ -14,7 +14,7 @@
{{end}}
{{if or (not $.DisableHTTP) (and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH))}}
-