From af12f408840ce902e3b75e247f3c32f8b3492de2 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 1 Nov 2020 11:09:04 +0800 Subject: [PATCH] Remove the push_test since the function has been removed. --- services/repository/push.go | 14 ++-- services/repository/push_test.go | 139 ------------------------------- 2 files changed, 7 insertions(+), 146 deletions(-) delete mode 100644 services/repository/push_test.go diff --git a/services/repository/push.go b/services/repository/push.go index 9f94503b5959..e9f111b3b726 100644 --- a/services/repository/push.go +++ b/services/repository/push.go @@ -128,12 +128,6 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { // Push new branch. var l *list.List if opts.IsNewRef() { - l, err = newCommit.CommitsBeforeLimit(10) - if err != nil { - return fmt.Errorf("newCommit.CommitsBeforeLimit: %v", err) - } - notification.NotifyCreateRef(pusher, repo, "branch", opts.RefFullName) - } else { if repo.IsEmpty { // Change default branch and empty status only if pushed ref is non-empty branch. repo.DefaultBranch = refName repo.IsEmpty = false @@ -150,6 +144,12 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } } + l, err = newCommit.CommitsBeforeLimit(10) + if err != nil { + return fmt.Errorf("newCommit.CommitsBeforeLimit: %v", err) + } + notification.NotifyCreateRef(pusher, repo, "branch", opts.RefFullName) + } else { l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID) if err != nil { return fmt.Errorf("newCommit.CommitsBeforeUntil: %v", err) @@ -170,11 +170,11 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { } } + commits = repo_module.ListToPushCommits(l) if len(commits.Commits) > setting.UI.FeedMaxCommitNum { commits.Commits = commits.Commits[:setting.UI.FeedMaxCommitNum] } commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID) - commits = repo_module.ListToPushCommits(l) notification.NotifyPushCommits(pusher, repo, opts, commits) if err := repofiles.UpdateIssuesCommit(pusher, repo, commits.Commits, refName); err != nil { diff --git a/services/repository/push_test.go b/services/repository/push_test.go deleted file mode 100644 index da24c19d5709..000000000000 --- a/services/repository/push_test.go +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2020 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 repository - -import ( - "testing" - - "code.gitea.io/gitea/models" - "code.gitea.io/gitea/modules/git" - repo_module "code.gitea.io/gitea/modules/repository" - - "github.com/stretchr/testify/assert" -) - -func testCorrectRepoAction(t *testing.T, repo *models.Repository, gitRepo *git.Repository, opts *commitRepoActionOptions, actionBean *models.Action) { - models.AssertNotExistsBean(t, actionBean) - assert.NoError(t, commitRepoAction(repo, gitRepo, opts)) - models.AssertExistsAndLoadBean(t, actionBean) - models.CheckConsistencyFor(t, &models.Action{}) -} - -func TestCommitRepoAction(t *testing.T) { - samples := []struct { - userID int64 - repositoryID int64 - commitRepoActionOptions commitRepoActionOptions - action models.Action - }{ - { - userID: 2, - repositoryID: 16, - commitRepoActionOptions: commitRepoActionOptions{ - PushUpdateOptions: repo_module.PushUpdateOptions{ - RefFullName: "refName", - OldCommitID: "oldCommitID", - NewCommitID: "newCommitID", - }, - Commits: &repo_module.PushCommits{ - Commits: []*repo_module.PushCommit{ - { - Sha1: "69554a6", - CommitterEmail: "user2@example.com", - CommitterName: "User2", - AuthorEmail: "user2@example.com", - AuthorName: "User2", - Message: "not signed commit", - }, - { - Sha1: "27566bd", - CommitterEmail: "user2@example.com", - CommitterName: "User2", - AuthorEmail: "user2@example.com", - AuthorName: "User2", - Message: "good signed commit (with not yet validated email)", - }, - }, - Len: 2, - }, - }, - action: models.Action{ - OpType: models.ActionCommitRepo, - RefName: "refName", - }, - }, - { - userID: 2, - repositoryID: 1, - commitRepoActionOptions: commitRepoActionOptions{ - PushUpdateOptions: repo_module.PushUpdateOptions{ - RefFullName: git.TagPrefix + "v1.1", - OldCommitID: git.EmptySHA, - NewCommitID: "newCommitID", - }, - Commits: &repo_module.PushCommits{}, - }, - action: models.Action{ - OpType: models.ActionPushTag, - RefName: "v1.1", - }, - }, - { - userID: 2, - repositoryID: 1, - commitRepoActionOptions: commitRepoActionOptions{ - PushUpdateOptions: repo_module.PushUpdateOptions{ - RefFullName: git.TagPrefix + "v1.1", - OldCommitID: "oldCommitID", - NewCommitID: git.EmptySHA, - }, - Commits: &repo_module.PushCommits{}, - }, - action: models.Action{ - OpType: models.ActionDeleteTag, - RefName: "v1.1", - }, - }, - { - userID: 2, - repositoryID: 1, - commitRepoActionOptions: commitRepoActionOptions{ - PushUpdateOptions: repo_module.PushUpdateOptions{ - RefFullName: git.BranchPrefix + "feature/1", - OldCommitID: "oldCommitID", - NewCommitID: git.EmptySHA, - }, - Commits: &repo_module.PushCommits{}, - }, - action: models.Action{ - OpType: models.ActionDeleteBranch, - RefName: "feature/1", - }, - }, - } - - for _, s := range samples { - models.PrepareTestEnv(t) - - user := models.AssertExistsAndLoadBean(t, &models.User{ID: s.userID}).(*models.User) - repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: s.repositoryID, OwnerID: user.ID}).(*models.Repository) - repo.Owner = user - - gitRepo, err := git.OpenRepository(repo.RepoPath()) - assert.NoError(t, err) - - s.commitRepoActionOptions.PusherName = user.Name - s.commitRepoActionOptions.RepoOwnerID = user.ID - s.commitRepoActionOptions.RepoName = repo.Name - - s.action.ActUserID = user.ID - s.action.RepoID = repo.ID - s.action.Repo = repo - s.action.IsPrivate = repo.IsPrivate - - testCorrectRepoAction(t, repo, gitRepo, &s.commitRepoActionOptions, &s.action) - gitRepo.Close() - } -}