mirror of
https://github.com/go-gitea/gitea
synced 2025-07-23 02:38:35 +00:00
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>
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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",
|
||||
|
@@ -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{
|
||||
|
Reference in New Issue
Block a user