diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-11-24 17:49:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-24 17:49:20 +0800 |
commit | a666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch) | |
tree | 9ab1434b759a8a2cb275a83149903a823851e309 /modules | |
parent | 4e7ca946da2a2642a62f114825129bf5d7ed9196 (diff) | |
download | gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.tar.gz gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.zip |
Move user related model into models/user (#17781)
* Move user related model into models/user
* Fix lint for windows
* Fix windows lint
* Fix windows lint
* Move some tests in models
* Merge
Diffstat (limited to 'modules')
33 files changed, 363 insertions, 291 deletions
diff --git a/modules/context/context.go b/modules/context/context.go index 6fc4c7261a..5a37f8b0bf 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -20,8 +20,8 @@ import ( "strings" "time" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" mc "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/json" @@ -62,7 +62,7 @@ type Context struct { Link string // current request URL EscapedLink string - User *models.User + User *user_model.User IsSigned bool IsBasicAuth bool @@ -123,7 +123,7 @@ func (ctx *Context) IsUserRepoReaderAny() bool { // RedirectToUser redirect to a differently-named user func RedirectToUser(ctx *Context, userName string, redirectUserID int64) { - user, err := models.GetUserByID(redirectUserID) + user, err := user_model.GetUserByID(redirectUserID) if err != nil { ctx.ServerError("GetUserByID", err) return @@ -560,7 +560,7 @@ func GetContext(req *http.Request) *Context { } // GetContextUser returns context user -func GetContextUser(req *http.Request) *models.User { +func GetContextUser(req *http.Request) *user_model.User { if apiContext, ok := req.Context().Value(apiContextKey).(*APIContext); ok { return apiContext.User } diff --git a/modules/context/org.go b/modules/context/org.go index d4159a32a7..2a3ebdd1e7 100644 --- a/modules/context/org.go +++ b/modules/context/org.go @@ -52,7 +52,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { var err error ctx.Org.Organization, err = models.GetOrgByName(orgName) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { redirectUserID, err := user_model.LookupUserRedirect(orgName) if err == nil { RedirectToUser(ctx, orgName, redirectUserID) @@ -108,7 +108,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) { } } else { // Fake data. - ctx.Data["SignedUser"] = &models.User{} + ctx.Data["SignedUser"] = &user_model.User{} } if (requireMember && !ctx.Org.IsMember) || (requireOwner && !ctx.Org.IsOwner) { diff --git a/modules/context/repo.go b/modules/context/repo.go index 1f1a035267..7feaad4ccd 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/models" unit_model "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/cache" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -55,7 +56,7 @@ type Repository struct { IsViewTag bool IsViewCommit bool Repository *models.Repository - Owner *models.User + Owner *user_model.User Commit *git.Commit Tag *git.Tag GitRepo *git.Repository @@ -104,7 +105,7 @@ type CanCommitToBranchResults struct { // CanCommitToBranch returns true if repository is editable and user has proper access level // and branch is not protected for push -func (r *Repository) CanCommitToBranch(doer *models.User) (CanCommitToBranchResults, error) { +func (r *Repository) CanCommitToBranch(doer *user_model.User) (CanCommitToBranchResults, error) { protectedBranch, err := models.GetProtectedBranchBy(r.Repository.ID, r.BranchName) if err != nil { @@ -145,7 +146,7 @@ func (r *Repository) CanCommitToBranch(doer *models.User) (CanCommitToBranchResu } // CanUseTimetracker returns whether or not a user can use the timetracker. -func (r *Repository) CanUseTimetracker(issue *models.Issue, user *models.User) bool { +func (r *Repository) CanUseTimetracker(issue *models.Issue, user *user_model.User) bool { // Checking for following: // 1. Is timetracker enabled // 2. Is the user a contributor, admin, poster or assignee and do the repository policies require this? @@ -155,7 +156,7 @@ func (r *Repository) CanUseTimetracker(issue *models.Issue, user *models.User) b } // CanCreateIssueDependencies returns whether or not a user can create dependencies. -func (r *Repository) CanCreateIssueDependencies(user *models.User, isPull bool) bool { +func (r *Repository) CanCreateIssueDependencies(user *user_model.User, isPull bool) bool { return r.Repository.IsDependenciesEnabled() && r.Permission.CanWriteIssuesOrPulls(isPull) } @@ -402,7 +403,7 @@ func RepoIDAssignment() func(ctx *Context) { // RepoAssignment returns a middleware to handle repository assignment func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { var ( - owner *models.User + owner *user_model.User err error ) @@ -414,9 +415,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { if ctx.IsSigned && ctx.User.LowerName == strings.ToLower(userName) { owner = ctx.User } else { - owner, err = models.GetUserByName(userName) + owner, err = user_model.GetUserByName(userName) if err != nil { - if models.IsErrUserNotExist(err) { + if user_model.IsErrUserNotExist(err) { if ctx.FormString("go-get") == "1" { EarlyResponseForGoGetMeta(ctx) return diff --git a/modules/convert/convert.go b/modules/convert/convert.go index 4229e6cc7d..f08a62588e 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -33,7 +33,7 @@ func ToEmail(email *user_model.EmailAddress) *api.Email { } // ToBranch convert a git.Commit and git.Branch to an api.Branch -func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *models.User, isRepoAdmin bool) (*api.Branch, error) { +func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) { if bp == nil { var hasPerm bool var err error @@ -83,15 +83,15 @@ func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit, bp *models. // ToBranchProtection convert a ProtectedBranch to api.BranchProtection func ToBranchProtection(bp *models.ProtectedBranch) *api.BranchProtection { - pushWhitelistUsernames, err := models.GetUserNamesByIDs(bp.WhitelistUserIDs) + pushWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.WhitelistUserIDs) if err != nil { log.Error("GetUserNamesByIDs (WhitelistUserIDs): %v", err) } - mergeWhitelistUsernames, err := models.GetUserNamesByIDs(bp.MergeWhitelistUserIDs) + mergeWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.MergeWhitelistUserIDs) if err != nil { log.Error("GetUserNamesByIDs (MergeWhitelistUserIDs): %v", err) } - approvalsWhitelistUsernames, err := models.GetUserNamesByIDs(bp.ApprovalsWhitelistUserIDs) + approvalsWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.ApprovalsWhitelistUserIDs) if err != nil { log.Error("GetUserNamesByIDs (ApprovalsWhitelistUserIDs): %v", err) } @@ -276,7 +276,7 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey { } } -// ToOrganization convert models.User to api.Organization +// ToOrganization convert user_model.User to api.Organization func ToOrganization(org *models.Organization) *api.Organization { return &api.Organization{ ID: org.ID, @@ -355,12 +355,16 @@ func ToOAuth2Application(app *login.OAuth2Application) *api.OAuth2Application { // ToLFSLock convert a LFSLock to api.LFSLock func ToLFSLock(l *models.LFSLock) *api.LFSLock { + u, err := user_model.GetUserByID(l.OwnerID) + if err != nil { + return nil + } return &api.LFSLock{ ID: strconv.FormatInt(l.ID, 10), Path: l.Path, LockedAt: l.Created.Round(time.Second), Owner: &api.LFSLockOwner{ - Name: l.Owner.DisplayName(), + Name: u.DisplayName(), }, } } diff --git a/modules/convert/git_commit.go b/modules/convert/git_commit.go index 9905b51fe4..3148d880ff 100644 --- a/modules/convert/git_commit.go +++ b/modules/convert/git_commit.go @@ -9,6 +9,7 @@ import ( "time" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" api "code.gitea.io/gitea/modules/structs" @@ -38,16 +39,16 @@ func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta { // ToPayloadCommit convert a git.Commit to api.PayloadCommit func ToPayloadCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit { authorUsername := "" - if author, err := models.GetUserByEmail(c.Author.Email); err == nil { + if author, err := user_model.GetUserByEmail(c.Author.Email); err == nil { authorUsername = author.Name - } else if !models.IsErrUserNotExist(err) { + } else if !user_model.IsErrUserNotExist(err) { log.Error("GetUserByEmail: %v", err) } committerUsername := "" - if committer, err := models.GetUserByEmail(c.Committer.Email); err == nil { + if committer, err := user_model.GetUserByEmail(c.Committer.Email); err == nil { committerUsername = committer.Name - } else if !models.IsErrUserNotExist(err) { + } else if !user_model.IsErrUserNotExist(err) { log.Error("GetUserByEmail: %v", err) } @@ -71,16 +72,16 @@ func ToPayloadCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit } // ToCommit convert a git.Commit to api.Commit -func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]*models.User) (*api.Commit, error) { +func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]*user_model.User) (*api.Commit, error) { var apiAuthor, apiCommitter *api.User // Retrieve author and committer information - var cacheAuthor *models.User + var cacheAuthor *user_model.User var ok bool if userCache == nil { - cacheAuthor = (*models.User)(nil) + cacheAuthor = (*user_model.User)(nil) ok = false } else { cacheAuthor, ok = userCache[commit.Author.Email] @@ -89,8 +90,8 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] if ok { apiAuthor = ToUser(cacheAuthor, nil) } else { - author, err := models.GetUserByEmail(commit.Author.Email) - if err != nil && !models.IsErrUserNotExist(err) { + author, err := user_model.GetUserByEmail(commit.Author.Email) + if err != nil && !user_model.IsErrUserNotExist(err) { return nil, err } else if err == nil { apiAuthor = ToUser(author, nil) @@ -100,9 +101,9 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] } } - var cacheCommitter *models.User + var cacheCommitter *user_model.User if userCache == nil { - cacheCommitter = (*models.User)(nil) + cacheCommitter = (*user_model.User)(nil) ok = false } else { cacheCommitter, ok = userCache[commit.Committer.Email] @@ -111,8 +112,8 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string] if ok { apiCommitter = ToUser(cacheCommitter, nil) } else { - committer, err := models.GetUserByEmail(commit.Committer.Email) - if err != nil && !models.IsErrUserNotExist(err) { + committer, err := user_model.GetUserByEmail(commit.Committer.Email) + if err != nil && !user_model.IsErrUserNotExist(err) { return nil, err } else if err == nil { apiCommitter = ToUser(committer, nil) diff --git a/modules/convert/issue.go b/modules/convert/issue.go index 7363cfb8fb..c67ff5427f 100644 --- a/modules/convert/issue.go +++ b/modules/convert/issue.go @@ -10,6 +10,7 @@ import ( "strings" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" @@ -175,7 +176,7 @@ func ToTrackedTimeList(tl models.TrackedTimeList) api.TrackedTimeList { } // ToLabel converts Label to API format -func ToLabel(label *models.Label, repo *models.Repository, org *models.User) *api.Label { +func ToLabel(label *models.Label, repo *models.Repository, org *user_model.User) *api.Label { result := &api.Label{ ID: label.ID, Name: label.Name, @@ -202,7 +203,7 @@ func ToLabel(label *models.Label, repo *models.Repository, org *models.User) *ap } // ToLabelList converts list of Label to API format -func ToLabelList(labels []*models.Label, repo *models.Repository, org *models.User) []*api.Label { +func ToLabelList(labels []*models.Label, repo *models.Repository, org *user_model.User) []*api.Label { result := make([]*api.Label, len(labels)) for i := range labels { result[i] = ToLabel(labels[i], repo, org) diff --git a/modules/convert/pull.go b/modules/convert/pull.go index 0f2b5af1b4..f892107f4b 100644 --- a/modules/convert/pull.go +++ b/modules/convert/pull.go @@ -8,6 +8,7 @@ import ( "fmt" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" api "code.gitea.io/gitea/modules/structs" @@ -16,7 +17,7 @@ import ( // ToAPIPullRequest assumes following fields have been assigned with valid values: // Required - Issue // Optional - Merger -func ToAPIPullRequest(pr *models.PullRequest, doer *models.User) *api.PullRequest { +func ToAPIPullRequest(pr *models.PullRequest, doer *user_model.User) *api.PullRequest { var ( baseBranch *git.Branch headBranch *git.Branch diff --git a/modules/convert/pull_review.go b/modules/convert/pull_review.go index b461b27b5a..b99d7bead6 100644 --- a/modules/convert/pull_review.go +++ b/modules/convert/pull_review.go @@ -8,16 +8,17 @@ import ( "strings" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" api "code.gitea.io/gitea/modules/structs" ) // ToPullReview convert a review to api format -func ToPullReview(r *models.Review, doer *models.User) (*api.PullReview, error) { +func ToPullReview(r *models.Review, doer *user_model.User) (*api.PullReview, error) { if err := r.LoadAttributes(); err != nil { - if !models.IsErrUserNotExist(err) { + if !user_model.IsErrUserNotExist(err) { return nil, err } - r.Reviewer = models.NewGhostUser() + r.Reviewer = user_model.NewGhostUser() } result := &api.PullReview{ @@ -53,7 +54,7 @@ func ToPullReview(r *models.Review, doer *models.User) (*api.PullReview, error) } // ToPullReviewList convert a list of review to it's api format -func ToPullReviewList(rl []*models.Review, doer *models.User) ([]*api.PullReview, error) { +func ToPullReviewList(rl []*models.Review, doer *user_model.User) ([]*api.PullReview, error) { result := make([]*api.PullReview, 0, len(rl)) for i := range rl { // show pending reviews only for the user who created them @@ -70,12 +71,12 @@ func ToPullReviewList(rl []*models.Review, doer *models.User) ([]*api.PullReview } // ToPullReviewCommentList convert the CodeComments of an review to it's api format -func ToPullReviewCommentList(review *models.Review, doer *models.User) ([]*api.PullReviewComment, error) { +func ToPullReviewCommentList(review *models.Review, doer *user_model.User) ([]*api.PullReviewComment, error) { if err := review.LoadAttributes(); err != nil { - if !models.IsErrUserNotExist(err) { + if !user_model.IsErrUserNotExist(err) { return nil, err } - review.Reviewer = models.NewGhostUser() + review.Reviewer = user_model.NewGhostUser() } apiComments := make([]*api.PullReviewComment, 0, len(review.CodeComments)) diff --git a/modules/convert/status.go b/modules/convert/status.go index bb2f964fe4..eb77c14dab 100644 --- a/modules/convert/status.go +++ b/modules/convert/status.go @@ -6,6 +6,7 @@ package convert import ( "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" api "code.gitea.io/gitea/modules/structs" ) @@ -23,7 +24,7 @@ func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus { } if status.CreatorID != 0 { - creator, _ := models.GetUserByID(status.CreatorID) + creator, _ := user_model.GetUserByID(status.CreatorID) apiStatus.Creator = ToUser(creator, nil) } diff --git a/modules/convert/user.go b/modules/convert/user.go index 3f17ae4b4d..ebe2f06460 100644 --- a/modules/convert/user.go +++ b/modules/convert/user.go @@ -6,12 +6,13 @@ package convert import ( "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" api "code.gitea.io/gitea/modules/structs" ) -// ToUser convert models.User to api.User +// ToUser convert user_model.User to api.User // if doer is set, private information is added if the doer has the permission to see it -func ToUser(user, doer *models.User) *api.User { +func ToUser(user, doer *user_model.User) *api.User { if user == nil { return nil } @@ -24,8 +25,8 @@ func ToUser(user, doer *models.User) *api.User { return toUser(user, signed, authed) } -// ToUsers convert list of models.User to list of api.User -func ToUsers(doer *models.User, users []*models.User) []*api.User { +// ToUsers convert list of user_model.User to list of api.User +func ToUsers(doer *user_model.User, users []*user_model.User) []*api.User { result := make([]*api.User, len(users)) for i := range users { result[i] = ToUser(users[i], doer) @@ -33,18 +34,18 @@ func ToUsers(doer *models.User, users []*models.User) []*api.User { return result } -// ToUserWithAccessMode convert models.User to api.User +// ToUserWithAccessMode convert user_model.User to api.User // AccessMode is not none show add some more information -func ToUserWithAccessMode(user *models.User, accessMode models.AccessMode) *api.User { +func ToUserWithAccessMode(user *user_model.User, accessMode models.AccessMode) *api.User { if user == nil { return nil } return toUser(user, accessMode != models.AccessModeNone, false) } -// toUser convert models.User to api.User +// toUser convert user_model.User to api.User // signed shall only be set if requester is logged in. authed shall only be set if user is site admin or user himself -func toUser(user *models.User, signed, authed bool) *api.User { +func toUser(user *user_model.User, signed, authed bool) *api.User { result := &api.User{ ID: user.ID, UserName: user.Name, @@ -81,7 +82,7 @@ func toUser(user *models.User, signed, authed bool) *api.User { } // User2UserSettings return UserSettings based on a user -func User2UserSettings(user *models.User) api.UserSettings { +func User2UserSettings(user *user_model.User) api.UserSettings { return api.UserSettings{ FullName: user.FullName, Website: user.Website, diff --git a/modules/convert/user_test.go b/modules/convert/user_test.go index ce174e3076..2ed962950f 100644 --- a/modules/convert/user_test.go +++ b/modules/convert/user_test.go @@ -7,8 +7,8 @@ package convert import ( "testing" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" api "code.gitea.io/gitea/modules/structs" "github.com/stretchr/testify/assert" @@ -17,13 +17,13 @@ import ( func TestUser_ToUser(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user1 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 1, IsAdmin: true}).(*models.User) + user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1, IsAdmin: true}).(*user_model.User) apiUser := toUser(user1, true, true) assert.True(t, apiUser.IsAdmin) assert.Contains(t, apiUser.AvatarURL, "://") - user2 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2, IsAdmin: false}).(*models.User) + user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2, IsAdmin: false}).(*user_model.User) apiUser = toUser(user2, true, true) assert.False(t, apiUser.IsAdmin) @@ -32,7 +32,7 @@ func TestUser_ToUser(t *testing.T) { assert.False(t, apiUser.IsAdmin) assert.EqualValues(t, api.VisibleTypePublic.String(), apiUser.Visibility) - user31 := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate}).(*models.User) + user31 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate}).(*user_model.User) apiUser = toUser(user31, true, true) assert.False(t, apiUser.IsAdmin) diff --git a/modules/doctor/misc.go b/modules/doctor/misc.go index 2f748bcb71..1cf8024b98 100644 --- a/modules/doctor/misc.go +++ b/modules/doctor/misc.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/repository" @@ -134,7 +135,7 @@ func checkDaemonExport(logger log.Logger, autofix bool) error { numRepos++ if owner, has := cache.Get(repo.OwnerID); has { - repo.Owner = owner.(*models.User) + repo.Owner = owner.(*user_model.User) } else { if err := repo.GetOwner(); err != nil { return err diff --git a/modules/gitgraph/graph_models.go b/modules/gitgraph/graph_models.go index 95f761742e..d7d198e01c 100644 --- a/modules/gitgraph/graph_models.go +++ b/modules/gitgraph/graph_models.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" ) @@ -91,7 +92,7 @@ func (graph *Graph) LoadAndProcessCommits(repository *models.Repository, gitRepo var ok bool - emails := map[string]*models.User{} + emails := map[string]*user_model.User{} keyMap := map[string]bool{} for _, c := range graph.Commits { @@ -106,7 +107,7 @@ func (graph *Graph) LoadAndProcessCommits(repository *models.Repository, gitRepo if c.Commit.Author != nil { email := c.Commit.Author.Email if c.User, ok = emails[email]; !ok { - c.User, _ = models.GetUserByEmail(email) + c.User, _ = user_model.GetUserByEmail(email) emails[email] = c.User } } @@ -233,7 +234,7 @@ func newRefsFromRefNames(refNames []byte) []git.Reference { // Commit represents a commit at co-ordinate X, Y with the data type Commit struct { Commit *git.Commit - User *models.User + User *user_model.User Verification *models.CommitVerification Status *models.CommitStatus Flow int64 diff --git a/modules/indexer/issues/indexer.go b/modules/indexer/issues/indexer.go index 4e133b4dd3..0b855460bd 100644 --- a/modules/indexer/issues/indexer.go +++ b/modules/indexer/issues/indexer.go @@ -243,7 +243,7 @@ func populateIssueIndexer(ctx context.Context) { } repos, _, err := models.SearchRepositoryByName(&models.SearchRepoOptions{ ListOptions: db.ListOptions{Page: page, PageSize: models.RepositoryListDefaultPageSize}, - OrderBy: models.SearchOrderByID, + OrderBy: db.SearchOrderByID, Private: true, Collaborate: util.OptionalBoolFalse, }) diff --git a/modules/notification/action/action.go b/modules/notification/action/action.go index 772e7be137..80f97ad993 100644 --- a/modules/notification/action/action.go +++ b/modules/notification/action/action.go @@ -10,6 +10,7 @@ import ( "strings" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification/base" @@ -29,7 +30,7 @@ func NewNotifier() base.Notifier { return &actionNotifier{} } -func (a *actionNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models.User) { +func (a *actionNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) { if err := issue.LoadPoster(); err != nil { log.Error("issue.LoadPoster: %v", err) return @@ -54,7 +55,7 @@ func (a *actionNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models. } // NotifyIssueChangeStatus notifies close or reopen issue to notifiers -func (a *actionNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) { +func (a *actionNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) { // Compose comment action, could be plain comment, close or reopen issue/pull request. // This object will be used to notify watchers in the end of function. act := &models.Action{ @@ -87,8 +88,8 @@ func (a *actionNotifier) NotifyIssueChangeStatus(doer *models.User, issue *model } // NotifyCreateIssueComment notifies comment on an issue to notifiers -func (a *actionNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository, - issue *models.Issue, comment *models.Comment, mentions []*models.User) { +func (a *actionNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, + issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { act := &models.Action{ ActUserID: doer.ID, ActUser: doer, @@ -120,7 +121,7 @@ func (a *actionNotifier) NotifyCreateIssueComment(doer *models.User, repo *model } } -func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest, mentions []*models.User) { +func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest, mentions []*user_model.User) { if err := pull.LoadIssue(); err != nil { log.Error("pull.LoadIssue: %v", err) return @@ -147,7 +148,7 @@ func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest, mentions } } -func (a *actionNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { +func (a *actionNotifier) NotifyRenameRepository(doer *user_model.User, repo *models.Repository, oldRepoName string) { log.Trace("action.ChangeRepositoryName: %s/%s", doer.Name, repo.Name) if err := models.NotifyWatchers(&models.Action{ @@ -163,7 +164,7 @@ func (a *actionNotifier) NotifyRenameRepository(doer *models.User, repo *models. } } -func (a *actionNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { +func (a *actionNotifier) NotifyTransferRepository(doer *user_model.User, repo *models.Repository, oldOwnerName string) { if err := models.NotifyWatchers(&models.Action{ ActUserID: doer.ID, ActUser: doer, @@ -177,7 +178,7 @@ func (a *actionNotifier) NotifyTransferRepository(doer *models.User, repo *model } } -func (a *actionNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) { +func (a *actionNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { if err := models.NotifyWatchers(&models.Action{ ActUserID: doer.ID, ActUser: doer, @@ -190,7 +191,7 @@ func (a *actionNotifier) NotifyCreateRepository(doer *models.User, u *models.Use } } -func (a *actionNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) { +func (a *actionNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) { if err := models.NotifyWatchers(&models.Action{ ActUserID: doer.ID, ActUser: doer, @@ -203,7 +204,7 @@ func (a *actionNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo * } } -func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*models.User) { +func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*user_model.User) { if err := review.LoadReviewer(); err != nil { log.Error("LoadReviewer '%d/%d': %v", review.ID, review.ReviewerID, err) return @@ -261,7 +262,7 @@ func (a *actionNotifier) NotifyPullRequestReview(pr *models.PullRequest, review } } -func (*actionNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) { +func (*actionNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *user_model.User) { if err := models.NotifyWatchers(&models.Action{ ActUserID: doer.ID, ActUser: doer, @@ -275,7 +276,7 @@ func (*actionNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mode } } -func (*actionNotifier) NotifyPullRevieweDismiss(doer *models.User, review *models.Review, comment *models.Comment) { +func (*actionNotifier) NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment) { reviewerName := review.Reviewer.Name if len(review.OriginalAuthor) > 0 { reviewerName = review.OriginalAuthor @@ -295,7 +296,7 @@ func (*actionNotifier) NotifyPullRevieweDismiss(doer *models.User, review *model } } -func (a *actionNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (a *actionNotifier) NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { data, err := json.Marshal(commits) if err != nil { log.Error("Marshal: %v", err) @@ -328,7 +329,7 @@ func (a *actionNotifier) NotifyPushCommits(pusher *models.User, repo *models.Rep } } -func (a *actionNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) { +func (a *actionNotifier) NotifyCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { opType := models.ActionCommitRepo if refType == "tag" { // has sent same action in `NotifyPushCommits`, so skip it. @@ -347,7 +348,7 @@ func (a *actionNotifier) NotifyCreateRef(doer *models.User, repo *models.Reposit } } -func (a *actionNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) { +func (a *actionNotifier) NotifyDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { opType := models.ActionDeleteBranch if refType == "tag" { // has sent same action in `NotifyPushCommits`, so skip it. @@ -366,7 +367,7 @@ func (a *actionNotifier) NotifyDeleteRef(doer *models.User, repo *models.Reposit } } -func (a *actionNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (a *actionNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { data, err := json.Marshal(commits) if err != nil { log.Error("json.Marshal: %v", err) @@ -387,7 +388,7 @@ func (a *actionNotifier) NotifySyncPushCommits(pusher *models.User, repo *models } } -func (a *actionNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) { +func (a *actionNotifier) NotifySyncCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { if err := models.NotifyWatchers(&models.Action{ ActUserID: repo.OwnerID, ActUser: repo.MustOwner(), @@ -401,7 +402,7 @@ func (a *actionNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Rep } } -func (a *actionNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) { +func (a *actionNotifier) NotifySyncDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { if err := models.NotifyWatchers(&models.Action{ ActUserID: repo.OwnerID, ActUser: repo.MustOwner(), diff --git a/modules/notification/action/action_test.go b/modules/notification/action/action_test.go index 448242bcdf..2218bd46cb 100644 --- a/modules/notification/action/action_test.go +++ b/modules/notification/action/action_test.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "github.com/stretchr/testify/assert" ) @@ -22,7 +23,7 @@ func TestMain(m *testing.M) { func TestRenameRepoAction(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}).(*user_model.User) repo := unittest.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID}).(*models.Repository) repo.Owner = user diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go index 8f8aa659b4..24f6375a69 100644 --- a/modules/notification/base/notifier.go +++ b/modules/notification/base/notifier.go @@ -6,6 +6,7 @@ package base import ( "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/repository" ) @@ -13,50 +14,50 @@ import ( type Notifier interface { Run() - NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) - NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) - NotifyDeleteRepository(doer *models.User, repo *models.Repository) - NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) - NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) - NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) - - NotifyNewIssue(issue *models.Issue, mentions []*models.User) - NotifyIssueChangeStatus(*models.User, *models.Issue, *models.Comment, bool) - NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) - NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) - NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) - NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) - NotifyIssueClearLabels(doer *models.User, issue *models.Issue) - NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) - NotifyIssueChangeRef(doer *models.User, issue *models.Issue, oldRef string) - NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, + NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) + NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) + NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) + NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) + NotifyRenameRepository(doer *user_model.User, repo *models.Repository, oldRepoName string) + NotifyTransferRepository(doer *user_model.User, repo *models.Repository, oldOwnerName string) + + NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) + NotifyIssueChangeStatus(*user_model.User, *models.Issue, *models.Comment, bool) + NotifyIssueChangeMilestone(doer *user_model.User, issue *models.Issue, oldMilestoneID int64) + NotifyIssueChangeAssignee(doer *user_model.User, issue *models.Issue, assignee *user_model.User, removed bool, comment *models.Comment) + NotifyPullReviewRequest(doer *user_model.User, issue *models.Issue, reviewer *user_model.User, isRequest bool, comment *models.Comment) + NotifyIssueChangeContent(doer *user_model.User, issue *models.Issue, oldContent string) + NotifyIssueClearLabels(doer *user_model.User, issue *models.Issue) + NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) + NotifyIssueChangeRef(doer *user_model.User, issue *models.Issue, oldRef string) + NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue, addedLabels []*models.Label, removedLabels []*models.Label) - NotifyNewPullRequest(pr *models.PullRequest, mentions []*models.User) - NotifyMergePullRequest(*models.PullRequest, *models.User) - NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) - NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*models.User) - NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*models.User) - NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) - NotifyPullRequestPushCommits(doer *models.User, pr *models.PullRequest, comment *models.Comment) - NotifyPullRevieweDismiss(doer *models.User, review *models.Review, comment *models.Comment) + NotifyNewPullRequest(pr *models.PullRequest, mentions []*user_model.User) + NotifyMergePullRequest(*models.PullRequest, *user_model.User) + NotifyPullRequestSynchronized(doer *user_model.User, pr *models.PullRequest) + NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*user_model.User) + NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*user_model.User) + NotifyPullRequestChangeTargetBranch(doer *user_model.User, pr *models.PullRequest, oldBranch string) + NotifyPullRequestPushCommits(doer *user_model.User, pr *models.PullRequest, comment *models.Comment) + NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment) - NotifyCreateIssueComment(doer *models.User, repo *models.Repository, - issue *models.Issue, comment *models.Comment, mentions []*models.User) - NotifyUpdateComment(*models.User, *models.Comment, string) - NotifyDeleteComment(*models.User, *models.Comment) + NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, + issue *models.Issue, comment *models.Comment, mentions []*user_model.User) + NotifyUpdateComment(*user_model.User, *models.Comment, string) + NotifyDeleteComment(*user_model.User, *models.Comment) NotifyNewRelease(rel *models.Release) - NotifyUpdateRelease(doer *models.User, rel *models.Release) - NotifyDeleteRelease(doer *models.User, rel *models.Release) + NotifyUpdateRelease(doer *user_model.User, rel *models.Release) + NotifyDeleteRelease(doer *user_model.User, rel *models.Release) - NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) - NotifyCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) - NotifyDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) + NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) + NotifyCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) + NotifyDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) - NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) - NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) - NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) + NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) + NotifySyncCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) + NotifySyncDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) - NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) + NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) } diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go index 32fe259bca..8a977e122b 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -6,6 +6,7 @@ package base import ( "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/repository" ) @@ -22,56 +23,56 @@ func (*NullNotifier) Run() { } // NotifyCreateIssueComment places a place holder function -func (*NullNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository, - issue *models.Issue, comment *models.Comment, mentions []*models.User) { +func (*NullNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, + issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { } // NotifyNewIssue places a place holder function -func (*NullNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models.User) { +func (*NullNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) { } // NotifyIssueChangeStatus places a place holder function -func (*NullNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) { +func (*NullNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) { } // NotifyNewPullRequest places a place holder function -func (*NullNotifier) NotifyNewPullRequest(pr *models.PullRequest, mentions []*models.User) { +func (*NullNotifier) NotifyNewPullRequest(pr *models.PullRequest, mentions []*user_model.User) { } // NotifyPullRequestReview places a place holder function -func (*NullNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment, mentions []*models.User) { +func (*NullNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment, mentions []*user_model.User) { } // NotifyPullRequestCodeComment places a place holder function -func (*NullNotifier) NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*models.User) { +func (*NullNotifier) NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*user_model.User) { } // NotifyMergePullRequest places a place holder function -func (*NullNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) { +func (*NullNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *user_model.User) { } // NotifyPullRequestSynchronized places a place holder function -func (*NullNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) { +func (*NullNotifier) NotifyPullRequestSynchronized(doer *user_model.User, pr *models.PullRequest) { } // NotifyPullRequestChangeTargetBranch places a place holder function -func (*NullNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) { +func (*NullNotifier) NotifyPullRequestChangeTargetBranch(doer *user_model.User, pr *models.PullRequest, oldBranch string) { } // NotifyPullRequestPushCommits notifies when push commits to pull request's head branch -func (*NullNotifier) NotifyPullRequestPushCommits(doer *models.User, pr *models.PullRequest, comment *models.Comment) { +func (*NullNotifier) NotifyPullRequestPushCommits(doer *user_model.User, pr *models.PullRequest, comment *models.Comment) { } // NotifyPullRevieweDismiss notifies when a review was dismissed by repo admin -func (*NullNotifier) NotifyPullRevieweDismiss(doer *models.User, review *models.Review, comment *models.Comment) { +func (*NullNotifier) NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment) { } // NotifyUpdateComment places a place holder function -func (*NullNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) { +func (*NullNotifier) NotifyUpdateComment(doer *user_model.User, c *models.Comment, oldContent string) { } // NotifyDeleteComment places a place holder function -func (*NullNotifier) NotifyDeleteComment(doer *models.User, c *models.Comment) { +func (*NullNotifier) NotifyDeleteComment(doer *user_model.User, c *models.Comment) { } // NotifyNewRelease places a place holder function @@ -79,94 +80,94 @@ func (*NullNotifier) NotifyNewRelease(rel *models.Release) { } // NotifyUpdateRelease places a place holder function -func (*NullNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) { +func (*NullNotifier) NotifyUpdateRelease(doer *user_model.User, rel *models.Release) { } // NotifyDeleteRelease places a place holder function -func (*NullNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) { +func (*NullNotifier) NotifyDeleteRelease(doer *user_model.User, rel *models.Release) { } // NotifyIssueChangeMilestone places a place holder function -func (*NullNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) { +func (*NullNotifier) NotifyIssueChangeMilestone(doer *user_model.User, issue *models.Issue, oldMilestoneID int64) { } // NotifyIssueChangeContent places a place holder function -func (*NullNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { +func (*NullNotifier) NotifyIssueChangeContent(doer *user_model.User, issue *models.Issue, oldContent string) { } // NotifyIssueChangeAssignee places a place holder function -func (*NullNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { +func (*NullNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue *models.Issue, assignee *user_model.User, removed bool, comment *models.Comment) { } // NotifyPullReviewRequest places a place holder function -func (*NullNotifier) NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) { +func (*NullNotifier) NotifyPullReviewRequest(doer *user_model.User, issue *models.Issue, reviewer *user_model.User, isRequest bool, comment *models.Comment) { } // NotifyIssueClearLabels places a place holder function -func (*NullNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) { +func (*NullNotifier) NotifyIssueClearLabels(doer *user_model.User, issue *models.Issue) { } // NotifyIssueChangeTitle places a place holder function -func (*NullNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) { +func (*NullNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) { } // NotifyIssueChangeRef places a place holder function -func (*NullNotifier) NotifyIssueChangeRef(doer *models.User, issue *models.Issue, oldTitle string) { +func (*NullNotifier) NotifyIssueChangeRef(doer *user_model.User, issue *models.Issue, oldTitle string) { } // NotifyIssueChangeLabels places a place holder function -func (*NullNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, +func (*NullNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue, addedLabels []*models.Label, removedLabels []*models.Label) { } // NotifyCreateRepository places a place holder function -func (*NullNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) { +func (*NullNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { } // NotifyDeleteRepository places a place holder function -func (*NullNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) { +func (*NullNotifier) NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) { } // NotifyForkRepository places a place holder function -func (*NullNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) { +func (*NullNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) { } // NotifyMigrateRepository places a place holder function -func (*NullNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) { +func (*NullNotifier) NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { } // NotifyPushCommits notifies commits pushed to notifiers -func (*NullNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (*NullNotifier) NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { } // NotifyCreateRef notifies branch or tag creation to notifiers -func (*NullNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) { +func (*NullNotifier) NotifyCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { } // NotifyDeleteRef notifies branch or tag deletion to notifiers -func (*NullNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) { +func (*NullNotifier) NotifyDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { } // NotifyRenameRepository places a place holder function -func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { +func (*NullNotifier) NotifyRenameRepository(doer *user_model.User, repo *models.Repository, oldRepoName string) { } // NotifyTransferRepository places a place holder function -func (*NullNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { +func (*NullNotifier) NotifyTransferRepository(doer *user_model.User, repo *models.Repository, oldOwnerName string) { } // NotifySyncPushCommits places a place holder function -func (*NullNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (*NullNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { } // NotifySyncCreateRef places a place holder function -func (*NullNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) { +func (*NullNotifier) NotifySyncCreateRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { } // NotifySyncDeleteRef places a place holder function -func (*NullNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) { +func (*NullNotifier) NotifySyncDeleteRef(doer *user_model.User, repo *models.Repository, refType, refFullName string) { } // NotifyRepoPendingTransfer places a place holder function -func (*NullNotifier) NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) { +func (*NullNotifier) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) { } diff --git a/modules/notification/indexer/indexer.go b/modules/notification/indexer/indexer.go index 109eb1f62d..03914db03b 100644 --- a/modules/notification/indexer/indexer.go +++ b/modules/notification/indexer/indexer.go @@ -6,6 +6,7 @@ package indexer import ( "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" code_indexer "code.gitea.io/gitea/modules/indexer/code" issue_indexer "code.gitea.io/gitea/modules/indexer/issues" @@ -29,8 +30,8 @@ func NewNotifier() base.Notifier { return &indexerNotifier{} } -func (r *indexerNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository, - issue *models.Issue, comment *models.Comment, mentions []*models.User) { +func (r *indexerNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, + issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { if comment.Type == models.CommentTypeComment { if issue.Comments == nil { if err := issue.LoadDiscussComments(); err != nil { @@ -45,15 +46,15 @@ func (r *indexerNotifier) NotifyCreateIssueComment(doer *models.User, repo *mode } } -func (r *indexerNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models.User) { +func (r *indexerNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) { issue_indexer.UpdateIssueIndexer(issue) } -func (r *indexerNotifier) NotifyNewPullRequest(pr *models.PullRequest, mentions []*models.User) { +func (r *indexerNotifier) NotifyNewPullRequest(pr *models.PullRequest, mentions []*user_model.User) { issue_indexer.UpdateIssueIndexer(pr.Issue) } -func (r *indexerNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) { +func (r *indexerNotifier) NotifyUpdateComment(doer *user_model.User, c *models.Comment, oldContent string) { if c.Type == models.CommentTypeComment { var found bool if c.Issue.Comments != nil { @@ -77,7 +78,7 @@ func (r *indexerNotifier) NotifyUpdateComment(doer *models.User, c *models.Comme } } -func (r *indexerNotifier) NotifyDeleteComment(doer *models.User, comment *models.Comment) { +func (r *indexerNotifier) NotifyDeleteComment(doer *user_model.User, comment *models.Comment) { if comment.Type == models.CommentTypeComment { if err := comment.LoadIssue(); err != nil { log.Error("LoadIssue: %v", err) @@ -106,14 +107,14 @@ func (r *indexerNotifier) NotifyDeleteComment(doer *models.User, comment *models } } -func (r *indexerNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) { +func (r *indexerNotifier) NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) { issue_indexer.DeleteRepoIssueIndexer(repo) if setting.Indexer.RepoIndexerEnabled { code_indexer.UpdateRepoIndexer(repo) } } -func (r *indexerNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) { +func (r *indexerNotifier) NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { issue_indexer.UpdateRepoIndexer(repo) if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty { code_indexer.UpdateRepoIndexer(repo) @@ -123,7 +124,7 @@ func (r *indexerNotifier) NotifyMigrateRepository(doer *models.User, u *models.U } } -func (r *indexerNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (r *indexerNotifier) NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { if setting.Indexer.RepoIndexerEnabled && opts.RefFullName == git.BranchPrefix+repo.DefaultBranch { code_indexer.UpdateRepoIndexer(repo) } @@ -132,7 +133,7 @@ func (r *indexerNotifier) NotifyPushCommits(pusher *models.User, repo *models.Re } } -func (r *indexerNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (r *indexerNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { if setting.Indexer.RepoIndexerEnabled && opts.RefFullName == git.BranchPrefix+repo.DefaultBranch { code_indexer.UpdateRepoIndexer(repo) } @@ -141,14 +142,14 @@ func (r *indexerNotifier) NotifySyncPushCommits(pusher *models.User, repo *model } } -func (r *indexerNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { +func (r *indexerNotifier) NotifyIssueChangeContent(doer *user_model.User, issue *models.Issue, oldContent string) { issue_indexer.UpdateIssueIndexer(issue) } -func (r *indexerNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) { +func (r *indexerNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) { issue_indexer.UpdateIssueIndexer(issue) } -func (r *indexerNotifier) NotifyIssueChangeRef(doer *models.User, issue *models.Issue, oldRef string) { +func (r *indexerNotifier) NotifyIssueChangeRef(doer *user_model.User, issue *models.Issue, oldRef string) { issue_indexer.UpdateIssueIndexer(issue) } diff --git a/modules/notification/mail/mail.go b/modules/notification/mail/mail.go index 5bfb0b3ef8..c1c9e96135 100644 --- a/modules/notification/mail/mail.go +++ b/modules/notification/mail/mail.go @@ -8,6 +8,7 @@ import ( "fmt" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/services/mailer" @@ -26,8 +27,8 @@ func NewNotifier() base.Notifier { return &mailNotifier{} } -func (m *mailNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository, - issue *models.Issue, comment *models.Comment, mentions []*models.User) { +func (m *mailNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, + issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { var act models.ActionType if comment.Type == models.CommentTypeClose { act = models.ActionCloseIssue @@ -46,13 +47,13 @@ func (m *mailNotifier) NotifyCreateIssueComment(doer *models.User, repo *models. } } -func (m *mailNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models.User) { +func (m *mailNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) { if err := mailer.MailParticipants(issue, issue.Poster, models.ActionCreateIssue, mentions); err != nil { log.Error("MailParticipants: %v", err) } } -func (m *mailNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) { +func (m *mailNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) { var actionType models.ActionType if issue.IsPull { if isClosed { @@ -73,7 +74,7 @@ func (m *mailNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models. } } -func (m *mailNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) { +func (m *mailNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) { if err := issue.LoadPullRequest(); err != nil { log.Error("issue.LoadPullRequest: %v", err) return @@ -85,13 +86,13 @@ func (m *mailNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.I } } -func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest, mentions []*models.User) { +func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest, mentions []*user_model.User) { if err := mailer.MailParticipants(pr.Issue, pr.Issue.Poster, models.ActionCreatePullRequest, mentions); err != nil { log.Error("MailParticipants: %v", err) } } -func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment, mentions []*models.User) { +func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment, mentions []*user_model.User) { var act models.ActionType if comment.Type == models.CommentTypeClose { act = models.ActionCloseIssue @@ -105,32 +106,32 @@ func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models } } -func (m *mailNotifier) NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*models.User) { +func (m *mailNotifier) NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*user_model.User) { if err := mailer.MailMentionsComment(pr, comment, mentions); err != nil { log.Error("MailMentionsComment: %v", err) } } -func (m *mailNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { +func (m *mailNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue *models.Issue, assignee *user_model.User, removed bool, comment *models.Comment) { // mail only sent to added assignees and not self-assignee - if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() == models.EmailNotificationsEnabled { + if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() == user_model.EmailNotificationsEnabled { ct := fmt.Sprintf("Assigned #%d.", issue.Index) - if err := mailer.SendIssueAssignedMail(issue, doer, ct, comment, []*models.User{assignee}); err != nil { + if err := mailer.SendIssueAssignedMail(issue, doer, ct, comment, []*user_model.User{assignee}); err != nil { log.Error("Error in SendIssueAssignedMail for issue[%d] to assignee[%d]: %v", issue.ID, assignee.ID, err) } } } -func (m *mailNotifier) NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) { - if isRequest && doer.ID != reviewer.ID && reviewer.EmailNotifications() == models.EmailNotificationsEnabled { +func (m *mailNotifier) NotifyPullReviewRequest(doer *user_model.User, issue *models.Issue, reviewer *user_model.User, isRequest bool, comment *models.Comment) { + if isRequest && doer.ID != reviewer.ID && reviewer.EmailNotifications() == user_model.EmailNotificationsEnabled { ct := fmt.Sprintf("Requested to review %s.", issue.HTMLURL()) - if err := mailer.SendIssueAssignedMail(issue, doer, ct, comment, []*models.User{reviewer}); err != nil { + if err := mailer.SendIssueAssignedMail(issue, doer, ct, comment, []*user_model.User{reviewer}); err != nil { log.Error("Error in SendIssueAssignedMail for issue[%d] to reviewer[%d]: %v", issue.ID, reviewer.ID, err) } } } -func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) { +func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *user_model.User) { if err := pr.LoadIssue(); err != nil { log.Error("pr.LoadIssue: %v", err) return @@ -140,7 +141,7 @@ func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mode } } -func (m *mailNotifier) NotifyPullRequestPushCommits(doer *models.User, pr *models.PullRequest, comment *models.Comment) { +func (m *mailNotifier) NotifyPullRequestPushCommits(doer *user_model.User, pr *models.PullRequest, comment *models.Comment) { var err error if err = comment.LoadIssue(); err != nil { log.Error("comment.LoadIssue: %v", err) @@ -164,7 +165,7 @@ func (m *mailNotifier) NotifyPullRequestPushCommits(doer *models.User, pr *model m.NotifyCreateIssueComment(doer, comment.Issue.Repo, comment.Issue, comment, nil) } -func (m *mailNotifier) NotifyPullRevieweDismiss(doer *models.User, review *models.Review, comment *models.Comment) { +func (m *mailNotifier) NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment) { if err := mailer.MailParticipantsComment(comment, models.ActionPullReviewDismissed, review.Issue, nil); err != nil { log.Error("MailParticipantsComment: %v", err) } @@ -183,7 +184,7 @@ func (m *mailNotifier) NotifyNewRelease(rel *models.Release) { mailer.MailNewRelease(rel) } -func (m *mailNotifier) NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) { +func (m *mailNotifier) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) { if err := mailer.SendRepoTransferNotifyMail(doer, newOwner, repo); err != nil { log.Error("NotifyRepoPendingTransfer: %v", err) } diff --git a/modules/notification/notification.go b/modules/notification/notification.go index b574f3ccda..9bea38faf6 100644 --- a/modules/notification/notification.go +++ b/modules/notification/notification.go @@ -6,6 +6,7 @@ package notification import ( "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/notification/action" "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/notification/indexer" @@ -38,92 +39,92 @@ func NewContext() { } // NotifyCreateIssueComment notifies issue comment related message to notifiers -func NotifyCreateIssueComment(doer *models.User, repo *models.Repository, - issue *models.Issue, comment *models.Comment, mentions []*models.User) { +func NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, + issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { for _, notifier := range notifiers { notifier.NotifyCreateIssueComment(doer, repo, issue, comment, mentions) } } // NotifyNewIssue notifies new issue to notifiers -func NotifyNewIssue(issue *models.Issue, mentions []*models.User) { +func NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) { for _, notifier := range notifiers { notifier.NotifyNewIssue(issue, mentions) } } // NotifyIssueChangeStatus notifies close or reopen issue to notifiers -func NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) { +func NotifyIssueChangeStatus(doer *user_model.User, issue *models.Issue, actionComment *models.Comment, closeOrReopen bool) { for _, notifier := range notifiers { notifier.NotifyIssueChangeStatus(doer, issue, actionComment, closeOrReopen) } } // NotifyMergePullRequest notifies merge pull request to notifiers -func NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) { +func NotifyMergePullRequest(pr *models.PullRequest, doer *user_model.User) { for _, notifier := range notifiers { notifier.NotifyMergePullRequest(pr, doer) } } // NotifyNewPullRequest notifies new pull request to notifiers -func NotifyNewPullRequest(pr *models.PullRequest, mentions []*models.User) { +func NotifyNewPullRequest(pr *models.PullRequest, mentions []*user_model.User) { for _, notifier := range notifiers { notifier.NotifyNewPullRequest(pr, mentions) } } // NotifyPullRequestSynchronized notifies Synchronized pull request -func NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) { +func NotifyPullRequestSynchronized(doer *user_model.User, pr *models.PullRequest) { for _, notifier := range notifiers { notifier.NotifyPullRequestSynchronized(doer, pr) } } // NotifyPullRequestReview notifies new pull request review -func NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*models.User) { +func NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*user_model.User) { for _, notifier := range notifiers { notifier.NotifyPullRequestReview(pr, review, comment, mentions) } } // NotifyPullRequestCodeComment notifies new pull request code comment -func NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*models.User) { +func NotifyPullRequestCodeComment(pr *models.PullRequest, comment *models.Comment, mentions []*user_model.User) { for _, notifier := range notifiers { notifier.NotifyPullRequestCodeComment(pr, comment, mentions) } } // NotifyPullRequestChangeTargetBranch notifies when a pull request's target branch was changed -func NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) { +func NotifyPullRequestChangeTargetBranch(doer *user_model.User, pr *models.PullRequest, oldBranch string) { for _, notifier := range notifiers { notifier.NotifyPullRequestChangeTargetBranch(doer, pr, oldBranch) } } // NotifyPullRequestPushCommits notifies when push commits to pull request's head branch -func NotifyPullRequestPushCommits(doer *models.User, pr *models.PullRequest, comment *models.Comment) { +func NotifyPullRequestPushCommits(doer *user_model.User, pr *models.PullRequest, comment *models.Comment) { for _, notifier := range notifiers { notifier.NotifyPullRequestPushCommits(doer, pr, comment) } } // NotifyPullRevieweDismiss notifies when a review was dismissed by repo admin -func NotifyPullRevieweDismiss(doer *models.User, review *models.Review, comment *models.Comment) { +func NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment) { for _, notifier := range notifiers { notifier.NotifyPullRevieweDismiss(doer, review, comment) } } // NotifyUpdateComment notifies update comment to notifiers -func NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) { +func NotifyUpdateComment(doer *user_model.User, c *models.Comment, oldContent string) { for _, notifier := range notifiers { notifier.NotifyUpdateComment(doer, c, oldContent) } } // NotifyDeleteComment notifies delete comment to notifiers -func NotifyDeleteComment(doer *models.User, c *models.Comment) { +func NotifyDeleteComment(doer *user_model.User, c *models.Comment) { for _, notifier := range notifiers { notifier.NotifyDeleteComment(doer, c) } @@ -137,70 +138,70 @@ func NotifyNewRelease(rel *models.Release) { } // NotifyUpdateRelease notifies update release to notifiers -func NotifyUpdateRelease(doer *models.User, rel *models.Release) { +func NotifyUpdateRelease(doer *user_model.User, rel *models.Release) { for _, notifier := range notifiers { notifier.NotifyUpdateRelease(doer, rel) } } // NotifyDeleteRelease notifies delete release to notifiers -func NotifyDeleteRelease(doer *models.User, rel *models.Release) { +func NotifyDeleteRelease(doer *user_model.User, rel *models.Release) { for _, notifier := range notifiers { notifier.NotifyDeleteRelease(doer, rel) } } // NotifyIssueChangeMilestone notifies change milestone to notifiers -func NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) { +func NotifyIssueChangeMilestone(doer *user_model.User, issue *models.Issue, oldMilestoneID int64) { for _, notifier := range notifiers { notifier.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID) } } // NotifyIssueChangeContent notifies change content to notifiers -func NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { +func NotifyIssueChangeContent(doer *user_model.User, issue *models.Issue, oldContent string) { for _, notifier := range notifiers { notifier.NotifyIssueChangeContent(doer, issue, oldContent) } } // NotifyIssueChangeAssignee notifies change content to notifiers -func NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { +func NotifyIssueChangeAssignee(doer *user_model.User, issue *models.Issue, assignee *user_model.User, removed bool, comment *models.Comment) { for _, notifier := range notifiers { notifier.NotifyIssueChangeAssignee(doer, issue, assignee, removed, comment) } } // NotifyPullReviewRequest notifies Request Review change -func NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) { +func NotifyPullReviewRequest(doer *user_model.User, issue *models.Issue, reviewer *user_model.User, isRequest bool, comment *models.Comment) { for _, notifier := range notifiers { notifier.NotifyPullReviewRequest(doer, issue, reviewer, isRequest, comment) } } // NotifyIssueClearLabels notifies clear labels to notifiers -func NotifyIssueClearLabels(doer *models.User, issue *models.Issue) { +func NotifyIssueClearLabels(doer *user_model.User, issue *models.Issue) { for _, notifier := range notifiers { notifier.NotifyIssueClearLabels(doer, issue) } } // NotifyIssueChangeTitle notifies change title to notifiers -func NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) { +func NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) { for _, notifier := range notifiers { notifier.NotifyIssueChangeTitle(doer, issue, oldTitle) } } // NotifyIssueChangeRef notifies change reference to notifiers -func NotifyIssueChangeRef(doer *models.User, issue *models.Issue, oldRef string) { +func NotifyIssueChangeRef(doer *user_model.User, issue *models.Issue, oldRef string) { for _, notifier := range notifiers { notifier.NotifyIssueChangeRef(doer, issue, oldRef) } } // NotifyIssueChangeLabels notifies change labels to notifiers -func NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, +func NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue, addedLabels []*models.Label, removedLabels []*models.Label) { for _, notifier := range notifiers { notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels) @@ -208,91 +209,91 @@ func NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, } // NotifyCreateRepository notifies create repository to notifiers -func NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) { +func NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { for _, notifier := range notifiers { notifier.NotifyCreateRepository(doer, u, repo) } } // NotifyMigrateRepository notifies create repository to notifiers -func NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) { +func NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { for _, notifier := range notifiers { notifier.NotifyMigrateRepository(doer, u, repo) } } // NotifyTransferRepository notifies create repository to notifiers -func NotifyTransferRepository(doer *models.User, repo *models.Repository, newOwnerName string) { +func NotifyTransferRepository(doer *user_model.User, repo *models.Repository, newOwnerName string) { for _, notifier := range notifiers { notifier.NotifyTransferRepository(doer, repo, newOwnerName) } } // NotifyDeleteRepository notifies delete repository to notifiers -func NotifyDeleteRepository(doer *models.User, repo *models.Repository) { +func NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) { for _, notifier := range notifiers { notifier.NotifyDeleteRepository(doer, repo) } } // NotifyForkRepository notifies fork repository to notifiers -func NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) { +func NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) { for _, notifier := range notifiers { notifier.NotifyForkRepository(doer, oldRepo, repo) } } // NotifyRenameRepository notifies repository renamed -func NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) { +func NotifyRenameRepository(doer *user_model.User, repo *models.Repository, oldName string) { for _, notifier := range notifiers { notifier.NotifyRenameRepository(doer, repo, oldName) } } // NotifyPushCommits notifies commits pushed to notifiers -func NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { for _, notifier := range notifiers { notifier.NotifyPushCommits(pusher, repo, opts, commits) } } // NotifyCreateRef notifies branch or tag creation to notifiers -func NotifyCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) { +func NotifyCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { for _, notifier := range notifiers { notifier.NotifyCreateRef(pusher, repo, refType, refFullName) } } // NotifyDeleteRef notifies branch or tag deletion to notifiers -func NotifyDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) { +func NotifyDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { for _, notifier := range notifiers { notifier.NotifyDeleteRef(pusher, repo, refType, refFullName) } } // NotifySyncPushCommits notifies commits pushed to notifiers -func NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { for _, notifier := range notifiers { notifier.NotifySyncPushCommits(pusher, repo, opts, commits) } } // NotifySyncCreateRef notifies branch or tag creation to notifiers -func NotifySyncCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) { +func NotifySyncCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { for _, notifier := range notifiers { notifier.NotifySyncCreateRef(pusher, repo, refType, refFullName) } } // NotifySyncDeleteRef notifies branch or tag deletion to notifiers -func NotifySyncDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) { +func NotifySyncDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { for _, notifier := range notifiers { notifier.NotifySyncDeleteRef(pusher, repo, refType, refFullName) } } // NotifyRepoPendingTransfer notifies creation of pending transfer to notifiers -func NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) { +func NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) { for _, notifier := range notifiers { notifier.NotifyRepoPendingTransfer(doer, newOwner, repo) } diff --git a/modules/notification/ui/ui.go b/modules/notification/ui/ui.go index f372d6759c..04967fc589 100644 --- a/modules/notification/ui/ui.go +++ b/modules/notification/ui/ui.go @@ -6,6 +6,7 @@ package ui import ( "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/notification/base" @@ -50,8 +51,8 @@ func (ns *notificationService) Run() { graceful.GetManager().RunWithShutdownFns(ns.issueQueue.Run) } -func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo *models.Repository, - issue *models.Issue, comment *models.Comment, mentions []*models.User) { +func (ns *notificationService) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, + issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { var opts = issueNotificationOpts{ IssueID: issue.ID, NotificationAuthorID: doer.ID, @@ -73,7 +74,7 @@ func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo } } -func (ns *notificationService) NotifyNewIssue(issue *models.Issue, mentions []*models.User) { +func (ns *notificationService) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) { _ = ns.issueQueue.Push(issueNotificationOpts{ IssueID: issue.ID, NotificationAuthorID: issue.Poster.ID, @@ -87,14 +88,14 @@ func (ns *notificationService) NotifyNewIssue(issue *models.Issue, mentions []*m } } -func (ns *notificationService) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) { +func (ns *notificationService) NotifyIssueChangeStatus(doer *user_model.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) { _ = ns.issueQueue.Push(issueNotificationOpts{ IssueID: issue.ID, NotificationAuthorID: doer.ID, }) } -func (ns *notificationService) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) { +func (ns *notificationService) NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) { if err := issue.LoadPullRequest(); err != nil { log.Error("issue.LoadPullRequest: %v", err) return @@ -107,14 +108,14 @@ func (ns *notificationService) NotifyIssueChangeTitle(doer *models.User, issue * } } -func (ns *notificationService) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) { +func (ns *notificationService) NotifyMergePullRequest(pr *models.PullRequest, doer *user_model.User) { _ = ns.issueQueue.Push(issueNotificationOpts{ IssueID: pr.Issue.ID, NotificationAuthorID: doer.ID, }) } -func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest, mentions []*models.User) { +func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest, mentions []*user_model.User) { if err := pr.LoadIssue(); err != nil { log.Error("Unable to load issue: %d for pr: %d: Error: %v", pr.IssueID, pr.ID, err) return @@ -149,7 +150,7 @@ func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest, ment } } -func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, c *models.Comment, mentions []*models.User) { +func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, c *models.Comment, mentions []*user_model.User) { var opts = issueNotificationOpts{ IssueID: pr.Issue.ID, NotificationAuthorID: r.Reviewer.ID, @@ -171,7 +172,7 @@ func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r } } -func (ns *notificationService) NotifyPullRequestCodeComment(pr *models.PullRequest, c *models.Comment, mentions []*models.User) { +func (ns *notificationService) NotifyPullRequestCodeComment(pr *models.PullRequest, c *models.Comment, mentions []*user_model.User) { for _, mention := range mentions { _ = ns.issueQueue.Push(issueNotificationOpts{ IssueID: pr.Issue.ID, @@ -182,7 +183,7 @@ func (ns *notificationService) NotifyPullRequestCodeComment(pr *models.PullReque } } -func (ns *notificationService) NotifyPullRequestPushCommits(doer *models.User, pr *models.PullRequest, comment *models.Comment) { +func (ns *notificationService) NotifyPullRequestPushCommits(doer *user_model.User, pr *models.PullRequest, comment *models.Comment) { var opts = issueNotificationOpts{ IssueID: pr.IssueID, NotificationAuthorID: doer.ID, @@ -191,7 +192,7 @@ func (ns *notificationService) NotifyPullRequestPushCommits(doer *models.User, p _ = ns.issueQueue.Push(opts) } -func (ns *notificationService) NotifyPullRevieweDismiss(doer *models.User, review *models.Review, comment *models.Comment) { +func (ns *notificationService) NotifyPullRevieweDismiss(doer *user_model.User, review *models.Review, comment *models.Comment) { var opts = issueNotificationOpts{ IssueID: review.IssueID, NotificationAuthorID: doer.ID, @@ -200,7 +201,7 @@ func (ns *notificationService) NotifyPullRevieweDismiss(doer *models.User, revie _ = ns.issueQueue.Push(opts) } -func (ns *notificationService) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { +func (ns *notificationService) NotifyIssueChangeAssignee(doer *user_model.User, issue *models.Issue, assignee *user_model.User, removed bool, comment *models.Comment) { if !removed { var opts = issueNotificationOpts{ IssueID: issue.ID, @@ -216,7 +217,7 @@ func (ns *notificationService) NotifyIssueChangeAssignee(doer *models.User, issu } } -func (ns *notificationService) NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) { +func (ns *notificationService) NotifyPullReviewRequest(doer *user_model.User, issue *models.Issue, reviewer *user_model.User, isRequest bool, comment *models.Comment) { if isRequest { var opts = issueNotificationOpts{ IssueID: issue.ID, @@ -232,7 +233,7 @@ func (ns *notificationService) NotifyPullReviewRequest(doer *models.User, issue } } -func (ns *notificationService) NotifyRepoPendingTransfer(doer, newOwner *models.User, repo *models.Repository) { +func (ns *notificationService) NotifyRepoPendingTransfer(doer, newOwner *user_model.User, repo *models.Repository) { if err := models.CreateRepoTransferNotification(doer, newOwner, repo); err != nil { log.Error("NotifyRepoPendingTransfer: %v", err) } diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go index d5a947d9ac..8fe456e1c9 100644 --- a/modules/notification/webhook/webhook.go +++ b/modules/notification/webhook/webhook.go @@ -7,6 +7,7 @@ package webhook import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unit" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/git" @@ -31,7 +32,7 @@ func NewNotifier() base.Notifier { return &webhookNotifier{} } -func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) { +func (m *webhookNotifier) NotifyIssueClearLabels(doer *user_model.User, issue *models.Issue) { if err := issue.LoadPoster(); err != nil { log.Error("loadPoster: %v", err) return @@ -71,7 +72,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *model } } -func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) { +func (m *webhookNotifier) NotifyForkRepository(doer *user_model.User, oldRepo, repo *models.Repository) { oldMode, _ := models.AccessLevel(doer, oldRepo) mode, _ := models.AccessLevel(doer, repo) @@ -99,7 +100,7 @@ func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo } } -func (m *webhookNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) { +func (m *webhookNotifier) NotifyCreateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { // Add to hook queue for created repo after session commit. if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{ Action: api.HookRepoCreated, @@ -111,7 +112,7 @@ func (m *webhookNotifier) NotifyCreateRepository(doer *models.User, u *models.Us } } -func (m *webhookNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) { +func (m *webhookNotifier) NotifyDeleteRepository(doer *user_model.User, repo *models.Repository) { u := repo.MustOwner() if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{ @@ -124,7 +125,7 @@ func (m *webhookNotifier) NotifyDeleteRepository(doer *models.User, repo *models } } -func (m *webhookNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) { +func (m *webhookNotifier) NotifyMigrateRepository(doer *user_model.User, u *user_model.User, repo *models.Repository) { // Add to hook queue for created repo after session commit. if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventRepository, &api.RepositoryPayload{ Action: api.HookRepoCreated, @@ -136,7 +137,7 @@ func (m *webhookNotifier) NotifyMigrateRepository(doer *models.User, u *models.U } } -func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { +func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *user_model.User, issue *models.Issue, assignee *user_model.User, removed bool, comment *models.Comment) { if issue.IsPull { mode, _ := models.AccessLevelUnit(doer, issue.Repo, unit.TypePullRequests) @@ -182,7 +183,7 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *mo } } -func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) { +func (m *webhookNotifier) NotifyIssueChangeTitle(doer *user_model.User, issue *models.Issue, oldTitle string) { mode, _ := models.AccessLevel(issue.Poster, issue.Repo) var err error if issue.IsPull { @@ -223,7 +224,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *model } } -func (m *webhookNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) { +func (m *webhookNotifier) NotifyIssueChangeStatus(doer *user_model.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) { mode, _ := models.AccessLevel(issue.Poster, issue.Repo) var err error if issue.IsPull { @@ -263,7 +264,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(doer *models.User, issue *mode } } -func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models.User) { +func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue, mentions []*user_model.User) { if err := issue.LoadRepo(); err != nil { log.Error("issue.LoadRepo: %v", err) return @@ -285,7 +286,7 @@ func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models } } -func (m *webhookNotifier) NotifyNewPullRequest(pull *models.PullRequest, mentions []*models.User) { +func (m *webhookNotifier) NotifyNewPullRequest(pull *models.PullRequest, mentions []*user_model.User) { if err := pull.LoadIssue(); err != nil { log.Error("pull.LoadIssue: %v", err) return @@ -311,7 +312,7 @@ func (m *webhookNotifier) NotifyNewPullRequest(pull *models.PullRequest, mention } } -func (m *webhookNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { +func (m *webhookNotifier) NotifyIssueChangeContent(doer *user_model.User, issue *models.Issue, oldContent string) { mode, _ := models.AccessLevel(issue.Poster, issue.Repo) var err error if issue.IsPull { @@ -347,7 +348,7 @@ func (m *webhookNotifier) NotifyIssueChangeContent(doer *models.User, issue *mod } } -func (m *webhookNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) { +func (m *webhookNotifier) NotifyUpdateComment(doer *user_model.User, c *models.Comment, oldContent string) { var err error if err = c.LoadPoster(); err != nil { @@ -400,8 +401,8 @@ func (m *webhookNotifier) NotifyUpdateComment(doer *models.User, c *models.Comme } } -func (m *webhookNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository, - issue *models.Issue, comment *models.Comment, mentions []*models.User) { +func (m *webhookNotifier) NotifyCreateIssueComment(doer *user_model.User, repo *models.Repository, + issue *models.Issue, comment *models.Comment, mentions []*user_model.User) { mode, _ := models.AccessLevel(doer, repo) var err error @@ -430,7 +431,7 @@ func (m *webhookNotifier) NotifyCreateIssueComment(doer *models.User, repo *mode } } -func (m *webhookNotifier) NotifyDeleteComment(doer *models.User, comment *models.Comment) { +func (m *webhookNotifier) NotifyDeleteComment(doer *user_model.User, comment *models.Comment) { var err error if err = comment.LoadPoster(); err != nil { @@ -475,7 +476,7 @@ func (m *webhookNotifier) NotifyDeleteComment(doer *models.User, comment *models } -func (m *webhookNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, +func (m *webhookNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *models.Issue, addedLabels []*models.Label, removedLabels []*models.Label) { var err error @@ -520,7 +521,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *models.User, issue *mode } } -func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) { +func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *user_model.User, issue *models.Issue, oldMilestoneID int64) { var hookAction api.HookIssueAction var err error if issue.MilestoneID > 0 { @@ -562,7 +563,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *m } } -func (m *webhookNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (m *webhookNotifier) NotifyPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { apiPusher := convert.ToUser(pusher, nil) apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL()) if err != nil { @@ -585,7 +586,7 @@ func (m *webhookNotifier) NotifyPushCommits(pusher *models.User, repo *models.Re } } -func (*webhookNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) { +func (*webhookNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *user_model.User) { // Reload pull request information. if err := pr.LoadAttributes(); err != nil { log.Error("LoadAttributes: %v", err) @@ -623,7 +624,7 @@ func (*webhookNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mod } } -func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) { +func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(doer *user_model.User, pr *models.PullRequest, oldBranch string) { issue := pr.Issue if !issue.IsPull { return @@ -654,7 +655,7 @@ func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, } } -func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*models.User) { +func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review *models.Review, comment *models.Comment, mentions []*user_model.User) { var reviewHookType webhook.HookEventType switch review.Type { @@ -695,7 +696,7 @@ func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review } } -func (m *webhookNotifier) NotifyCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) { +func (m *webhookNotifier) NotifyCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { apiPusher := convert.ToUser(pusher, nil) apiRepo := convert.ToRepo(repo, models.AccessModeNone) refName := git.RefEndName(refFullName) @@ -725,7 +726,7 @@ func (m *webhookNotifier) NotifyCreateRef(pusher *models.User, repo *models.Repo } } -func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) { +func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *user_model.User, pr *models.PullRequest) { if err := pr.LoadIssue(); err != nil { log.Error("pr.LoadIssue: %v", err) return @@ -746,7 +747,7 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *m } } -func (m *webhookNotifier) NotifyDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) { +func (m *webhookNotifier) NotifyDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { apiPusher := convert.ToUser(pusher, nil) apiRepo := convert.ToRepo(repo, models.AccessModeNone) refName := git.RefEndName(refFullName) @@ -762,7 +763,7 @@ func (m *webhookNotifier) NotifyDeleteRef(pusher *models.User, repo *models.Repo } } -func sendReleaseHook(doer *models.User, rel *models.Release, action api.HookReleaseAction) { +func sendReleaseHook(doer *user_model.User, rel *models.Release, action api.HookReleaseAction) { if err := rel.LoadAttributes(); err != nil { log.Error("LoadAttributes: %v", err) return @@ -783,15 +784,15 @@ func (m *webhookNotifier) NotifyNewRelease(rel *models.Release) { sendReleaseHook(rel.Publisher, rel, api.HookReleasePublished) } -func (m *webhookNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) { +func (m *webhookNotifier) NotifyUpdateRelease(doer *user_model.User, rel *models.Release) { sendReleaseHook(doer, rel, api.HookReleaseUpdated) } -func (m *webhookNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) { +func (m *webhookNotifier) NotifyDeleteRelease(doer *user_model.User, rel *models.Release) { sendReleaseHook(doer, rel, api.HookReleaseDeleted) } -func (m *webhookNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { +func (m *webhookNotifier) NotifySyncPushCommits(pusher *user_model.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) { apiPusher := convert.ToUser(pusher, nil) apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL()) if err != nil { @@ -814,10 +815,10 @@ func (m *webhookNotifier) NotifySyncPushCommits(pusher *models.User, repo *model } } -func (m *webhookNotifier) NotifySyncCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) { +func (m *webhookNotifier) NotifySyncCreateRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { m.NotifyCreateRef(pusher, repo, refType, refFullName) } -func (m *webhookNotifier) NotifySyncDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) { +func (m *webhookNotifier) NotifySyncDeleteRef(pusher *user_model.User, repo *models.Repository, refType, refFullName string) { m.NotifyDeleteRef(pusher, repo, refType, refFullName) } diff --git a/modules/private/serv.go b/modules/private/serv.go index c378dc6dc7..7e4805d60c 100644 --- a/modules/private/serv.go +++ b/modules/private/serv.go @@ -11,6 +11,7 @@ import ( "net/url" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/setting" ) @@ -18,11 +19,11 @@ import ( // KeyAndOwner is the response from ServNoCommand type KeyAndOwner struct { Key *models.PublicKey `json:"key"` - Owner *models.User `json:"user"` + Owner *user_model.User `json:"user"` } // ServNoCommand returns information about the provided key -func ServNoCommand(ctx context.Context, keyID int64) (*models.PublicKey, *models.User, error) { +func ServNoCommand(ctx context.Context, keyID int64) (*models.PublicKey, *user_model.User, error) { reqURL := setting.LocalURL + fmt.Sprintf("api/internal/serv/none/%d", keyID) resp, err := newInternalRequest(ctx, reqURL, "GET").Response() diff --git a/modules/repofiles/commit_status.go b/modules/repofiles/commit_status.go new file mode 100644 index 0000000000..2074b4b464 --- /dev/null +++ b/modules/repofiles/commit_status.go @@ -0,0 +1,42 @@ +// 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 repofiles + +import ( + "fmt" + + "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/git" +) + +// CreateCommitStatus creates a new CommitStatus given a bunch of parameters +// NOTE: All text-values will be trimmed from whitespaces. +// Requires: Repo, Creator, SHA +func CreateCommitStatus(repo *models.Repository, creator *user_model.User, sha string, status *models.CommitStatus) error { + repoPath := repo.RepoPath() + + // confirm that commit is exist + gitRepo, err := git.OpenRepository(repoPath) + if err != nil { + return fmt.Errorf("OpenRepository[%s]: %v", repoPath, err) + } + if _, err := gitRepo.GetCommit(sha); err != nil { + gitRepo.Close() + return fmt.Errorf("GetCommit[%s]: %v", sha, err) + } + gitRepo.Close() + + if err := models.NewCommitStatus(models.NewCommitStatusOptions{ + Repo: repo, + Creator: creator, + SHA: sha, + CommitStatus: status, + }); err != nil { + return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %v", repo.ID, creator.ID, sha, err) + } + + return nil +} diff --git a/modules/repository/commits.go b/modules/repository/commits.go index a545ce952b..8e727c95d0 100644 --- a/modules/repository/commits.go +++ b/modules/repository/commits.go @@ -9,8 +9,8 @@ import ( "net/url" "time" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/avatars" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" api "code.gitea.io/gitea/modules/structs" @@ -35,14 +35,14 @@ type PushCommits struct { Len int avatars map[string]string - emailUsers map[string]*models.User + emailUsers map[string]*user_model.User } // NewPushCommits creates a new PushCommits object. func NewPushCommits() *PushCommits { return &PushCommits{ avatars: make(map[string]string), - emailUsers: make(map[string]*models.User), + emailUsers: make(map[string]*user_model.User), } } @@ -52,7 +52,7 @@ func (pc *PushCommits) toAPIPayloadCommit(repoPath, repoLink string, commit *Pus authorUsername := "" author, ok := pc.emailUsers[commit.AuthorEmail] if !ok { - author, err = models.GetUserByEmail(commit.AuthorEmail) + author, err = user_model.GetUserByEmail(commit.AuthorEmail) if err == nil { authorUsername = author.Name pc.emailUsers[commit.AuthorEmail] = author @@ -64,7 +64,7 @@ func (pc *PushCommits) toAPIPayloadCommit(repoPath, repoLink string, commit *Pus committerUsername := "" committer, ok := pc.emailUsers[commit.CommitterEmail] if !ok { - committer, err = models.GetUserByEmail(commit.CommitterEmail) + committer, err = user_model.GetUserByEmail(commit.CommitterEmail) if err == nil { // TODO: check errors other than email not found. committerUsername = committer.Name @@ -107,7 +107,7 @@ func (pc *PushCommits) ToAPIPayloadCommits(repoPath, repoLink string) ([]*api.Pa var headCommit *api.PayloadCommit if pc.emailUsers == nil { - pc.emailUsers = make(map[string]*models.User) + pc.emailUsers = make(map[string]*user_model.User) } for i, commit := range pc.Commits { apiCommit, err := pc.toAPIPayloadCommit(repoPath, repoLink, commit) @@ -146,10 +146,10 @@ func (pc *PushCommits) AvatarLink(email string) string { u, ok := pc.emailUsers[email] if !ok { var err error - u, err = models.GetUserByEmail(email) + u, err = user_model.GetUserByEmail(email) if err != nil { pc.avatars[email] = avatars.GenerateEmailAvatarFastLink(email, size) - if !models.IsErrUserNotExist(err) { + if !user_model.IsErrUserNotExist(err) { log.Error("GetUserByEmail: %v", err) return "" } @@ -189,6 +189,6 @@ func GitToPushCommits(gitCommits []*git.Commit) *PushCommits { CompareURL: "", Len: len(commits), avatars: make(map[string]string), - emailUsers: make(map[string]*models.User), + emailUsers: make(map[string]*user_model.User), } } diff --git a/modules/repository/create.go b/modules/repository/create.go index 64d92eeb2d..850f7488bd 100644 --- a/modules/repository/create.go +++ b/modules/repository/create.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -18,7 +19,7 @@ import ( ) // CreateRepository creates a repository for the user/organization. -func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*models.Repository, error) { +func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (*models.Repository, error) { if !doer.IsAdmin && !u.CanCreateRepo() { return nil, models.ErrReachLimitOfRepo{ Limit: u.MaxRepoCreation, diff --git a/modules/repository/create_test.go b/modules/repository/create_test.go index 12fc7afeeb..d7d3281872 100644 --- a/modules/repository/create_test.go +++ b/modules/repository/create_test.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/structs" "github.com/stretchr/testify/assert" @@ -32,14 +33,14 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) { } // Get an admin user. - user, err := models.GetUserByID(1) + user, err := user_model.GetUserByID(1) assert.NoError(t, err, "GetUserByID") // Create org. org := &models.Organization{ Name: "All_repo", IsActive: true, - Type: models.UserTypeOrganization, + Type: user_model.UserTypeOrganization, Visibility: structs.VisibleTypePublic, } assert.NoError(t, models.CreateOrganization(org, user), "CreateOrganization") diff --git a/modules/repository/generate.go b/modules/repository/generate.go index f6b76b14af..61a8b0d111 100644 --- a/modules/repository/generate.go +++ b/modules/repository/generate.go @@ -14,6 +14,7 @@ import ( "time" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/util" @@ -239,7 +240,7 @@ func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *models. } // GenerateRepository generates a repository from a template -func GenerateRepository(ctx context.Context, doer, owner *models.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) { +func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) { generateRepo := &models.Repository{ OwnerID: owner.ID, Owner: owner, diff --git a/modules/repository/init.go b/modules/repository/init.go index 076dbf748e..d7f31fabde 100644 --- a/modules/repository/init.go +++ b/modules/repository/init.go @@ -14,6 +14,7 @@ import ( "time" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" @@ -100,7 +101,7 @@ func prepareRepoCommit(ctx context.Context, repo *models.Repository, tmpDir, rep } // initRepoCommit temporarily changes with work directory. -func initRepoCommit(tmpPath string, repo *models.Repository, u *models.User, defaultBranch string) (err error) { +func initRepoCommit(tmpPath string, repo *models.Repository, u *user_model.User, defaultBranch string) (err error) { commitTimeStr := time.Now().Format(time.RFC3339) sig := u.NewGitSig() @@ -197,7 +198,7 @@ func checkInitRepository(owner, name string) (err error) { } // InitRepository initializes README and .gitignore if needed. -func initRepository(ctx context.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) { +func initRepository(ctx context.Context, repoPath string, u *user_model.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) { if err = checkInitRepository(repo.OwnerName, repo.Name); err != nil { return err } diff --git a/modules/repository/repo.go b/modules/repository/repo.go index dd54a99cc9..c7145658f8 100644 --- a/modules/repository/repo.go +++ b/modules/repository/repo.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" @@ -46,7 +47,7 @@ func WikiRemoteURL(remote string) string { } // MigrateRepositoryGitData starts migrating git related data after created migrating repository -func MigrateRepositoryGitData(ctx context.Context, u *models.User, +func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, repo *models.Repository, opts migration.MigrateOptions, httpTransport *http.Transport, ) (*models.Repository, error) { @@ -307,12 +308,12 @@ func PushUpdateAddTag(repo *models.Repository, gitRepo *git.Repository, tagName sig = commit.Committer } - var author *models.User + var author *user_model.User var createdAt = time.Unix(1, 0) if sig != nil { - author, err = models.GetUserByEmail(sig.Email) - if err != nil && !models.IsErrUserNotExist(err) { + author, err = user_model.GetUserByEmail(sig.Email) + if err != nil && !user_model.IsErrUserNotExist(err) { return fmt.Errorf("GetUserByEmail: %v", err) } createdAt = sig.When diff --git a/modules/templates/helper.go b/modules/templates/helper.go index aec3596bd4..4eb8f34707 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -24,6 +24,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/avatars" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/emoji" "code.gitea.io/gitea/modules/git" @@ -554,7 +555,7 @@ func Avatar(item interface{}, others ...interface{}) template.HTML { size, class := parseOthers(avatars.DefaultAvatarPixelSize, "ui avatar image", others...) switch t := item.(type) { - case *models.User: + case *user_model.User: src := t.AvatarLinkWithSize(size * avatars.AvatarRenderedSizeFactor) if src != "" { return AvatarHTML(src, size, class, t.DisplayName()) diff --git a/modules/test/context_tests.go b/modules/test/context_tests.go index eb1a54d86f..548e454c8e 100644 --- a/modules/test/context_tests.go +++ b/modules/test/context_tests.go @@ -15,6 +15,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/web/middleware" @@ -55,7 +56,7 @@ func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) { ctx.Repo = &context.Repository{} ctx.Repo.Repository = unittest.AssertExistsAndLoadBean(t, &models.Repository{ID: repoID}).(*models.Repository) var err error - ctx.Repo.Owner, err = models.GetUserByID(ctx.Repo.Repository.OwnerID) + ctx.Repo.Owner, err = user_model.GetUserByID(ctx.Repo.Repository.OwnerID) assert.NoError(t, err) ctx.Repo.RepoLink = ctx.Repo.Repository.Link() ctx.Repo.Permission, err = models.GetUserRepoPermission(ctx.Repo.Repository, ctx.User) @@ -78,7 +79,7 @@ func LoadRepoCommit(t *testing.T, ctx *context.Context) { // LoadUser load a user into a test context. func LoadUser(t *testing.T, ctx *context.Context, userID int64) { - ctx.User = unittest.AssertExistsAndLoadBean(t, &models.User{ID: userID}).(*models.User) + ctx.User = unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID}).(*user_model.User) } // LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has |