-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move some actions to notification/action #8779
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,49 +283,6 @@ func (a *Action) GetIssueContent() string { | |
return issue.Content | ||
} | ||
|
||
func newRepoAction(e Engine, u *User, repo *Repository) (err error) { | ||
if err = notifyWatchers(e, &Action{ | ||
ActUserID: u.ID, | ||
ActUser: u, | ||
OpType: ActionCreateRepo, | ||
RepoID: repo.ID, | ||
Repo: repo, | ||
IsPrivate: repo.IsPrivate, | ||
}); err != nil { | ||
return fmt.Errorf("notify watchers '%d/%d': %v", u.ID, repo.ID, err) | ||
} | ||
|
||
log.Trace("action.newRepoAction: %s/%s", u.Name, repo.Name) | ||
return err | ||
} | ||
|
||
// NewRepoAction adds new action for creating repository. | ||
func NewRepoAction(u *User, repo *Repository) (err error) { | ||
return newRepoAction(x, u, repo) | ||
} | ||
|
||
func renameRepoAction(e Engine, actUser *User, oldRepoName string, repo *Repository) (err error) { | ||
if err = notifyWatchers(e, &Action{ | ||
ActUserID: actUser.ID, | ||
ActUser: actUser, | ||
OpType: ActionRenameRepo, | ||
RepoID: repo.ID, | ||
Repo: repo, | ||
IsPrivate: repo.IsPrivate, | ||
Content: oldRepoName, | ||
}); err != nil { | ||
return fmt.Errorf("notify watchers: %v", err) | ||
} | ||
|
||
log.Trace("action.renameRepoAction: %s/%s", actUser.Name, repo.Name) | ||
return nil | ||
} | ||
|
||
// RenameRepoAction adds new action for renaming a repository. | ||
func RenameRepoAction(actUser *User, oldRepoName string, repo *Repository) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return renameRepoAction(x, actUser, oldRepoName, repo) | ||
} | ||
|
||
// PushCommit represents a commit in a push operation. | ||
type PushCommit struct { | ||
Sha1 string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ package models | |
|
||
import ( | ||
"path" | ||
"strings" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/modules/setting" | ||
|
@@ -28,58 +27,6 @@ func TestAction_GetRepoLink(t *testing.T) { | |
assert.Equal(t, expected, action.GetRepoLink()) | ||
} | ||
|
||
func TestNewRepoAction(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
assert.NoError(t, PrepareTestDatabase()) | ||
|
||
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) | ||
repo := AssertExistsAndLoadBean(t, &Repository{OwnerID: user.ID}).(*Repository) | ||
repo.Owner = user | ||
|
||
actionBean := &Action{ | ||
OpType: ActionCreateRepo, | ||
ActUserID: user.ID, | ||
RepoID: repo.ID, | ||
ActUser: user, | ||
Repo: repo, | ||
IsPrivate: repo.IsPrivate, | ||
} | ||
|
||
AssertNotExistsBean(t, actionBean) | ||
assert.NoError(t, NewRepoAction(user, repo)) | ||
AssertExistsAndLoadBean(t, actionBean) | ||
CheckConsistencyFor(t, &Action{}) | ||
} | ||
|
||
func TestRenameRepoAction(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
|
||
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) | ||
repo := AssertExistsAndLoadBean(t, &Repository{OwnerID: user.ID}).(*Repository) | ||
repo.Owner = user | ||
|
||
oldRepoName := repo.Name | ||
const newRepoName = "newRepoName" | ||
repo.Name = newRepoName | ||
repo.LowerName = strings.ToLower(newRepoName) | ||
|
||
actionBean := &Action{ | ||
OpType: ActionRenameRepo, | ||
ActUserID: user.ID, | ||
ActUser: user, | ||
RepoID: repo.ID, | ||
Repo: repo, | ||
IsPrivate: repo.IsPrivate, | ||
Content: oldRepoName, | ||
} | ||
AssertNotExistsBean(t, actionBean) | ||
assert.NoError(t, RenameRepoAction(user, oldRepoName, repo)) | ||
AssertExistsAndLoadBean(t, actionBean) | ||
|
||
_, err := x.ID(repo.ID).Cols("name", "lower_name").Update(repo) | ||
assert.NoError(t, err) | ||
CheckConsistencyFor(t, &Action{}) | ||
} | ||
|
||
func TestPushCommits_ToAPIPayloadCommits(t *testing.T) { | ||
pushCommits := NewPushCommits() | ||
pushCommits.Commits = []*PushCommit{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ var ( | |
_ base.Notifier = &actionNotifier{} | ||
) | ||
|
||
// NewNotifier create a new webhookNotifier notifier | ||
// NewNotifier create a new actionNotifier notifier | ||
func NewNotifier() base.Notifier { | ||
return &actionNotifier{} | ||
} | ||
|
@@ -75,3 +75,19 @@ func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest) { | |
log.Error("NotifyWatchers: %v", err) | ||
} | ||
} | ||
|
||
func (a *actionNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems weird that this is the only action in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guillep2k That will result an import recycle. The dependency cycle is I will move more |
||
if err := models.NotifyWatchers(&models.Action{ | ||
ActUserID: doer.ID, | ||
ActUser: doer, | ||
OpType: models.ActionRenameRepo, | ||
RepoID: repo.ID, | ||
Repo: repo, | ||
IsPrivate: repo.IsPrivate, | ||
Content: oldName, | ||
}); err != nil { | ||
log.Error("notify watchers: %v", err) | ||
} else { | ||
log.Trace("action.renameRepoAction: %s/%s", doer.Name, repo.Name) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2019 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 action | ||
|
||
import ( | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
models.MainTest(m, filepath.Join("..", "..", "..")) | ||
} | ||
|
||
func TestRenameRepoAction(t *testing.T) { | ||
assert.NoError(t, models.PrepareTestDatabase()) | ||
|
||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) | ||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID}).(*models.Repository) | ||
repo.Owner = user | ||
|
||
oldRepoName := repo.Name | ||
const newRepoName = "newRepoName" | ||
repo.Name = newRepoName | ||
repo.LowerName = strings.ToLower(newRepoName) | ||
|
||
actionBean := &models.Action{ | ||
OpType: models.ActionRenameRepo, | ||
ActUserID: user.ID, | ||
ActUser: user, | ||
RepoID: repo.ID, | ||
Repo: repo, | ||
IsPrivate: repo.IsPrivate, | ||
Content: oldRepoName, | ||
} | ||
models.AssertNotExistsBean(t, actionBean) | ||
|
||
NewNotifier().NotifyRenameRepository(user, repo, oldRepoName) | ||
|
||
models.AssertExistsAndLoadBean(t, actionBean) | ||
models.CheckConsistencyFor(t, &models.Action{}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conflicts with https://github.com/go-gitea/gitea/pull/8573/files#diff-7603238519a500de37f3e4b25cef1800L307
-> wich also remove this function