summaryrefslogtreecommitdiffstats
path: root/services/wiki
diff options
context:
space:
mode:
Diffstat (limited to 'services/wiki')
-rw-r--r--services/wiki/wiki.go21
-rw-r--r--services/wiki/wiki_test.go13
2 files changed, 18 insertions, 16 deletions
diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go
index cf25c33274..18e9b26d81 100644
--- a/services/wiki/wiki.go
+++ b/services/wiki/wiki.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/models"
admin_model "code.gitea.io/gitea/models/admin"
"code.gitea.io/gitea/models/db"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
@@ -70,7 +71,7 @@ func FilenameToName(filename string) (string, error) {
// InitWiki initializes a wiki for repository,
// it does nothing when repository already has wiki.
-func InitWiki(repo *models.Repository) error {
+func InitWiki(repo *repo_model.Repository) error {
if repo.HasWiki() {
return nil
}
@@ -117,7 +118,7 @@ func prepareWikiFileName(gitRepo *git.Repository, wikiName string) (bool, string
}
// updateWikiPage adds a new page to the repository wiki.
-func updateWikiPage(doer *user_model.User, repo *models.Repository, oldWikiName, newWikiName, content, message string, isNew bool) (err error) {
+func updateWikiPage(doer *user_model.User, repo *repo_model.Repository, oldWikiName, newWikiName, content, message string, isNew bool) (err error) {
if err = nameAllowed(newWikiName); err != nil {
return err
}
@@ -224,10 +225,10 @@ func updateWikiPage(doer *user_model.User, repo *models.Repository, oldWikiName,
committer := doer.NewGitSig()
- sign, signingKey, signer, _ := repo.SignWikiCommit(doer)
+ sign, signingKey, signer, _ := models.SignWikiCommit(repo, doer)
if sign {
commitTreeOpts.KeyID = signingKey
- if repo.GetTrustModel() == models.CommitterTrustModel || repo.GetTrustModel() == models.CollaboratorCommitterTrustModel {
+ if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel {
committer = signer
}
} else {
@@ -265,18 +266,18 @@ func updateWikiPage(doer *user_model.User, repo *models.Repository, oldWikiName,
}
// AddWikiPage adds a new wiki page with a given wikiPath.
-func AddWikiPage(doer *user_model.User, repo *models.Repository, wikiName, content, message string) error {
+func AddWikiPage(doer *user_model.User, repo *repo_model.Repository, wikiName, content, message string) error {
return updateWikiPage(doer, repo, "", wikiName, content, message, true)
}
// EditWikiPage updates a wiki page identified by its wikiPath,
// optionally also changing wikiPath.
-func EditWikiPage(doer *user_model.User, repo *models.Repository, oldWikiName, newWikiName, content, message string) error {
+func EditWikiPage(doer *user_model.User, repo *repo_model.Repository, oldWikiName, newWikiName, content, message string) error {
return updateWikiPage(doer, repo, oldWikiName, newWikiName, content, message, false)
}
// DeleteWikiPage deletes a wiki page identified by its path.
-func DeleteWikiPage(doer *user_model.User, repo *models.Repository, wikiName string) (err error) {
+func DeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, wikiName string) (err error) {
wikiWorkingPool.CheckIn(fmt.Sprint(repo.ID))
defer wikiWorkingPool.CheckOut(fmt.Sprint(repo.ID))
@@ -342,10 +343,10 @@ func DeleteWikiPage(doer *user_model.User, repo *models.Repository, wikiName str
committer := doer.NewGitSig()
- sign, signingKey, signer, _ := repo.SignWikiCommit(doer)
+ sign, signingKey, signer, _ := models.SignWikiCommit(repo, doer)
if sign {
commitTreeOpts.KeyID = signingKey
- if repo.GetTrustModel() == models.CommitterTrustModel || repo.GetTrustModel() == models.CollaboratorCommitterTrustModel {
+ if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel {
committer = signer
}
} else {
@@ -372,7 +373,7 @@ func DeleteWikiPage(doer *user_model.User, repo *models.Repository, wikiName str
}
// DeleteWiki removes the actual and local copy of repository wiki.
-func DeleteWiki(repo *models.Repository) error {
+func DeleteWiki(repo *repo_model.Repository) error {
if err := models.UpdateRepositoryUnits(repo, nil, []unit.Type{unit.TypeWiki}); err != nil {
return err
}
diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go
index 5b42dd590f..659666f977 100644
--- a/services/wiki/wiki_test.go
+++ b/services/wiki/wiki_test.go
@@ -10,6 +10,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
@@ -113,11 +114,11 @@ func TestWikiNameToFilenameToName(t *testing.T) {
func TestRepository_InitWiki(t *testing.T) {
unittest.PrepareTestEnv(t)
// repo1 already has a wiki
- repo1 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
assert.NoError(t, InitWiki(repo1))
// repo2 does not already have a wiki
- repo2 := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
+ repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2}).(*repo_model.Repository)
assert.NoError(t, InitWiki(repo2))
assert.True(t, repo2.HasWiki())
}
@@ -126,7 +127,7 @@ func TestRepository_AddWikiPage(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
const wikiContent = "This is the wiki content"
const commitMsg = "Commit message"
- repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
for _, wikiName := range []string{
"Another page",
@@ -171,7 +172,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
const newWikiContent = "This is the new content"
const commitMsg = "Commit message"
- repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
for _, newWikiName := range []string{
"Home", // same name as before
@@ -201,7 +202,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
func TestRepository_DeleteWikiPage(t *testing.T) {
unittest.PrepareTestEnv(t)
- repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User)
assert.NoError(t, DeleteWikiPage(doer, repo, "Home"))
@@ -218,7 +219,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
func TestPrepareWikiFileName(t *testing.T) {
unittest.PrepareTestEnv(t)
- repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
gitRepo, err := git.OpenRepository(repo.WikiPath())
defer gitRepo.Close()
assert.NoError(t, err)