aboutsummaryrefslogtreecommitdiffstats
path: root/modules/repofiles
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-01-10 17:34:21 +0800
committerGitHub <noreply@github.com>2020-01-10 17:34:21 +0800
commit99d869fa63e07780f1a17d1a9599187b9b689d9b (patch)
treeecadeba077cf0ae58d0a21f232d280fec60c779a /modules/repofiles
parent384c2b342ec01fadb520572666127cb5564e1050 (diff)
downloadgitea-99d869fa63e07780f1a17d1a9599187b9b689d9b.tar.gz
gitea-99d869fa63e07780f1a17d1a9599187b9b689d9b.zip
Move push commits from models to modules/repository (#9370)
* Move push commits from models to modules/repository * fix test * fix test * fix test * fix test * fix test Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/repofiles')
-rw-r--r--modules/repofiles/action.go9
-rw-r--r--modules/repofiles/action_test.go23
-rw-r--r--modules/repofiles/update.go11
3 files changed, 23 insertions, 20 deletions
diff --git a/modules/repofiles/action.go b/modules/repofiles/action.go
index d207247114..07bc1b875b 100644
--- a/modules/repofiles/action.go
+++ b/modules/repofiles/action.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/references"
+ "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
)
@@ -59,7 +60,7 @@ func changeIssueStatus(repo *models.Repository, issue *models.Issue, doer *model
}
// UpdateIssuesCommit checks if issues are manipulated by commit message.
-func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*models.PushCommit, branchName string) error {
+func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*repository.PushCommit, branchName string) error {
// Commits are appended in the reverse order.
for i := len(commits) - 1; i >= 0; i-- {
c := commits[i]
@@ -154,7 +155,7 @@ type CommitRepoActionOptions struct {
RefFullName string
OldCommitID string
NewCommitID string
- Commits *models.PushCommits
+ Commits *repository.PushCommits
}
// CommitRepoAction adds new commit action to the repository, and prepare
@@ -216,10 +217,10 @@ func CommitRepoAction(optsList ...*CommitRepoActionOptions) error {
if opts.NewCommitID == git.EmptySHA {
opType = models.ActionDeleteTag
}
- opts.Commits = &models.PushCommits{}
+ opts.Commits = &repository.PushCommits{}
} else if opts.NewCommitID == git.EmptySHA {
opType = models.ActionDeleteBranch
- opts.Commits = &models.PushCommits{}
+ opts.Commits = &repository.PushCommits{}
} else {
// if not the first commit, set the compare URL.
if opts.OldCommitID == git.EmptySHA {
diff --git a/modules/repofiles/action_test.go b/modules/repofiles/action_test.go
index 97ac1c45e9..85bf39c835 100644
--- a/modules/repofiles/action_test.go
+++ b/modules/repofiles/action_test.go
@@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/repository"
"github.com/stretchr/testify/assert"
)
@@ -34,8 +35,8 @@ func TestCommitRepoAction(t *testing.T) {
RefFullName: "refName",
OldCommitID: "oldCommitID",
NewCommitID: "newCommitID",
- Commits: &models.PushCommits{
- Commits: []*models.PushCommit{
+ Commits: &repository.PushCommits{
+ Commits: []*repository.PushCommit{
{
Sha1: "69554a6",
CommitterEmail: "user2@example.com",
@@ -68,7 +69,7 @@ func TestCommitRepoAction(t *testing.T) {
RefFullName: git.TagPrefix + "v1.1",
OldCommitID: git.EmptySHA,
NewCommitID: "newCommitID",
- Commits: &models.PushCommits{},
+ Commits: &repository.PushCommits{},
},
action: models.Action{
OpType: models.ActionPushTag,
@@ -82,7 +83,7 @@ func TestCommitRepoAction(t *testing.T) {
RefFullName: git.TagPrefix + "v1.1",
OldCommitID: "oldCommitID",
NewCommitID: git.EmptySHA,
- Commits: &models.PushCommits{},
+ Commits: &repository.PushCommits{},
},
action: models.Action{
OpType: models.ActionDeleteTag,
@@ -96,7 +97,7 @@ func TestCommitRepoAction(t *testing.T) {
RefFullName: git.BranchPrefix + "feature/1",
OldCommitID: "oldCommitID",
NewCommitID: git.EmptySHA,
- Commits: &models.PushCommits{},
+ Commits: &repository.PushCommits{},
},
action: models.Action{
OpType: models.ActionDeleteBranch,
@@ -127,7 +128,7 @@ func TestCommitRepoAction(t *testing.T) {
func TestUpdateIssuesCommit(t *testing.T) {
assert.NoError(t, models.PrepareTestDatabase())
- pushCommits := []*models.PushCommit{
+ pushCommits := []*repository.PushCommit{
{
Sha1: "abcdef1",
CommitterEmail: "user2@example.com",
@@ -174,7 +175,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
models.CheckConsistencyFor(t, &models.Action{})
// Test that push to a non-default branch closes no issue.
- pushCommits = []*models.PushCommit{
+ pushCommits = []*repository.PushCommit{
{
Sha1: "abcdef1",
CommitterEmail: "user2@example.com",
@@ -203,7 +204,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
func TestUpdateIssuesCommit_Colon(t *testing.T) {
assert.NoError(t, models.PrepareTestDatabase())
- pushCommits := []*models.PushCommit{
+ pushCommits := []*repository.PushCommit{
{
Sha1: "abcdef2",
CommitterEmail: "user2@example.com",
@@ -231,7 +232,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
// Test that push to a non-default branch closes an issue.
- pushCommits := []*models.PushCommit{
+ pushCommits := []*repository.PushCommit{
{
Sha1: "abcdef1",
CommitterEmail: "user2@example.com",
@@ -266,7 +267,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
// Test that a push to default branch closes issue in another repo
// If the user also has push permissions to that repo
- pushCommits := []*models.PushCommit{
+ pushCommits := []*repository.PushCommit{
{
Sha1: "abcdef1",
CommitterEmail: "user2@example.com",
@@ -301,7 +302,7 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
// Test that a push with close reference *can not* close issue
// If the commiter doesn't have push rights in that repo
- pushCommits := []*models.PushCommit{
+ pushCommits := []*repository.PushCommit{
{
Sha1: "abcdef3",
CommitterEmail: "user10@example.com",
diff --git a/modules/repofiles/update.go b/modules/repofiles/update.go
index 7ad4a4d388..3a0ba668c1 100644
--- a/modules/repofiles/update.go
+++ b/modules/repofiles/update.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
pull_service "code.gitea.io/gitea/services/pull"
@@ -549,7 +550,7 @@ func createCommitRepoActions(repo *models.Repository, gitRepo *git.Repository, o
if isNewRef && isDelRef {
return nil, fmt.Errorf("Old and new revisions are both %s", git.EmptySHA)
}
- var commits = &models.PushCommits{}
+ var commits = &repository.PushCommits{}
if strings.HasPrefix(opts.RefFullName, git.TagPrefix) {
// If is tag reference
tagName := opts.RefFullName[len(git.TagPrefix):]
@@ -584,7 +585,7 @@ func createCommitRepoActions(repo *models.Repository, gitRepo *git.Repository, o
}
}
- commits = models.ListToPushCommits(l)
+ commits = repository.ListToPushCommits(l)
}
actions = append(actions, &CommitRepoActionOptions{
PusherName: opts.PusherName,
@@ -609,7 +610,7 @@ func createCommitRepoActionOption(repo *models.Repository, gitRepo *git.Reposito
return nil, fmt.Errorf("Old and new revisions are both %s", git.EmptySHA)
}
- var commits = &models.PushCommits{}
+ var commits = &repository.PushCommits{}
if strings.HasPrefix(opts.RefFullName, git.TagPrefix) {
// If is tag reference
tagName := opts.RefFullName[len(git.TagPrefix):]
@@ -620,7 +621,7 @@ func createCommitRepoActionOption(repo *models.Repository, gitRepo *git.Reposito
} else {
// Clear cache for tag commit count
cache.Remove(repo.GetCommitsCountCacheKey(tagName, true))
- if err := models.PushUpdateAddTag(repo, gitRepo, tagName); err != nil {
+ if err := repository.PushUpdateAddTag(repo, gitRepo, tagName); err != nil {
return nil, fmt.Errorf("PushUpdateAddTag: %v", err)
}
}
@@ -649,7 +650,7 @@ func createCommitRepoActionOption(repo *models.Repository, gitRepo *git.Reposito
}
}
- commits = models.ListToPushCommits(l)
+ commits = repository.ListToPushCommits(l)
}
return &CommitRepoActionOptions{