mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 13:28:25 +00:00
Merge branch 'main' into api-repo-actions
This commit is contained in:
@@ -6,9 +6,9 @@ package actions
|
||||
import (
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/queue"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
func Init() {
|
||||
@@ -22,5 +22,5 @@ func Init() {
|
||||
}
|
||||
go graceful.GetManager().RunWithCancel(jobEmitterQueue)
|
||||
|
||||
notification.RegisterNotifier(NewNotifier())
|
||||
notify_service.RegisterNotifier(NewNotifier())
|
||||
}
|
||||
|
||||
@@ -15,28 +15,28 @@ import (
|
||||
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/notification/base"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
type actionsNotifier struct {
|
||||
base.NullNotifier
|
||||
notify_service.NullNotifier
|
||||
}
|
||||
|
||||
var _ base.Notifier = &actionsNotifier{}
|
||||
var _ notify_service.Notifier = &actionsNotifier{}
|
||||
|
||||
// NewNotifier create a new actionsNotifier notifier
|
||||
func NewNotifier() base.Notifier {
|
||||
func NewNotifier() notify_service.Notifier {
|
||||
return &actionsNotifier{}
|
||||
}
|
||||
|
||||
// NotifyNewIssue notifies issue created event
|
||||
func (n *actionsNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, _ []*user_model.User) {
|
||||
ctx = withMethod(ctx, "NotifyNewIssue")
|
||||
// NewIssue notifies issue created event
|
||||
func (n *actionsNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, _ []*user_model.User) {
|
||||
ctx = withMethod(ctx, "NewIssue")
|
||||
if err := issue.LoadRepo(ctx); err != nil {
|
||||
log.Error("issue.LoadRepo: %v", err)
|
||||
return
|
||||
@@ -53,12 +53,12 @@ func (n *actionsNotifier) NotifyNewIssue(ctx context.Context, issue *issues_mode
|
||||
Issue: convert.ToAPIIssue(ctx, issue),
|
||||
Repository: convert.ToRepo(ctx, issue.Repo, permission),
|
||||
Sender: convert.ToUser(ctx, issue.Poster, nil),
|
||||
}).Notify(withMethod(ctx, "NotifyNewIssue"))
|
||||
}).Notify(withMethod(ctx, "NewIssue"))
|
||||
}
|
||||
|
||||
// NotifyIssueChangeStatus notifies close or reopen issue to notifiers
|
||||
func (n *actionsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, _ *issues_model.Comment, isClosed bool) {
|
||||
ctx = withMethod(ctx, "NotifyIssueChangeStatus")
|
||||
// IssueChangeStatus notifies close or reopen issue to notifiers
|
||||
func (n *actionsNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, _ *issues_model.Comment, isClosed bool) {
|
||||
ctx = withMethod(ctx, "IssueChangeStatus")
|
||||
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster)
|
||||
if issue.IsPull {
|
||||
if err := issue.LoadPullRequest(ctx); err != nil {
|
||||
@@ -102,10 +102,10 @@ func (n *actionsNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use
|
||||
Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
|
||||
func (n *actionsNotifier) IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
|
||||
_, _ []*issues_model.Label,
|
||||
) {
|
||||
ctx = withMethod(ctx, "NotifyIssueChangeLabels")
|
||||
ctx = withMethod(ctx, "IssueChangeLabels")
|
||||
|
||||
var err error
|
||||
if err = issue.LoadRepo(ctx); err != nil {
|
||||
@@ -153,11 +153,11 @@ func (n *actionsNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *use
|
||||
Notify(ctx)
|
||||
}
|
||||
|
||||
// NotifyCreateIssueComment notifies comment on an issue to notifiers
|
||||
func (n *actionsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
||||
// CreateIssueComment notifies comment on an issue to notifiers
|
||||
func (n *actionsNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
||||
issue *issues_model.Issue, comment *issues_model.Comment, _ []*user_model.User,
|
||||
) {
|
||||
ctx = withMethod(ctx, "NotifyCreateIssueComment")
|
||||
ctx = withMethod(ctx, "CreateIssueComment")
|
||||
|
||||
permission, _ := access_model.GetUserRepoPermission(ctx, repo, doer)
|
||||
|
||||
@@ -193,8 +193,8 @@ func (n *actionsNotifier) NotifyCreateIssueComment(ctx context.Context, doer *us
|
||||
Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues_model.PullRequest, _ []*user_model.User) {
|
||||
ctx = withMethod(ctx, "NotifyNewPullRequest")
|
||||
func (n *actionsNotifier) NewPullRequest(ctx context.Context, pull *issues_model.PullRequest, _ []*user_model.User) {
|
||||
ctx = withMethod(ctx, "NewPullRequest")
|
||||
|
||||
if err := pull.LoadIssue(ctx); err != nil {
|
||||
log.Error("pull.LoadIssue: %v", err)
|
||||
@@ -223,8 +223,8 @@ func (n *actionsNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues
|
||||
Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
ctx = withMethod(ctx, "NotifyCreateRepository")
|
||||
func (n *actionsNotifier) CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
ctx = withMethod(ctx, "CreateRepository")
|
||||
|
||||
newNotifyInput(repo, doer, webhook_module.HookEventRepository).WithPayload(&api.RepositoryPayload{
|
||||
Action: api.HookRepoCreated,
|
||||
@@ -234,8 +234,8 @@ func (n *actionsNotifier) NotifyCreateRepository(ctx context.Context, doer, u *u
|
||||
}).Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
|
||||
ctx = withMethod(ctx, "NotifyForkRepository")
|
||||
func (n *actionsNotifier) ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
|
||||
ctx = withMethod(ctx, "ForkRepository")
|
||||
|
||||
oldPermission, _ := access_model.GetUserRepoPermission(ctx, oldRepo, doer)
|
||||
permission, _ := access_model.GetUserRepoPermission(ctx, repo, doer)
|
||||
@@ -262,8 +262,8 @@ func (n *actionsNotifier) NotifyForkRepository(ctx context.Context, doer *user_m
|
||||
}
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, _ *issues_model.Comment, _ []*user_model.User) {
|
||||
ctx = withMethod(ctx, "NotifyPullRequestReview")
|
||||
func (n *actionsNotifier) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, _ *issues_model.Comment, _ []*user_model.User) {
|
||||
ctx = withMethod(ctx, "PullRequestReview")
|
||||
|
||||
var reviewHookType webhook_module.HookEventType
|
||||
|
||||
@@ -306,8 +306,8 @@ func (n *actionsNotifier) NotifyPullRequestReview(ctx context.Context, pr *issue
|
||||
}).Notify(ctx)
|
||||
}
|
||||
|
||||
func (*actionsNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
ctx = withMethod(ctx, "NotifyMergePullRequest")
|
||||
func (*actionsNotifier) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
ctx = withMethod(ctx, "MergePullRequest")
|
||||
|
||||
// Reload pull request information.
|
||||
if err := pr.LoadAttributes(ctx); err != nil {
|
||||
@@ -347,8 +347,8 @@ func (*actionsNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_m
|
||||
Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
ctx = withMethod(ctx, "NotifyPushCommits")
|
||||
func (n *actionsNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
ctx = withMethod(ctx, "PushCommits")
|
||||
|
||||
apiPusher := convert.ToUser(ctx, pusher, nil)
|
||||
apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL())
|
||||
@@ -373,8 +373,8 @@ func (n *actionsNotifier) NotifyPushCommits(ctx context.Context, pusher *user_mo
|
||||
Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
ctx = withMethod(ctx, "NotifyCreateRef")
|
||||
func (n *actionsNotifier) CreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
ctx = withMethod(ctx, "CreateRef")
|
||||
|
||||
apiPusher := convert.ToUser(ctx, pusher, nil)
|
||||
apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeNone})
|
||||
@@ -391,8 +391,8 @@ func (n *actionsNotifier) NotifyCreateRef(ctx context.Context, pusher *user_mode
|
||||
Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
ctx = withMethod(ctx, "NotifyDeleteRef")
|
||||
func (n *actionsNotifier) DeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
ctx = withMethod(ctx, "DeleteRef")
|
||||
|
||||
apiPusher := convert.ToUser(ctx, pusher, nil)
|
||||
apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeNone})
|
||||
@@ -409,8 +409,8 @@ func (n *actionsNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_mode
|
||||
Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
ctx = withMethod(ctx, "NotifySyncPushCommits")
|
||||
func (n *actionsNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
ctx = withMethod(ctx, "SyncPushCommits")
|
||||
|
||||
apiPusher := convert.ToUser(ctx, pusher, nil)
|
||||
apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(db.DefaultContext, repo.RepoPath(), repo.HTMLURL())
|
||||
@@ -436,48 +436,48 @@ func (n *actionsNotifier) NotifySyncPushCommits(ctx context.Context, pusher *use
|
||||
Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
ctx = withMethod(ctx, "NotifySyncCreateRef")
|
||||
n.NotifyCreateRef(ctx, pusher, repo, refFullName, refID)
|
||||
func (n *actionsNotifier) SyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
ctx = withMethod(ctx, "SyncCreateRef")
|
||||
n.CreateRef(ctx, pusher, repo, refFullName, refID)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
ctx = withMethod(ctx, "NotifySyncDeleteRef")
|
||||
n.NotifyDeleteRef(ctx, pusher, repo, refFullName)
|
||||
func (n *actionsNotifier) SyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
ctx = withMethod(ctx, "SyncDeleteRef")
|
||||
n.DeleteRef(ctx, pusher, repo, refFullName)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) {
|
||||
ctx = withMethod(ctx, "NotifyNewRelease")
|
||||
func (n *actionsNotifier) NewRelease(ctx context.Context, rel *repo_model.Release) {
|
||||
ctx = withMethod(ctx, "NewRelease")
|
||||
notifyRelease(ctx, rel.Publisher, rel, api.HookReleasePublished)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
||||
ctx = withMethod(ctx, "NotifyUpdateRelease")
|
||||
func (n *actionsNotifier) UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
||||
ctx = withMethod(ctx, "UpdateRelease")
|
||||
notifyRelease(ctx, doer, rel, api.HookReleaseUpdated)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
||||
ctx = withMethod(ctx, "NotifyDeleteRelease")
|
||||
func (n *actionsNotifier) DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
||||
ctx = withMethod(ctx, "DeleteRelease")
|
||||
notifyRelease(ctx, doer, rel, api.HookReleaseDeleted)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
||||
ctx = withMethod(ctx, "NotifyPackageCreate")
|
||||
func (n *actionsNotifier) PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
||||
ctx = withMethod(ctx, "PackageCreate")
|
||||
notifyPackage(ctx, doer, pd, api.HookPackageCreated)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
||||
ctx = withMethod(ctx, "NotifyPackageDelete")
|
||||
func (n *actionsNotifier) PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
||||
ctx = withMethod(ctx, "PackageDelete")
|
||||
notifyPackage(ctx, doer, pd, api.HookPackageDeleted)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
ctx = withMethod(ctx, "NotifyAutoMergePullRequest")
|
||||
n.NotifyMergePullRequest(ctx, doer, pr)
|
||||
func (n *actionsNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
ctx = withMethod(ctx, "AutoMergePullRequest")
|
||||
n.MergePullRequest(ctx, doer, pr)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
ctx = withMethod(ctx, "NotifyPullRequestSynchronized")
|
||||
func (n *actionsNotifier) PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
ctx = withMethod(ctx, "PullRequestSynchronized")
|
||||
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
log.Error("LoadAttributes: %v", err)
|
||||
@@ -501,8 +501,8 @@ func (n *actionsNotifier) NotifyPullRequestSynchronized(ctx context.Context, doe
|
||||
Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
|
||||
ctx = withMethod(ctx, "NotifyPullRequestChangeTargetBranch")
|
||||
func (n *actionsNotifier) PullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
|
||||
ctx = withMethod(ctx, "PullRequestChangeTargetBranch")
|
||||
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
log.Error("LoadAttributes: %v", err)
|
||||
@@ -532,8 +532,8 @@ func (n *actionsNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Contex
|
||||
Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
|
||||
ctx = withMethod(ctx, "NotifyNewWikiPage")
|
||||
func (n *actionsNotifier) NewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
|
||||
ctx = withMethod(ctx, "NewWikiPage")
|
||||
|
||||
newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
|
||||
Action: api.HookWikiCreated,
|
||||
@@ -544,8 +544,8 @@ func (n *actionsNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_mode
|
||||
}).Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
|
||||
ctx = withMethod(ctx, "NotifyEditWikiPage")
|
||||
func (n *actionsNotifier) EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
|
||||
ctx = withMethod(ctx, "EditWikiPage")
|
||||
|
||||
newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
|
||||
Action: api.HookWikiEdited,
|
||||
@@ -556,8 +556,8 @@ func (n *actionsNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_mod
|
||||
}).Notify(ctx)
|
||||
}
|
||||
|
||||
func (n *actionsNotifier) NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
|
||||
ctx = withMethod(ctx, "NotifyDeleteWikiPage")
|
||||
func (n *actionsNotifier) DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
|
||||
ctx = withMethod(ctx, "DeleteWikiPage")
|
||||
|
||||
newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
|
||||
Action: api.HookWikiDeleted,
|
||||
|
||||
@@ -14,8 +14,8 @@ import (
|
||||
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/notification"
|
||||
"code.gitea.io/gitea/modules/private"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
)
|
||||
|
||||
@@ -208,9 +208,9 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
}
|
||||
comment, err := pull_service.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i])
|
||||
if err == nil && comment != nil {
|
||||
notification.NotifyPullRequestPushCommits(ctx, pusher, pr, comment)
|
||||
notify_service.PullRequestPushCommits(ctx, pusher, pr, comment)
|
||||
}
|
||||
notification.NotifyPullRequestSynchronized(ctx, pusher, pr)
|
||||
notify_service.PullRequestSynchronized(ctx, pusher, pr)
|
||||
isForcePush := comment != nil && comment.IsForcePush
|
||||
|
||||
results = append(results, private.HookProcReceiveRefResult{
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
// Ensure the struct implements the interface.
|
||||
var (
|
||||
_ Method = &Basic{}
|
||||
_ Named = &Basic{}
|
||||
)
|
||||
|
||||
// BasicMethodName is the constant name of the basic authentication method
|
||||
|
||||
+4
-12
@@ -5,7 +5,6 @@ package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -37,21 +36,16 @@ func (b *Group) Add(method Method) {
|
||||
func (b *Group) Name() string {
|
||||
names := make([]string, 0, len(b.methods))
|
||||
for _, m := range b.methods {
|
||||
if n, ok := m.(Named); ok {
|
||||
names = append(names, n.Name())
|
||||
} else {
|
||||
names = append(names, reflect.TypeOf(m).Elem().Name())
|
||||
}
|
||||
names = append(names, m.Name())
|
||||
}
|
||||
return strings.Join(names, ",")
|
||||
}
|
||||
|
||||
// Verify extracts and validates
|
||||
func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error) {
|
||||
// Try to sign in with each of the enabled plugins
|
||||
var retErr error
|
||||
for _, ssoMethod := range b.methods {
|
||||
user, err := ssoMethod.Verify(req, w, store, sess)
|
||||
for _, m := range b.methods {
|
||||
user, err := m.Verify(req, w, store, sess)
|
||||
if err != nil {
|
||||
if retErr == nil {
|
||||
retErr = err
|
||||
@@ -67,9 +61,7 @@ func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore
|
||||
// Return the user and ignore any error returned by previous methods.
|
||||
if user != nil {
|
||||
if store.GetData()["AuthedMethod"] == nil {
|
||||
if named, ok := ssoMethod.(Named); ok {
|
||||
store.GetData()["AuthedMethod"] = named.Name()
|
||||
}
|
||||
store.GetData()["AuthedMethod"] = m.Name()
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
// Ensure the struct implements the interface.
|
||||
var (
|
||||
_ Method = &HTTPSign{}
|
||||
_ Named = &HTTPSign{}
|
||||
)
|
||||
|
||||
// HTTPSign implements the Auth interface and authenticates requests (API requests
|
||||
|
||||
@@ -27,10 +27,7 @@ type Method interface {
|
||||
// Second argument returns err if verification fails, otherwise
|
||||
// First return argument returns nil if no matched verification condition
|
||||
Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) (*user_model.User, error)
|
||||
}
|
||||
|
||||
// Named represents a named thing
|
||||
type Named interface {
|
||||
Name() string
|
||||
}
|
||||
|
||||
|
||||
@@ -120,9 +120,9 @@ func VerifyAuthWithOptions(options *VerifyOptions) func(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to dashboard if user tries to visit any non-login page.
|
||||
// Redirect to dashboard (or alternate location) if user tries to visit any non-login page.
|
||||
if options.SignOutRequired && ctx.IsSigned && ctx.Req.URL.RequestURI() != "/" {
|
||||
ctx.Redirect(setting.AppSubURL + "/")
|
||||
ctx.RedirectToFirst(ctx.FormString("redirect_to"))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
// Ensure the struct implements the interface.
|
||||
var (
|
||||
_ Method = &OAuth2{}
|
||||
_ Named = &OAuth2{}
|
||||
)
|
||||
|
||||
// CheckOAuthAccessToken returns uid of user from oauth token
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
// Ensure the struct implements the interface.
|
||||
var (
|
||||
_ Method = &ReverseProxy{}
|
||||
_ Named = &ReverseProxy{}
|
||||
)
|
||||
|
||||
// ReverseProxyMethodName is the constant name of the ReverseProxy authentication method
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
// Ensure the struct implements the interface.
|
||||
var (
|
||||
_ Method = &Session{}
|
||||
_ Named = &Session{}
|
||||
)
|
||||
|
||||
// Session checks if there is a user uid stored in the session and returns the user
|
||||
|
||||
@@ -114,12 +114,13 @@ share the following fields:
|
||||
* Example: (|(cn=gitea_users)(cn=admins))
|
||||
|
||||
* User Attribute in Group (optional)
|
||||
* Which user LDAP attribute is listed in the group.
|
||||
* Example: uid
|
||||
* The user attribute that is used to reference a user in the group object.
|
||||
* Example: uid if the group objects contains a member: bender and the user object contains a uid: bender.
|
||||
* Example: dn if the group object contains a member: uid=bender,ou=users,dc=planetexpress,dc=com.
|
||||
|
||||
* Group Attribute for User (optional)
|
||||
* Which group LDAP attribute contains an array above user attribute names.
|
||||
* Example: memberUid
|
||||
* The attribute of the group object that lists/contains the group members.
|
||||
* Example: memberUid or member
|
||||
|
||||
* Team group map (optional)
|
||||
* Automatically add users to Organization teams, depending on LDAP group memberships.
|
||||
|
||||
@@ -37,7 +37,6 @@ var (
|
||||
|
||||
// Ensure the struct implements the interface.
|
||||
_ Method = &SSPI{}
|
||||
_ Named = &SSPI{}
|
||||
)
|
||||
|
||||
// SSPI implements the SingleSignOn interface and authenticates requests
|
||||
|
||||
@@ -0,0 +1,458 @@
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package feed
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
type actionNotifier struct {
|
||||
notify_service.NullNotifier
|
||||
}
|
||||
|
||||
var _ notify_service.Notifier = &actionNotifier{}
|
||||
|
||||
func Init() error {
|
||||
notify_service.RegisterNotifier(NewNotifier())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewNotifier create a new actionNotifier notifier
|
||||
func NewNotifier() notify_service.Notifier {
|
||||
return &actionNotifier{}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
|
||||
if err := issue.LoadPoster(ctx); err != nil {
|
||||
log.Error("issue.LoadPoster: %v", err)
|
||||
return
|
||||
}
|
||||
if err := issue.LoadRepo(ctx); err != nil {
|
||||
log.Error("issue.LoadRepo: %v", err)
|
||||
return
|
||||
}
|
||||
repo := issue.Repo
|
||||
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: issue.Poster.ID,
|
||||
ActUser: issue.Poster,
|
||||
OpType: activities_model.ActionCreateIssue,
|
||||
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Title),
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// IssueChangeStatus notifies close or reopen issue to notifiers
|
||||
func (a *actionNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.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 := &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
Content: fmt.Sprintf("%d|%s", issue.Index, ""),
|
||||
RepoID: issue.Repo.ID,
|
||||
Repo: issue.Repo,
|
||||
Comment: actionComment,
|
||||
CommentID: actionComment.ID,
|
||||
IsPrivate: issue.Repo.IsPrivate,
|
||||
}
|
||||
// Check comment type.
|
||||
if closeOrReopen {
|
||||
act.OpType = activities_model.ActionCloseIssue
|
||||
if issue.IsPull {
|
||||
act.OpType = activities_model.ActionClosePullRequest
|
||||
}
|
||||
} else {
|
||||
act.OpType = activities_model.ActionReopenIssue
|
||||
if issue.IsPull {
|
||||
act.OpType = activities_model.ActionReopenPullRequest
|
||||
}
|
||||
}
|
||||
|
||||
// Notify watchers for whatever action comes in, ignore if no action type.
|
||||
if err := activities_model.NotifyWatchers(ctx, act); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateIssueComment notifies comment on an issue to notifiers
|
||||
func (a *actionNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
||||
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
|
||||
) {
|
||||
act := &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
RepoID: issue.Repo.ID,
|
||||
Repo: issue.Repo,
|
||||
Comment: comment,
|
||||
CommentID: comment.ID,
|
||||
IsPrivate: issue.Repo.IsPrivate,
|
||||
}
|
||||
|
||||
truncatedContent, truncatedRight := util.SplitStringAtByteN(comment.Content, 200)
|
||||
if truncatedRight != "" {
|
||||
// in case the content is in a Latin family language, we remove the last broken word.
|
||||
lastSpaceIdx := strings.LastIndex(truncatedContent, " ")
|
||||
if lastSpaceIdx != -1 && (len(truncatedContent)-lastSpaceIdx < 15) {
|
||||
truncatedContent = truncatedContent[:lastSpaceIdx] + "…"
|
||||
}
|
||||
}
|
||||
act.Content = fmt.Sprintf("%d|%s", issue.Index, truncatedContent)
|
||||
|
||||
if issue.IsPull {
|
||||
act.OpType = activities_model.ActionCommentPull
|
||||
} else {
|
||||
act.OpType = activities_model.ActionCommentIssue
|
||||
}
|
||||
|
||||
// Notify watchers for whatever action comes in, ignore if no action type.
|
||||
if err := activities_model.NotifyWatchers(ctx, act); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) NewPullRequest(ctx context.Context, pull *issues_model.PullRequest, mentions []*user_model.User) {
|
||||
if err := pull.LoadIssue(ctx); err != nil {
|
||||
log.Error("pull.LoadIssue: %v", err)
|
||||
return
|
||||
}
|
||||
if err := pull.Issue.LoadRepo(ctx); err != nil {
|
||||
log.Error("pull.Issue.LoadRepo: %v", err)
|
||||
return
|
||||
}
|
||||
if err := pull.Issue.LoadPoster(ctx); err != nil {
|
||||
log.Error("pull.Issue.LoadPoster: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: pull.Issue.Poster.ID,
|
||||
ActUser: pull.Issue.Poster,
|
||||
OpType: activities_model.ActionCreatePullRequest,
|
||||
Content: fmt.Sprintf("%d|%s", pull.Issue.Index, pull.Issue.Title),
|
||||
RepoID: pull.Issue.Repo.ID,
|
||||
Repo: pull.Issue.Repo,
|
||||
IsPrivate: pull.Issue.Repo.IsPrivate,
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) RenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionRenameRepo,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
Content: oldRepoName,
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) TransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionTransferRepo,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
Content: path.Join(oldOwnerName, repo.Name),
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionCreateRepo,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
}); err != nil {
|
||||
log.Error("notify watchers '%d/%d': %v", doer.ID, repo.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionCreateRepo,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
}); err != nil {
|
||||
log.Error("notify watchers '%d/%d': %v", doer.ID, repo.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
|
||||
if err := review.LoadReviewer(ctx); err != nil {
|
||||
log.Error("LoadReviewer '%d/%d': %v", review.ID, review.ReviewerID, err)
|
||||
return
|
||||
}
|
||||
if err := review.LoadCodeComments(ctx); err != nil {
|
||||
log.Error("LoadCodeComments '%d/%d': %v", review.Reviewer.ID, review.ID, err)
|
||||
return
|
||||
}
|
||||
|
||||
actions := make([]*activities_model.Action, 0, 10)
|
||||
for _, lines := range review.CodeComments {
|
||||
for _, comments := range lines {
|
||||
for _, comm := range comments {
|
||||
actions = append(actions, &activities_model.Action{
|
||||
ActUserID: review.Reviewer.ID,
|
||||
ActUser: review.Reviewer,
|
||||
Content: fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(comm.Content, "\n")[0]),
|
||||
OpType: activities_model.ActionCommentPull,
|
||||
RepoID: review.Issue.RepoID,
|
||||
Repo: review.Issue.Repo,
|
||||
IsPrivate: review.Issue.Repo.IsPrivate,
|
||||
Comment: comm,
|
||||
CommentID: comm.ID,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if review.Type != issues_model.ReviewTypeComment || strings.TrimSpace(comment.Content) != "" {
|
||||
action := &activities_model.Action{
|
||||
ActUserID: review.Reviewer.ID,
|
||||
ActUser: review.Reviewer,
|
||||
Content: fmt.Sprintf("%d|%s", review.Issue.Index, strings.Split(comment.Content, "\n")[0]),
|
||||
RepoID: review.Issue.RepoID,
|
||||
Repo: review.Issue.Repo,
|
||||
IsPrivate: review.Issue.Repo.IsPrivate,
|
||||
Comment: comment,
|
||||
CommentID: comment.ID,
|
||||
}
|
||||
|
||||
switch review.Type {
|
||||
case issues_model.ReviewTypeApprove:
|
||||
action.OpType = activities_model.ActionApprovePullRequest
|
||||
case issues_model.ReviewTypeReject:
|
||||
action.OpType = activities_model.ActionRejectPullRequest
|
||||
default:
|
||||
action.OpType = activities_model.ActionCommentPull
|
||||
}
|
||||
|
||||
actions = append(actions, action)
|
||||
}
|
||||
|
||||
if err := activities_model.NotifyWatchersActions(actions); err != nil {
|
||||
log.Error("notify watchers '%d/%d': %v", review.Reviewer.ID, review.Issue.RepoID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (*actionNotifier) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionMergePullRequest,
|
||||
Content: fmt.Sprintf("%d|%s", pr.Issue.Index, pr.Issue.Title),
|
||||
RepoID: pr.Issue.Repo.ID,
|
||||
Repo: pr.Issue.Repo,
|
||||
IsPrivate: pr.Issue.Repo.IsPrivate,
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers [%d]: %v", pr.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (*actionNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionAutoMergePullRequest,
|
||||
Content: fmt.Sprintf("%d|%s", pr.Issue.Index, pr.Issue.Title),
|
||||
RepoID: pr.Issue.Repo.ID,
|
||||
Repo: pr.Issue.Repo,
|
||||
IsPrivate: pr.Issue.Repo.IsPrivate,
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers [%d]: %v", pr.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (*actionNotifier) NotifyPullRevieweDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
|
||||
reviewerName := review.Reviewer.Name
|
||||
if len(review.OriginalAuthor) > 0 {
|
||||
reviewerName = review.OriginalAuthor
|
||||
}
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: activities_model.ActionPullReviewDismissed,
|
||||
Content: fmt.Sprintf("%d|%s|%s", review.Issue.Index, reviewerName, comment.Content),
|
||||
RepoID: review.Issue.Repo.ID,
|
||||
Repo: review.Issue.Repo,
|
||||
IsPrivate: review.Issue.Repo.IsPrivate,
|
||||
CommentID: comment.ID,
|
||||
Comment: comment,
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers [%d]: %v", review.Issue.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
data, err := json.Marshal(commits)
|
||||
if err != nil {
|
||||
log.Error("Marshal: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
opType := activities_model.ActionCommitRepo
|
||||
|
||||
// Check it's tag push or branch.
|
||||
if opts.RefFullName.IsTag() {
|
||||
opType = activities_model.ActionPushTag
|
||||
if opts.IsDelRef() {
|
||||
opType = activities_model.ActionDeleteTag
|
||||
}
|
||||
} else if opts.IsDelRef() {
|
||||
opType = activities_model.ActionDeleteBranch
|
||||
}
|
||||
|
||||
if err = activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: pusher.ID,
|
||||
ActUser: pusher,
|
||||
OpType: opType,
|
||||
Content: string(data),
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
RefName: opts.RefFullName.String(),
|
||||
IsPrivate: repo.IsPrivate,
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) CreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
opType := activities_model.ActionCommitRepo
|
||||
if refFullName.IsTag() {
|
||||
// has sent same action in `PushCommits`, so skip it.
|
||||
return
|
||||
}
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: opType,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
RefName: refFullName.String(),
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) DeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
opType := activities_model.ActionDeleteBranch
|
||||
if refFullName.IsTag() {
|
||||
// has sent same action in `PushCommits`, so skip it.
|
||||
return
|
||||
}
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: doer.ID,
|
||||
ActUser: doer,
|
||||
OpType: opType,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
RefName: refFullName.String(),
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
data, err := json.Marshal(commits)
|
||||
if err != nil {
|
||||
log.Error("json.Marshal: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: repo.OwnerID,
|
||||
ActUser: repo.MustOwner(ctx),
|
||||
OpType: activities_model.ActionMirrorSyncPush,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
RefName: opts.RefFullName.String(),
|
||||
Content: string(data),
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) SyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: repo.OwnerID,
|
||||
ActUser: repo.MustOwner(ctx),
|
||||
OpType: activities_model.ActionMirrorSyncCreate,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
RefName: refFullName.String(),
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) SyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: repo.OwnerID,
|
||||
ActUser: repo.MustOwner(ctx),
|
||||
OpType: activities_model.ActionMirrorSyncDelete,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
RefName: refFullName.String(),
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *actionNotifier) NewRelease(ctx context.Context, rel *repo_model.Release) {
|
||||
if err := rel.LoadAttributes(ctx); err != nil {
|
||||
log.Error("LoadAttributes: %v", err)
|
||||
return
|
||||
}
|
||||
if err := activities_model.NotifyWatchers(ctx, &activities_model.Action{
|
||||
ActUserID: rel.PublisherID,
|
||||
ActUser: rel.Publisher,
|
||||
OpType: activities_model.ActionPublishRelease,
|
||||
RepoID: rel.RepoID,
|
||||
Repo: rel.Repo,
|
||||
IsPrivate: rel.Repo.IsPrivate,
|
||||
Content: rel.Title,
|
||||
RefName: rel.TagName, // FIXME: use a full ref name?
|
||||
}); err != nil {
|
||||
log.Error("NotifyWatchers: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package feed
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.MainTest(m, &unittest.TestOptions{
|
||||
GiteaRootPath: filepath.Join("..", ".."),
|
||||
})
|
||||
}
|
||||
|
||||
func TestRenameRepoAction(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID})
|
||||
repo.Owner = user
|
||||
|
||||
oldRepoName := repo.Name
|
||||
const newRepoName = "newRepoName"
|
||||
repo.Name = newRepoName
|
||||
repo.LowerName = strings.ToLower(newRepoName)
|
||||
|
||||
actionBean := &activities_model.Action{
|
||||
OpType: activities_model.ActionRenameRepo,
|
||||
ActUserID: user.ID,
|
||||
ActUser: user,
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
IsPrivate: repo.IsPrivate,
|
||||
Content: oldRepoName,
|
||||
}
|
||||
unittest.AssertNotExistsBean(t, actionBean)
|
||||
|
||||
NewNotifier().RenameRepository(db.DefaultContext, user, repo, oldRepoName)
|
||||
|
||||
unittest.AssertExistsAndLoadBean(t, actionBean)
|
||||
unittest.CheckConsistencyFor(t, &activities_model.Action{})
|
||||
}
|
||||
@@ -7,8 +7,6 @@ import (
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -396,7 +394,7 @@ func tryMapColumnsByContent(baseCSVReader *csvReader, base2HeadColMap []int, hea
|
||||
headStart := 0
|
||||
for base2HeadColMap[i] == unmappedColumn && headStart < len(head2BaseColMap) {
|
||||
if head2BaseColMap[headStart] == unmappedColumn {
|
||||
rows := util.Min(maxRowsToInspect, util.Max(0, util.Min(len(baseCSVReader.buffer), len(headCSVReader.buffer))-1))
|
||||
rows := min(maxRowsToInspect, max(0, min(len(baseCSVReader.buffer), len(headCSVReader.buffer))-1))
|
||||
same := 0
|
||||
for j := 1; j <= rows; j++ {
|
||||
baseCell, baseErr := getCell(baseCSVReader.buffer[j], i)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package indexer
|
||||
|
||||
import (
|
||||
code_indexer "code.gitea.io/gitea/modules/indexer/code"
|
||||
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
|
||||
stats_indexer "code.gitea.io/gitea/modules/indexer/stats"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// Init initialize the repo indexer
|
||||
func Init() error {
|
||||
notify_service.RegisterNotifier(NewNotifier())
|
||||
|
||||
issue_indexer.InitIssueIndexer(false)
|
||||
code_indexer.Init()
|
||||
return stats_indexer.Init()
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package indexer
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
code_indexer "code.gitea.io/gitea/modules/indexer/code"
|
||||
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
|
||||
stats_indexer "code.gitea.io/gitea/modules/indexer/stats"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
type indexerNotifier struct {
|
||||
notify_service.NullNotifier
|
||||
}
|
||||
|
||||
var _ notify_service.Notifier = &indexerNotifier{}
|
||||
|
||||
// NewNotifier create a new indexerNotifier notifier
|
||||
func NewNotifier() notify_service.Notifier {
|
||||
return &indexerNotifier{}
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) AdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
r.MigrateRepository(ctx, doer, u, repo)
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
||||
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
|
||||
) {
|
||||
issue_indexer.UpdateIssueIndexer(issue.ID)
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
|
||||
issue_indexer.UpdateIssueIndexer(issue.ID)
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
log.Error("LoadIssue: %v", err)
|
||||
return
|
||||
}
|
||||
issue_indexer.UpdateIssueIndexer(pr.Issue.ID)
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
|
||||
if err := c.LoadIssue(ctx); err != nil {
|
||||
log.Error("LoadIssue: %v", err)
|
||||
return
|
||||
}
|
||||
issue_indexer.UpdateIssueIndexer(c.Issue.ID)
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) {
|
||||
if err := comment.LoadIssue(ctx); err != nil {
|
||||
log.Error("LoadIssue: %v", err)
|
||||
return
|
||||
}
|
||||
issue_indexer.UpdateIssueIndexer(comment.Issue.ID)
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) {
|
||||
issue_indexer.DeleteRepoIssueIndexer(ctx, repo.ID)
|
||||
if setting.Indexer.RepoIndexerEnabled {
|
||||
code_indexer.UpdateRepoIndexer(repo)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
issue_indexer.UpdateRepoIndexer(ctx, repo.ID)
|
||||
if setting.Indexer.RepoIndexerEnabled && !repo.IsEmpty {
|
||||
code_indexer.UpdateRepoIndexer(repo)
|
||||
}
|
||||
if err := stats_indexer.UpdateRepoIndexer(repo); err != nil {
|
||||
log.Error("stats_indexer.UpdateRepoIndexer(%d) failed: %v", repo.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
if !opts.RefFullName.IsBranch() {
|
||||
return
|
||||
}
|
||||
|
||||
if setting.Indexer.RepoIndexerEnabled && opts.RefFullName.BranchName() == repo.DefaultBranch {
|
||||
code_indexer.UpdateRepoIndexer(repo)
|
||||
}
|
||||
if err := stats_indexer.UpdateRepoIndexer(repo); err != nil {
|
||||
log.Error("stats_indexer.UpdateRepoIndexer(%d) failed: %v", repo.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
if !opts.RefFullName.IsBranch() {
|
||||
return
|
||||
}
|
||||
|
||||
if setting.Indexer.RepoIndexerEnabled && opts.RefFullName.BranchName() == repo.DefaultBranch {
|
||||
code_indexer.UpdateRepoIndexer(repo)
|
||||
}
|
||||
if err := stats_indexer.UpdateRepoIndexer(repo); err != nil {
|
||||
log.Error("stats_indexer.UpdateRepoIndexer(%d) failed: %v", repo.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) {
|
||||
issue_indexer.UpdateIssueIndexer(issue.ID)
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
|
||||
issue_indexer.UpdateIssueIndexer(issue.ID)
|
||||
}
|
||||
|
||||
func (r *indexerNotifier) IssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) {
|
||||
issue_indexer.UpdateIssueIndexer(issue.ID)
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// DeleteNotPassedAssignee deletes all assignees who aren't passed via the "assignees" array
|
||||
@@ -54,7 +54,7 @@ func ToggleAssigneeWithNotify(ctx context.Context, issue *issues_model.Issue, do
|
||||
return false, nil, err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeAssignee(ctx, doer, issue, assignee, removed, comment)
|
||||
notify_service.IssueChangeAssignee(ctx, doer, issue, assignee, removed, comment)
|
||||
|
||||
return removed, comment, err
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func ReviewRequest(ctx context.Context, issue *issues_model.Issue, doer, reviewe
|
||||
}
|
||||
|
||||
if comment != nil {
|
||||
notification.NotifyPullRequestReviewRequest(ctx, doer, issue, reviewer, isAdd, comment)
|
||||
notify_service.PullRequestReviewRequest(ctx, doer, issue, reviewer, isAdd, comment)
|
||||
}
|
||||
|
||||
return comment, err
|
||||
@@ -259,7 +259,7 @@ func TeamReviewRequest(ctx context.Context, issue *issues_model.Issue, doer *use
|
||||
continue
|
||||
}
|
||||
comment.AssigneeID = member.ID
|
||||
notification.NotifyPullRequestReviewRequest(ctx, doer, issue, member, isAdd, comment)
|
||||
notify_service.PullRequestReviewRequest(ctx, doer, issue, member, isAdd, comment)
|
||||
}
|
||||
|
||||
return comment, err
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// CreateRefComment creates a commit reference comment to issue.
|
||||
@@ -63,7 +63,7 @@ func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_m
|
||||
return nil, err
|
||||
}
|
||||
|
||||
notification.NotifyCreateIssueComment(ctx, doer, repo, issue, comment, mentions)
|
||||
notify_service.CreateIssueComment(ctx, doer, repo, issue, comment, mentions)
|
||||
|
||||
return comment, nil
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, doer *user_mode
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyUpdateComment(ctx, doer, c, oldContent)
|
||||
notify_service.UpdateComment(ctx, doer, c, oldContent)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -109,7 +109,7 @@ func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_m
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyDeleteComment(ctx, doer, comment)
|
||||
notify_service.DeleteComment(ctx, doer, comment)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// ChangeContent changes issue content, as the given user.
|
||||
@@ -18,7 +18,7 @@ func ChangeContent(issue *issues_model.Issue, doer *user_model.User, content str
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeContent(db.DefaultContext, doer, issue, oldContent)
|
||||
notify_service.IssueChangeContent(db.DefaultContext, doer, issue, oldContent)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ import (
|
||||
system_model "code.gitea.io/gitea/models/system"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/storage"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// NewIssue creates new issue with labels for repository.
|
||||
@@ -37,12 +37,12 @@ func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *issues_mo
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyNewIssue(ctx, issue, mentions)
|
||||
notify_service.NewIssue(ctx, issue, mentions)
|
||||
if len(issue.Labels) > 0 {
|
||||
notification.NotifyIssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil)
|
||||
notify_service.IssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil)
|
||||
}
|
||||
if issue.Milestone != nil {
|
||||
notification.NotifyIssueChangeMilestone(ctx, issue.Poster, issue, 0)
|
||||
notify_service.IssueChangeMilestone(ctx, issue.Poster, issue, 0)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -63,7 +63,7 @@ func ChangeTitle(ctx context.Context, issue *issues_model.Issue, doer *user_mode
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeTitle(ctx, doer, issue, oldTitle)
|
||||
notify_service.IssueChangeTitle(ctx, doer, issue, oldTitle)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func ChangeIssueRef(ctx context.Context, issue *issues_model.Issue, doer *user_m
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeRef(ctx, doer, issue, oldRef)
|
||||
notify_service.IssueChangeRef(ctx, doer, issue, oldRef)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func DeleteIssue(ctx context.Context, doer *user_model.User, gitRepo *git.Reposi
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyDeleteIssue(ctx, doer, issue)
|
||||
notify_service.DeleteIssue(ctx, doer, issue)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
access_model "code.gitea.io/gitea/models/perm/access"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// ClearLabels clears all of an issue's labels
|
||||
@@ -17,7 +17,7 @@ func ClearLabels(issue *issues_model.Issue, doer *user_model.User) error {
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueClearLabels(db.DefaultContext, doer, issue)
|
||||
notify_service.IssueClearLabels(db.DefaultContext, doer, issue)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -28,7 +28,7 @@ func AddLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_mo
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, []*issues_model.Label{label}, nil)
|
||||
notify_service.IssueChangeLabels(db.DefaultContext, doer, issue, []*issues_model.Label{label}, nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func AddLabels(issue *issues_model.Issue, doer *user_model.User, labels []*issue
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, labels, nil)
|
||||
notify_service.IssueChangeLabels(db.DefaultContext, doer, issue, labels, nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, nil, []*issues_model.Label{label})
|
||||
notify_service.IssueChangeLabels(db.DefaultContext, doer, issue, nil, []*issues_model.Label{label})
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -88,6 +88,6 @@ func ReplaceLabels(issue *issues_model.Issue, doer *user_model.User, labels []*i
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, labels, old)
|
||||
notify_service.IssueChangeLabels(db.DefaultContext, doer, issue, labels, old)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) error {
|
||||
@@ -78,7 +78,7 @@ func ChangeMilestoneAssign(issue *issues_model.Issue, doer *user_model.User, old
|
||||
return fmt.Errorf("Commit: %w", err)
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeMilestone(db.DefaultContext, doer, issue, oldMilestoneID)
|
||||
notify_service.IssueChangeMilestone(db.DefaultContext, doer, issue, oldMilestoneID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// ChangeStatus changes issue status to open or closed.
|
||||
@@ -30,7 +30,7 @@ func ChangeStatus(ctx context.Context, issue *issues_model.Issue, doer *user_mod
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeStatus(ctx, doer, commitID, issue, comment, closed)
|
||||
notify_service.IssueChangeStatus(ctx, doer, commitID, issue, comment, closed)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ package mailer
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
org_model "code.gitea.io/gitea/models/organization"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -33,6 +35,22 @@ func MailTeamInvite(ctx context.Context, inviter *user_model.User, team *org_mod
|
||||
|
||||
locale := translation.NewLocale(inviter.Language)
|
||||
|
||||
// check if a user with this email already exists
|
||||
user, err := user_model.GetUserByEmail(ctx, invite.Email)
|
||||
if err != nil && !user_model.IsErrUserNotExist(err) {
|
||||
return err
|
||||
} else if user != nil && user.ProhibitLogin {
|
||||
return fmt.Errorf("login is prohibited for the invited user")
|
||||
}
|
||||
|
||||
inviteRedirect := url.QueryEscape(fmt.Sprintf("/org/invite/%s", invite.Token))
|
||||
inviteURL := fmt.Sprintf("%suser/sign_up?redirect_to=%s", setting.AppURL, inviteRedirect)
|
||||
|
||||
if err == nil && user != nil {
|
||||
// user account exists
|
||||
inviteURL = fmt.Sprintf("%suser/login?redirect_to=%s", setting.AppURL, inviteRedirect)
|
||||
}
|
||||
|
||||
subject := locale.Tr("mail.team_invite.subject", inviter.DisplayName(), org.DisplayName())
|
||||
mailMeta := map[string]any{
|
||||
"Inviter": inviter,
|
||||
@@ -40,6 +58,7 @@ func MailTeamInvite(ctx context.Context, inviter *user_model.User, team *org_mod
|
||||
"Team": team,
|
||||
"Invite": invite,
|
||||
"Subject": subject,
|
||||
"InviteURL": inviteURL,
|
||||
// helper
|
||||
"locale": locale,
|
||||
"Str2html": templates.Str2html,
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/queue"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/templates"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
|
||||
ntlmssp "github.com/Azure/go-ntlmssp"
|
||||
"github.com/jaytaylor/html2text"
|
||||
@@ -392,6 +393,10 @@ func NewContext(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if setting.Service.EnableNotifyMail {
|
||||
notify_service.RegisterNotifier(NewNotifier())
|
||||
}
|
||||
|
||||
switch setting.MailService.Protocol {
|
||||
case "sendmail":
|
||||
Sender = &sendmailSender{}
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package mailer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
type mailNotifier struct {
|
||||
notify_service.NullNotifier
|
||||
}
|
||||
|
||||
var _ notify_service.Notifier = &mailNotifier{}
|
||||
|
||||
// NewNotifier create a new mailNotifier notifier
|
||||
func NewNotifier() notify_service.Notifier {
|
||||
return &mailNotifier{}
|
||||
}
|
||||
|
||||
func (m *mailNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
||||
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
|
||||
) {
|
||||
var act activities_model.ActionType
|
||||
if comment.Type == issues_model.CommentTypeClose {
|
||||
act = activities_model.ActionCloseIssue
|
||||
} else if comment.Type == issues_model.CommentTypeReopen {
|
||||
act = activities_model.ActionReopenIssue
|
||||
} else if comment.Type == issues_model.CommentTypeComment {
|
||||
act = activities_model.ActionCommentIssue
|
||||
} else if comment.Type == issues_model.CommentTypeCode {
|
||||
act = activities_model.ActionCommentIssue
|
||||
} else if comment.Type == issues_model.CommentTypePullRequestPush {
|
||||
act = 0
|
||||
}
|
||||
|
||||
if err := MailParticipantsComment(ctx, comment, act, issue, mentions); err != nil {
|
||||
log.Error("MailParticipantsComment: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mailNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
|
||||
if err := MailParticipants(ctx, issue, issue.Poster, activities_model.ActionCreateIssue, mentions); err != nil {
|
||||
log.Error("MailParticipants: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mailNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
|
||||
var actionType activities_model.ActionType
|
||||
if issue.IsPull {
|
||||
if isClosed {
|
||||
actionType = activities_model.ActionClosePullRequest
|
||||
} else {
|
||||
actionType = activities_model.ActionReopenPullRequest
|
||||
}
|
||||
} else {
|
||||
if isClosed {
|
||||
actionType = activities_model.ActionCloseIssue
|
||||
} else {
|
||||
actionType = activities_model.ActionReopenIssue
|
||||
}
|
||||
}
|
||||
|
||||
if err := MailParticipants(ctx, issue, doer, actionType, nil); err != nil {
|
||||
log.Error("MailParticipants: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mailNotifier) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
|
||||
if err := issue.LoadPullRequest(ctx); err != nil {
|
||||
log.Error("issue.LoadPullRequest: %v", err)
|
||||
return
|
||||
}
|
||||
if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issue.PullRequest.IsWorkInProgress() {
|
||||
if err := MailParticipants(ctx, issue, doer, activities_model.ActionPullRequestReadyForReview, nil); err != nil {
|
||||
log.Error("MailParticipants: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mailNotifier) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
|
||||
if err := MailParticipants(ctx, pr.Issue, pr.Issue.Poster, activities_model.ActionCreatePullRequest, mentions); err != nil {
|
||||
log.Error("MailParticipants: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mailNotifier) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, r *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
|
||||
var act activities_model.ActionType
|
||||
if comment.Type == issues_model.CommentTypeClose {
|
||||
act = activities_model.ActionCloseIssue
|
||||
} else if comment.Type == issues_model.CommentTypeReopen {
|
||||
act = activities_model.ActionReopenIssue
|
||||
} else if comment.Type == issues_model.CommentTypeComment {
|
||||
act = activities_model.ActionCommentPull
|
||||
}
|
||||
if err := MailParticipantsComment(ctx, comment, act, pr.Issue, mentions); err != nil {
|
||||
log.Error("MailParticipantsComment: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mailNotifier) PullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) {
|
||||
if err := MailMentionsComment(ctx, pr, comment, mentions); err != nil {
|
||||
log.Error("MailMentionsComment: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mailNotifier) IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
|
||||
// mail only sent to added assignees and not self-assignee
|
||||
if !removed && doer.ID != assignee.ID && assignee.EmailNotifications() != user_model.EmailNotificationsDisabled {
|
||||
ct := fmt.Sprintf("Assigned #%d.", issue.Index)
|
||||
if err := SendIssueAssignedMail(ctx, 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) PullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
|
||||
if isRequest && doer.ID != reviewer.ID && reviewer.EmailNotifications() != user_model.EmailNotificationsDisabled {
|
||||
ct := fmt.Sprintf("Requested to review %s.", issue.HTMLURL())
|
||||
if err := SendIssueAssignedMail(ctx, 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) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
log.Error("LoadIssue: %v", err)
|
||||
return
|
||||
}
|
||||
if err := MailParticipants(ctx, pr.Issue, doer, activities_model.ActionMergePullRequest, nil); err != nil {
|
||||
log.Error("MailParticipants: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mailNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
log.Error("pr.LoadIssue: %v", err)
|
||||
return
|
||||
}
|
||||
if err := MailParticipants(ctx, pr.Issue, doer, activities_model.ActionAutoMergePullRequest, nil); err != nil {
|
||||
log.Error("MailParticipants: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mailNotifier) PullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
|
||||
var err error
|
||||
if err = comment.LoadIssue(ctx); err != nil {
|
||||
log.Error("comment.LoadIssue: %v", err)
|
||||
return
|
||||
}
|
||||
if err = comment.Issue.LoadRepo(ctx); err != nil {
|
||||
log.Error("comment.Issue.LoadRepo: %v", err)
|
||||
return
|
||||
}
|
||||
if err = comment.Issue.LoadPullRequest(ctx); err != nil {
|
||||
log.Error("comment.Issue.LoadPullRequest: %v", err)
|
||||
return
|
||||
}
|
||||
if err = comment.Issue.PullRequest.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("comment.Issue.PullRequest.LoadBaseRepo: %v", err)
|
||||
return
|
||||
}
|
||||
if err := comment.LoadPushCommits(ctx); err != nil {
|
||||
log.Error("comment.LoadPushCommits: %v", err)
|
||||
}
|
||||
m.CreateIssueComment(ctx, doer, comment.Issue.Repo, comment.Issue, comment, nil)
|
||||
}
|
||||
|
||||
func (m *mailNotifier) PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
|
||||
if err := MailParticipantsComment(ctx, comment, activities_model.ActionPullReviewDismissed, review.Issue, nil); err != nil {
|
||||
log.Error("MailParticipantsComment: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mailNotifier) NewRelease(ctx context.Context, rel *repo_model.Release) {
|
||||
if err := rel.LoadAttributes(ctx); err != nil {
|
||||
log.Error("LoadAttributes: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if rel.IsDraft || rel.IsPrerelease {
|
||||
return
|
||||
}
|
||||
|
||||
MailNewRelease(ctx, rel)
|
||||
}
|
||||
|
||||
func (m *mailNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) {
|
||||
if err := SendRepoTransferNotifyMail(ctx, doer, newOwner, repo); err != nil {
|
||||
log.Error("SendRepoTransferNotifyMail: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/models/user"
|
||||
gitea_context "code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/contexttest"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -42,7 +42,7 @@ func TestProcessorHelper(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
base, baseCleanUp := gitea_context.NewBaseContext(httptest.NewRecorder(), req)
|
||||
defer baseCleanUp()
|
||||
giteaCtx := gitea_context.NewWebContext(base, &test.MockRender{}, nil)
|
||||
giteaCtx := gitea_context.NewWebContext(base, &contexttest.MockRender{}, nil)
|
||||
|
||||
assert.True(t, ProcessorHelper().IsUsernameMentionable(giteaCtx, userPublic))
|
||||
assert.False(t, ProcessorHelper().IsUsernameMentionable(giteaCtx, userPrivate))
|
||||
|
||||
@@ -16,13 +16,13 @@ import (
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/lfs"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/process"
|
||||
"code.gitea.io/gitea/modules/proxy"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// gitShortEmptySha Git short empty SHA
|
||||
@@ -479,18 +479,18 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
||||
log.Error("SyncMirrors [repo: %-v]: unable to GetRefCommitID [ref_name: %s]: %v", m.Repo, result.refName, err)
|
||||
continue
|
||||
}
|
||||
notification.NotifySyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{
|
||||
notify_service.SyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{
|
||||
RefFullName: result.refName,
|
||||
OldCommitID: git.EmptySHA,
|
||||
NewCommitID: commitID,
|
||||
}, repo_module.NewPushCommits())
|
||||
notification.NotifySyncCreateRef(ctx, m.Repo.MustOwner(ctx), m.Repo, result.refName, commitID)
|
||||
notify_service.SyncCreateRef(ctx, m.Repo.MustOwner(ctx), m.Repo, result.refName, commitID)
|
||||
continue
|
||||
}
|
||||
|
||||
// Delete reference
|
||||
if result.newCommitID == gitShortEmptySha {
|
||||
notification.NotifySyncDeleteRef(ctx, m.Repo.MustOwner(ctx), m.Repo, result.refName)
|
||||
notify_service.SyncDeleteRef(ctx, m.Repo.MustOwner(ctx), m.Repo, result.refName)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -525,7 +525,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
||||
|
||||
theCommits.CompareURL = m.Repo.ComposeCompareURL(oldCommitID, newCommitID)
|
||||
|
||||
notification.NotifySyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{
|
||||
notify_service.SyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{
|
||||
RefFullName: result.refName,
|
||||
OldCommitID: oldCommitID,
|
||||
NewCommitID: newCommitID,
|
||||
|
||||
@@ -8,25 +8,24 @@ import (
|
||||
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/notification/base"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
func init() {
|
||||
notification.RegisterNotifier(&mirrorNotifier{})
|
||||
notify_service.RegisterNotifier(&mirrorNotifier{})
|
||||
}
|
||||
|
||||
type mirrorNotifier struct {
|
||||
base.NullNotifier
|
||||
notify_service.NullNotifier
|
||||
}
|
||||
|
||||
var _ base.Notifier = &mirrorNotifier{}
|
||||
var _ notify_service.Notifier = &mirrorNotifier{}
|
||||
|
||||
func (m *mirrorNotifier) NotifyPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) {
|
||||
func (m *mirrorNotifier) PushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) {
|
||||
syncPushMirrorWithSyncOnCommit(ctx, repo.ID)
|
||||
}
|
||||
|
||||
func (m *mirrorNotifier) NotifySyncPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) {
|
||||
func (m *mirrorNotifier) SyncPushCommits(ctx context.Context, _ *user_model.User, repo *repo_model.Repository, _ *repository.PushUpdateOptions, _ *repository.PushCommits) {
|
||||
syncPushMirrorWithSyncOnCommit(ctx, repo.ID)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package notify
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
)
|
||||
|
||||
// Notifier defines an interface to notify receiver
|
||||
type Notifier interface {
|
||||
Run()
|
||||
|
||||
AdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository)
|
||||
CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository)
|
||||
MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository)
|
||||
DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository)
|
||||
ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository)
|
||||
RenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string)
|
||||
TransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string)
|
||||
RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository)
|
||||
|
||||
NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User)
|
||||
IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool)
|
||||
DeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue)
|
||||
IssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64)
|
||||
IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment)
|
||||
PullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment)
|
||||
IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string)
|
||||
IssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue)
|
||||
IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string)
|
||||
IssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string)
|
||||
IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
|
||||
addedLabels, removedLabels []*issues_model.Label)
|
||||
|
||||
NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User)
|
||||
MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest)
|
||||
AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest)
|
||||
PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest)
|
||||
PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User)
|
||||
PullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User)
|
||||
PullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string)
|
||||
PullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment)
|
||||
PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment)
|
||||
|
||||
CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
||||
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User)
|
||||
UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string)
|
||||
DeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment)
|
||||
|
||||
NewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string)
|
||||
EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string)
|
||||
DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string)
|
||||
|
||||
NewRelease(ctx context.Context, rel *repo_model.Release)
|
||||
UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release)
|
||||
DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release)
|
||||
|
||||
PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits)
|
||||
CreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string)
|
||||
DeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName)
|
||||
SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits)
|
||||
SyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string)
|
||||
SyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName)
|
||||
|
||||
PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor)
|
||||
PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor)
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package notify
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
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"
|
||||
)
|
||||
|
||||
var notifiers []Notifier
|
||||
|
||||
// RegisterNotifier providers method to receive notify messages
|
||||
func RegisterNotifier(notifier Notifier) {
|
||||
go notifier.Run()
|
||||
notifiers = append(notifiers, notifier)
|
||||
}
|
||||
|
||||
// NewWikiPage notifies creating new wiki pages to notifiers
|
||||
func NewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.NewWikiPage(ctx, doer, repo, page, comment)
|
||||
}
|
||||
}
|
||||
|
||||
// EditWikiPage notifies editing or renaming wiki pages to notifiers
|
||||
func EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.EditWikiPage(ctx, doer, repo, page, comment)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteWikiPage notifies deleting wiki pages to notifiers
|
||||
func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.DeleteWikiPage(ctx, doer, repo, page)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateIssueComment notifies issue comment related message to notifiers
|
||||
func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
||||
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
|
||||
) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.CreateIssueComment(ctx, doer, repo, issue, comment, mentions)
|
||||
}
|
||||
}
|
||||
|
||||
// NewIssue notifies new issue to notifiers
|
||||
func NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.NewIssue(ctx, issue, mentions)
|
||||
}
|
||||
}
|
||||
|
||||
// IssueChangeStatus notifies close or reopen issue to notifiers
|
||||
func IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, closeOrReopen bool) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.IssueChangeStatus(ctx, doer, commitID, issue, actionComment, closeOrReopen)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteIssue notify when some issue deleted
|
||||
func DeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.DeleteIssue(ctx, doer, issue)
|
||||
}
|
||||
}
|
||||
|
||||
// MergePullRequest notifies merge pull request to notifiers
|
||||
func MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.MergePullRequest(ctx, doer, pr)
|
||||
}
|
||||
}
|
||||
|
||||
// AutoMergePullRequest notifies merge pull request to notifiers
|
||||
func AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.AutoMergePullRequest(ctx, doer, pr)
|
||||
}
|
||||
}
|
||||
|
||||
// NewPullRequest notifies new pull request to notifiers
|
||||
func NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
log.Error("%v", err)
|
||||
return
|
||||
}
|
||||
if err := pr.Issue.LoadPoster(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
for _, notifier := range notifiers {
|
||||
notifier.NewPullRequest(ctx, pr, mentions)
|
||||
}
|
||||
}
|
||||
|
||||
// PullRequestSynchronized notifies Synchronized pull request
|
||||
func PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.PullRequestSynchronized(ctx, doer, pr)
|
||||
}
|
||||
}
|
||||
|
||||
// PullRequestReview notifies new pull request review
|
||||
func PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
|
||||
if err := review.LoadReviewer(ctx); err != nil {
|
||||
log.Error("%v", err)
|
||||
return
|
||||
}
|
||||
for _, notifier := range notifiers {
|
||||
notifier.PullRequestReview(ctx, pr, review, comment, mentions)
|
||||
}
|
||||
}
|
||||
|
||||
// PullRequestCodeComment notifies new pull request code comment
|
||||
func PullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) {
|
||||
if err := comment.LoadPoster(ctx); err != nil {
|
||||
log.Error("LoadPoster: %v", err)
|
||||
return
|
||||
}
|
||||
for _, notifier := range notifiers {
|
||||
notifier.PullRequestCodeComment(ctx, pr, comment, mentions)
|
||||
}
|
||||
}
|
||||
|
||||
// PullRequestChangeTargetBranch notifies when a pull request's target branch was changed
|
||||
func PullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.PullRequestChangeTargetBranch(ctx, doer, pr, oldBranch)
|
||||
}
|
||||
}
|
||||
|
||||
// PullRequestPushCommits notifies when push commits to pull request's head branch
|
||||
func PullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.PullRequestPushCommits(ctx, doer, pr, comment)
|
||||
}
|
||||
}
|
||||
|
||||
// PullReviewDismiss notifies when a review was dismissed by repo admin
|
||||
func PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.PullReviewDismiss(ctx, doer, review, comment)
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateComment notifies update comment to notifiers
|
||||
func UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.UpdateComment(ctx, doer, c, oldContent)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteComment notifies delete comment to notifiers
|
||||
func DeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.DeleteComment(ctx, doer, c)
|
||||
}
|
||||
}
|
||||
|
||||
// NewRelease notifies new release to notifiers
|
||||
func NewRelease(ctx context.Context, rel *repo_model.Release) {
|
||||
if err := rel.LoadAttributes(ctx); err != nil {
|
||||
log.Error("LoadPublisher: %v", err)
|
||||
return
|
||||
}
|
||||
for _, notifier := range notifiers {
|
||||
notifier.NewRelease(ctx, rel)
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateRelease notifies update release to notifiers
|
||||
func UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.UpdateRelease(ctx, doer, rel)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteRelease notifies delete release to notifiers
|
||||
func DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.DeleteRelease(ctx, doer, rel)
|
||||
}
|
||||
}
|
||||
|
||||
// IssueChangeMilestone notifies change milestone to notifiers
|
||||
func IssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.IssueChangeMilestone(ctx, doer, issue, oldMilestoneID)
|
||||
}
|
||||
}
|
||||
|
||||
// IssueChangeContent notifies change content to notifiers
|
||||
func IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.IssueChangeContent(ctx, doer, issue, oldContent)
|
||||
}
|
||||
}
|
||||
|
||||
// IssueChangeAssignee notifies change content to notifiers
|
||||
func IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.IssueChangeAssignee(ctx, doer, issue, assignee, removed, comment)
|
||||
}
|
||||
}
|
||||
|
||||
// PullRequestReviewRequest notifies Request Review change
|
||||
func PullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.PullRequestReviewRequest(ctx, doer, issue, reviewer, isRequest, comment)
|
||||
}
|
||||
}
|
||||
|
||||
// IssueClearLabels notifies clear labels to notifiers
|
||||
func IssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.IssueClearLabels(ctx, doer, issue)
|
||||
}
|
||||
}
|
||||
|
||||
// IssueChangeTitle notifies change title to notifiers
|
||||
func IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.IssueChangeTitle(ctx, doer, issue, oldTitle)
|
||||
}
|
||||
}
|
||||
|
||||
// IssueChangeRef notifies change reference to notifiers
|
||||
func IssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldRef string) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.IssueChangeRef(ctx, doer, issue, oldRef)
|
||||
}
|
||||
}
|
||||
|
||||
// IssueChangeLabels notifies change labels to notifiers
|
||||
func IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
|
||||
addedLabels, removedLabels []*issues_model.Label,
|
||||
) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.IssueChangeLabels(ctx, doer, issue, addedLabels, removedLabels)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateRepository notifies create repository to notifiers
|
||||
func CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.CreateRepository(ctx, doer, u, repo)
|
||||
}
|
||||
}
|
||||
|
||||
// AdoptRepository notifies the adoption of a repository to notifiers
|
||||
func AdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.AdoptRepository(ctx, doer, u, repo)
|
||||
}
|
||||
}
|
||||
|
||||
// MigrateRepository notifies create repository to notifiers
|
||||
func MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.MigrateRepository(ctx, doer, u, repo)
|
||||
}
|
||||
}
|
||||
|
||||
// TransferRepository notifies create repository to notifiers
|
||||
func TransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, newOwnerName string) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.TransferRepository(ctx, doer, repo, newOwnerName)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteRepository notifies delete repository to notifiers
|
||||
func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.DeleteRepository(ctx, doer, repo)
|
||||
}
|
||||
}
|
||||
|
||||
// ForkRepository notifies fork repository to notifiers
|
||||
func ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.ForkRepository(ctx, doer, oldRepo, repo)
|
||||
}
|
||||
}
|
||||
|
||||
// RenameRepository notifies repository renamed
|
||||
func RenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldName string) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.RenameRepository(ctx, doer, repo, oldName)
|
||||
}
|
||||
}
|
||||
|
||||
// PushCommits notifies commits pushed to notifiers
|
||||
func PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.PushCommits(ctx, pusher, repo, opts, commits)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateRef notifies branch or tag creation to notifiers
|
||||
func CreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.CreateRef(ctx, pusher, repo, refFullName, refID)
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteRef notifies branch or tag deletion to notifiers
|
||||
func DeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.DeleteRef(ctx, pusher, repo, refFullName)
|
||||
}
|
||||
}
|
||||
|
||||
// SyncPushCommits notifies commits pushed to notifiers
|
||||
func SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.SyncPushCommits(ctx, pusher, repo, opts, commits)
|
||||
}
|
||||
}
|
||||
|
||||
// SyncCreateRef notifies branch or tag creation to notifiers
|
||||
func SyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.SyncCreateRef(ctx, pusher, repo, refFullName, refID)
|
||||
}
|
||||
}
|
||||
|
||||
// SyncDeleteRef notifies branch or tag deletion to notifiers
|
||||
func SyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.SyncDeleteRef(ctx, pusher, repo, refFullName)
|
||||
}
|
||||
}
|
||||
|
||||
// RepoPendingTransfer notifies creation of pending transfer to notifiers
|
||||
func RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.RepoPendingTransfer(ctx, doer, newOwner, repo)
|
||||
}
|
||||
}
|
||||
|
||||
// PackageCreate notifies creation of a package to notifiers
|
||||
func PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.PackageCreate(ctx, doer, pd)
|
||||
}
|
||||
}
|
||||
|
||||
// PackageDelete notifies deletion of a package to notifiers
|
||||
func PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
||||
for _, notifier := range notifiers {
|
||||
notifier.PackageDelete(ctx, doer, pd)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package notify
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
packages_model "code.gitea.io/gitea/models/packages"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
)
|
||||
|
||||
// NullNotifier implements a blank notifier
|
||||
type NullNotifier struct{}
|
||||
|
||||
var _ Notifier = &NullNotifier{}
|
||||
|
||||
// Run places a place holder function
|
||||
func (*NullNotifier) Run() {
|
||||
}
|
||||
|
||||
// CreateIssueComment places a place holder function
|
||||
func (*NullNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
||||
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User) {
|
||||
}
|
||||
|
||||
// NewIssue places a place holder function
|
||||
func (*NullNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
|
||||
}
|
||||
|
||||
// IssueChangeStatus places a place holder function
|
||||
func (*NullNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
|
||||
}
|
||||
|
||||
// DeleteIssue notify when some issue deleted
|
||||
func (*NullNotifier) DeleteIssue(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) {
|
||||
}
|
||||
|
||||
// NewPullRequest places a place holder function
|
||||
func (*NullNotifier) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
|
||||
}
|
||||
|
||||
// PullRequestReview places a place holder function
|
||||
func (*NullNotifier) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, r *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
|
||||
}
|
||||
|
||||
// PullRequestCodeComment places a place holder function
|
||||
func (*NullNotifier) PullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, comment *issues_model.Comment, mentions []*user_model.User) {
|
||||
}
|
||||
|
||||
// MergePullRequest places a place holder function
|
||||
func (*NullNotifier) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
}
|
||||
|
||||
// AutoMergePullRequest places a place holder function
|
||||
func (*NullNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
}
|
||||
|
||||
// PullRequestSynchronized places a place holder function
|
||||
func (*NullNotifier) PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
}
|
||||
|
||||
// PullRequestChangeTargetBranch places a place holder function
|
||||
func (*NullNotifier) PullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
|
||||
}
|
||||
|
||||
// PullRequestPushCommits notifies when push commits to pull request's head branch
|
||||
func (*NullNotifier) PullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
|
||||
}
|
||||
|
||||
// PullReviewDismiss notifies when a review was dismissed by repo admin
|
||||
func (*NullNotifier) PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
|
||||
}
|
||||
|
||||
// UpdateComment places a place holder function
|
||||
func (*NullNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
|
||||
}
|
||||
|
||||
// DeleteComment places a place holder function
|
||||
func (*NullNotifier) DeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) {
|
||||
}
|
||||
|
||||
// NewWikiPage places a place holder function
|
||||
func (*NullNotifier) NewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
|
||||
}
|
||||
|
||||
// EditWikiPage places a place holder function
|
||||
func (*NullNotifier) EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
|
||||
}
|
||||
|
||||
// DeleteWikiPage places a place holder function
|
||||
func (*NullNotifier) DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
|
||||
}
|
||||
|
||||
// NewRelease places a place holder function
|
||||
func (*NullNotifier) NewRelease(ctx context.Context, rel *repo_model.Release) {
|
||||
}
|
||||
|
||||
// UpdateRelease places a place holder function
|
||||
func (*NullNotifier) UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
||||
}
|
||||
|
||||
// DeleteRelease places a place holder function
|
||||
func (*NullNotifier) DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
||||
}
|
||||
|
||||
// IssueChangeMilestone places a place holder function
|
||||
func (*NullNotifier) IssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) {
|
||||
}
|
||||
|
||||
// IssueChangeContent places a place holder function
|
||||
func (*NullNotifier) IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) {
|
||||
}
|
||||
|
||||
// IssueChangeAssignee places a place holder function
|
||||
func (*NullNotifier) IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
|
||||
}
|
||||
|
||||
// PullRequestReviewRequest places a place holder function
|
||||
func (*NullNotifier) PullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
|
||||
}
|
||||
|
||||
// IssueClearLabels places a place holder function
|
||||
func (*NullNotifier) IssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) {
|
||||
}
|
||||
|
||||
// IssueChangeTitle places a place holder function
|
||||
func (*NullNotifier) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
|
||||
}
|
||||
|
||||
// IssueChangeRef places a place holder function
|
||||
func (*NullNotifier) IssueChangeRef(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
|
||||
}
|
||||
|
||||
// IssueChangeLabels places a place holder function
|
||||
func (*NullNotifier) IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
|
||||
addedLabels, removedLabels []*issues_model.Label) {
|
||||
}
|
||||
|
||||
// CreateRepository places a place holder function
|
||||
func (*NullNotifier) CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
}
|
||||
|
||||
// AdoptRepository places a place holder function
|
||||
func (*NullNotifier) AdoptRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
}
|
||||
|
||||
// DeleteRepository places a place holder function
|
||||
func (*NullNotifier) DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) {
|
||||
}
|
||||
|
||||
// ForkRepository places a place holder function
|
||||
func (*NullNotifier) ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
|
||||
}
|
||||
|
||||
// MigrateRepository places a place holder function
|
||||
func (*NullNotifier) MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
}
|
||||
|
||||
// PushCommits notifies commits pushed to notifiers
|
||||
func (*NullNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
}
|
||||
|
||||
// CreateRef notifies branch or tag creation to notifiers
|
||||
func (*NullNotifier) CreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
}
|
||||
|
||||
// DeleteRef notifies branch or tag deletion to notifiers
|
||||
func (*NullNotifier) DeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
}
|
||||
|
||||
// RenameRepository places a place holder function
|
||||
func (*NullNotifier) RenameRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldRepoName string) {
|
||||
}
|
||||
|
||||
// TransferRepository places a place holder function
|
||||
func (*NullNotifier) TransferRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, oldOwnerName string) {
|
||||
}
|
||||
|
||||
// SyncPushCommits places a place holder function
|
||||
func (*NullNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
}
|
||||
|
||||
// SyncCreateRef places a place holder function
|
||||
func (*NullNotifier) SyncCreateRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
}
|
||||
|
||||
// SyncDeleteRef places a place holder function
|
||||
func (*NullNotifier) SyncDeleteRef(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
}
|
||||
|
||||
// RepoPendingTransfer places a place holder function
|
||||
func (*NullNotifier) RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) {
|
||||
}
|
||||
|
||||
// PackageCreate places a place holder function
|
||||
func (*NullNotifier) PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
||||
}
|
||||
|
||||
// PackageDelete places a place holder function
|
||||
func (*NullNotifier) PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
||||
}
|
||||
@@ -18,11 +18,11 @@ import (
|
||||
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"
|
||||
packages_module "code.gitea.io/gitea/modules/packages"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/storage"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -113,7 +113,7 @@ func createPackageAndAddFile(pvci *PackageCreationInfo, pfci *PackageFileCreatio
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
notification.NotifyPackageCreate(db.DefaultContext, pvci.Creator, pd)
|
||||
notify_service.PackageCreate(db.DefaultContext, pvci.Creator, pd)
|
||||
}
|
||||
|
||||
return pv, pf, nil
|
||||
@@ -489,7 +489,7 @@ func RemovePackageVersion(doer *user_model.User, pv *packages_model.PackageVersi
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyPackageDelete(db.DefaultContext, doer, pd)
|
||||
notify_service.PackageDelete(db.DefaultContext, doer, pd)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -529,7 +529,7 @@ func RemovePackageFileAndVersionIfUnreferenced(doer *user_model.User, pf *packag
|
||||
}
|
||||
|
||||
if pd != nil {
|
||||
notification.NotifyPackageDelete(db.DefaultContext, doer, pd)
|
||||
notify_service.PackageDelete(db.DefaultContext, doer, pd)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -22,11 +22,11 @@ import (
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/process"
|
||||
"code.gitea.io/gitea/modules/queue"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
asymkey_service "code.gitea.io/gitea/services/asymkey"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// prPatchCheckerQueue represents a queue to handle update pull request tests
|
||||
@@ -295,7 +295,7 @@ func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
notification.NotifyMergePullRequest(ctx, merger, pr)
|
||||
notify_service.MergePullRequest(ctx, merger, pr)
|
||||
|
||||
log.Info("manuallyMerged[%-v]: Marked as manually merged into %s/%s by commit id: %s", pr, pr.BaseRepo.Name, pr.BaseBranch, commit.ID.String())
|
||||
return true
|
||||
|
||||
@@ -25,12 +25,12 @@ import (
|
||||
"code.gitea.io/gitea/modules/cache"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/references"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// getMergeMessage composes the message used when merging a pull request.
|
||||
@@ -206,9 +206,9 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
|
||||
}
|
||||
|
||||
if wasAutoMerged {
|
||||
notification.NotifyAutoMergePullRequest(ctx, doer, pr)
|
||||
notify_service.AutoMergePullRequest(ctx, doer, pr)
|
||||
} else {
|
||||
notification.NotifyMergePullRequest(ctx, doer, pr)
|
||||
notify_service.MergePullRequest(ctx, doer, pr)
|
||||
}
|
||||
|
||||
// Reset cached commit count
|
||||
@@ -521,7 +521,7 @@ func MergedManually(pr *issues_model.PullRequest, doer *user_model.User, baseGit
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyMergePullRequest(baseGitRepo.Ctx, doer, pr)
|
||||
notify_service.MergePullRequest(baseGitRepo.Ctx, doer, pr)
|
||||
log.Info("manuallyMerged[%d]: Marked as manually merged into %s/%s by commit id: %s", pr.ID, pr.BaseRepo.Name, pr.BaseBranch, commitID)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -25,12 +25,12 @@ import (
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/sync"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// TODO: use clustered lock (unique queue? or *abuse* cache)
|
||||
@@ -145,12 +145,12 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyNewPullRequest(ctx, pr, mentions)
|
||||
notify_service.NewPullRequest(ctx, pr, mentions)
|
||||
if len(issue.Labels) > 0 {
|
||||
notification.NotifyIssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil)
|
||||
notify_service.IssueChangeLabels(ctx, issue.Poster, issue, issue.Labels, nil)
|
||||
}
|
||||
if issue.Milestone != nil {
|
||||
notification.NotifyIssueChangeMilestone(ctx, issue.Poster, issue, 0)
|
||||
notify_service.IssueChangeMilestone(ctx, issue.Poster, issue, 0)
|
||||
}
|
||||
if len(assigneeIDs) > 0 {
|
||||
for _, assigneeID := range assigneeIDs {
|
||||
@@ -158,7 +158,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss
|
||||
if err != nil {
|
||||
return ErrDependenciesLeft
|
||||
}
|
||||
notification.NotifyIssueChangeAssignee(ctx, issue.Poster, issue, assignee, false, assigneeCommentMap[assigneeID])
|
||||
notify_service.IssueChangeAssignee(ctx, issue.Poster, issue, assignee, false, assigneeCommentMap[assigneeID])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
|
||||
AddToTaskQueue(ctx, pr)
|
||||
comment, err := CreatePushPullComment(ctx, doer, pr, oldCommitID, newCommitID)
|
||||
if err == nil && comment != nil {
|
||||
notification.NotifyPullRequestPushCommits(ctx, doer, pr, comment)
|
||||
notify_service.PullRequestPushCommits(ctx, doer, pr, comment)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyPullRequestSynchronized(ctx, doer, pr)
|
||||
notify_service.PullRequestSynchronized(ctx, doer, pr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ import (
|
||||
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/notification"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
var notEnoughLines = regexp.MustCompile(`fatal: file .* has only \d+ lines?`)
|
||||
@@ -113,7 +113,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
notification.NotifyCreateIssueComment(ctx, doer, issue.Repo, issue, comment, mentions)
|
||||
notify_service.CreateIssueComment(ctx, doer, issue.Repo, issue, comment, mentions)
|
||||
|
||||
return comment, nil
|
||||
}
|
||||
@@ -298,7 +298,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
notification.NotifyPullRequestReview(ctx, pr, review, comm, mentions)
|
||||
notify_service.PullRequestReview(ctx, pr, review, comm, mentions)
|
||||
|
||||
for _, lines := range review.CodeComments {
|
||||
for _, comments := range lines {
|
||||
@@ -307,7 +307,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
notification.NotifyPullRequestCodeComment(ctx, pr, codeComment, mentions)
|
||||
notify_service.PullRequestCodeComment(ctx, pr, codeComment, mentions)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,7 +355,7 @@ func DismissApprovalReviews(ctx context.Context, doer *user_model.User, pull *is
|
||||
comment.Poster = doer
|
||||
comment.Issue = review.Issue
|
||||
|
||||
notification.NotifyPullReviewDismiss(ctx, doer, review, comment)
|
||||
notify_service.PullReviewDismiss(ctx, doer, review, comment)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
@@ -426,7 +426,7 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
||||
comment.Poster = doer
|
||||
comment.Issue = review.Issue
|
||||
|
||||
notification.NotifyPullReviewDismiss(ctx, doer, review, comment)
|
||||
notify_service.PullReviewDismiss(ctx, doer, review, comment)
|
||||
|
||||
return comment, nil
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ import (
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/storage"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Release, msg string) (bool, error) {
|
||||
@@ -81,14 +81,14 @@ func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Rel
|
||||
commits.CompareURL = rel.Repo.ComposeCompareURL(git.EmptySHA, commit.ID.String())
|
||||
|
||||
refFullName := git.RefNameFromTag(rel.TagName)
|
||||
notification.NotifyPushCommits(
|
||||
notify_service.PushCommits(
|
||||
ctx, rel.Publisher, rel.Repo,
|
||||
&repository.PushUpdateOptions{
|
||||
RefFullName: refFullName,
|
||||
OldCommitID: git.EmptySHA,
|
||||
NewCommitID: commit.ID.String(),
|
||||
}, commits)
|
||||
notification.NotifyCreateRef(ctx, rel.Publisher, rel.Repo, refFullName, commit.ID.String())
|
||||
notify_service.CreateRef(ctx, rel.Publisher, rel.Repo, refFullName, commit.ID.String())
|
||||
rel.CreatedUnix = timeutil.TimeStampNow()
|
||||
}
|
||||
commit, err := gitRepo.GetTagCommit(rel.TagName)
|
||||
@@ -139,7 +139,7 @@ func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentU
|
||||
}
|
||||
|
||||
if !rel.IsDraft {
|
||||
notification.NotifyNewRelease(gitRepo.Ctx, rel)
|
||||
notify_service.NewRelease(gitRepo.Ctx, rel)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -279,12 +279,12 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
||||
}
|
||||
|
||||
if !isCreated {
|
||||
notification.NotifyUpdateRelease(gitRepo.Ctx, doer, rel)
|
||||
notify_service.UpdateRelease(gitRepo.Ctx, doer, rel)
|
||||
return nil
|
||||
}
|
||||
|
||||
if !rel.IsDraft {
|
||||
notification.NotifyNewRelease(gitRepo.Ctx, rel)
|
||||
notify_service.NewRelease(gitRepo.Ctx, rel)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -325,14 +325,14 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
|
||||
}
|
||||
|
||||
refName := git.RefNameFromTag(rel.TagName)
|
||||
notification.NotifyPushCommits(
|
||||
notify_service.PushCommits(
|
||||
ctx, doer, repo,
|
||||
&repository.PushUpdateOptions{
|
||||
RefFullName: refName,
|
||||
OldCommitID: rel.Sha1,
|
||||
NewCommitID: git.EmptySHA,
|
||||
}, repository.NewPushCommits())
|
||||
notification.NotifyDeleteRef(ctx, doer, repo, refName)
|
||||
notify_service.DeleteRef(ctx, doer, repo, refName)
|
||||
|
||||
if err := repo_model.DeleteReleaseByID(ctx, id); err != nil {
|
||||
return fmt.Errorf("DeleteReleaseByID: %w", err)
|
||||
@@ -361,7 +361,7 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyDeleteRelease(ctx, doer, rel)
|
||||
notify_service.DeleteRelease(ctx, doer, rel)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ import (
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
|
||||
"github.com/gobwas/glob"
|
||||
)
|
||||
@@ -104,7 +104,7 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts repo_mo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
notification.NotifyAdoptRepository(ctx, doer, u, repo)
|
||||
notify_service.AdoptRepository(ctx, doer, u, repo)
|
||||
|
||||
return repo, nil
|
||||
}
|
||||
@@ -195,6 +195,10 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
|
||||
return fmt.Errorf("updateRepository: %w", err)
|
||||
}
|
||||
|
||||
if err = repo_module.SyncReleasesWithTags(repo, gitRepo); err != nil {
|
||||
return fmt.Errorf("SyncReleasesWithTags: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/contexttest"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -24,11 +24,11 @@ func TestMain(m *testing.M) {
|
||||
func TestArchive_Basic(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
ctx, _ := test.MockContext(t, "user27/repo49")
|
||||
ctx, _ := contexttest.MockContext(t, "user27/repo49")
|
||||
firstCommit, secondCommit := "51f84af23134", "aacbdfe9e1c4"
|
||||
|
||||
test.LoadRepo(t, ctx, 49)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
contexttest.LoadRepo(t, ctx, 49)
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
bogusReq, err := NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, firstCommit+".zip")
|
||||
|
||||
@@ -18,10 +18,10 @@ import (
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/queue"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
files_service "code.gitea.io/gitea/services/repository/files"
|
||||
|
||||
"xorm.io/builder"
|
||||
@@ -301,8 +301,8 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m
|
||||
return "", err
|
||||
}
|
||||
|
||||
notification.NotifyDeleteRef(ctx, doer, repo, git.RefNameFromBranch(from))
|
||||
notification.NotifyCreateRef(ctx, doer, repo, refNameTo, refID)
|
||||
notify_service.DeleteRef(ctx, doer, repo, git.RefNameFromBranch(from))
|
||||
notify_service.CreateRef(ctx, doer, repo, refNameTo, refID)
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import (
|
||||
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/contexttest"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -54,12 +54,12 @@ func getExpectedReadmeContentsResponse() *api.ContentsResponse {
|
||||
|
||||
func TestGetContents(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx, _ := test.MockContext(t, "user2/repo1")
|
||||
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
treePath := "README.md"
|
||||
@@ -82,12 +82,12 @@ func TestGetContents(t *testing.T) {
|
||||
|
||||
func TestGetContentsOrListForDir(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx, _ := test.MockContext(t, "user2/repo1")
|
||||
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
treePath := "" // root dir
|
||||
@@ -117,12 +117,12 @@ func TestGetContentsOrListForDir(t *testing.T) {
|
||||
|
||||
func TestGetContentsOrListForFile(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx, _ := test.MockContext(t, "user2/repo1")
|
||||
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
treePath := "README.md"
|
||||
@@ -145,12 +145,12 @@ func TestGetContentsOrListForFile(t *testing.T) {
|
||||
|
||||
func TestGetContentsErrors(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx, _ := test.MockContext(t, "user2/repo1")
|
||||
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
@@ -176,12 +176,12 @@ func TestGetContentsErrors(t *testing.T) {
|
||||
|
||||
func TestGetContentsOrListErrors(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx, _ := test.MockContext(t, "user2/repo1")
|
||||
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
@@ -207,11 +207,11 @@ func TestGetContentsOrListErrors(t *testing.T) {
|
||||
|
||||
func TestGetContentsOrListOfEmptyRepos(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx, _ := test.MockContext(t, "user30/empty")
|
||||
ctx, _ := contexttest.MockContext(t, "user30/empty")
|
||||
ctx.SetParams(":id", "52")
|
||||
test.LoadRepo(t, ctx, 52)
|
||||
test.LoadUser(t, ctx, 30)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
contexttest.LoadRepo(t, ctx, 52)
|
||||
contexttest.LoadUser(t, ctx, 30)
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
@@ -225,11 +225,11 @@ func TestGetContentsOrListOfEmptyRepos(t *testing.T) {
|
||||
|
||||
func TestGetBlobBySHA(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx, _ := test.MockContext(t, "user2/repo1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/contexttest"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/services/gitdiff"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -17,12 +17,12 @@ import (
|
||||
|
||||
func TestGetDiffPreview(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx, _ := test.MockContext(t, "user2/repo1")
|
||||
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
branch := ctx.Repo.Repository.DefaultBranch
|
||||
@@ -139,12 +139,12 @@ func TestGetDiffPreview(t *testing.T) {
|
||||
|
||||
func TestGetDiffPreviewErrors(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx, _ := test.MockContext(t, "user2/repo1")
|
||||
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
branch := ctx.Repo.Repository.DefaultBranch
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/contexttest"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -98,12 +98,12 @@ func getExpectedFileResponse() *api.FileResponse {
|
||||
|
||||
func TestGetFileResponseFromCommit(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx, _ := test.MockContext(t, "user2/repo1")
|
||||
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
@@ -7,19 +7,19 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/contexttest"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetTreeBySHA(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx, _ := test.MockContext(t, "user2/repo1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
test.LoadUser(t, ctx, 2)
|
||||
test.LoadGitRepo(t, ctx)
|
||||
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
||||
contexttest.LoadRepo(t, ctx, 1)
|
||||
contexttest.LoadRepoCommit(t, ctx)
|
||||
contexttest.LoadUser(t, ctx, 2)
|
||||
contexttest.LoadGitRepo(t, ctx)
|
||||
defer ctx.Repo.GitRepo.Close()
|
||||
|
||||
sha := ctx.Repo.Repository.DefaultBranch
|
||||
|
||||
@@ -15,10 +15,10 @@ import (
|
||||
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/notification"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// ErrForkAlreadyExist represents a "ForkAlreadyExist" kind of error.
|
||||
@@ -191,7 +191,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyForkRepository(ctx, doer, opts.BaseRepo, repo)
|
||||
notify_service.ForkRepository(ctx, doer, opts.BaseRepo, repo)
|
||||
|
||||
return repo, nil
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ import (
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/process"
|
||||
"code.gitea.io/gitea/modules/queue"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
issue_service "code.gitea.io/gitea/services/issue"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
)
|
||||
|
||||
@@ -119,7 +119,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
}
|
||||
tagName := opts.RefFullName.TagName()
|
||||
if opts.IsDelRef() {
|
||||
notification.NotifyPushCommits(
|
||||
notify_service.PushCommits(
|
||||
ctx, pusher, repo,
|
||||
&repo_module.PushUpdateOptions{
|
||||
RefFullName: git.RefNameFromTag(tagName),
|
||||
@@ -128,7 +128,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
}, repo_module.NewPushCommits())
|
||||
|
||||
delTags = append(delTags, tagName)
|
||||
notification.NotifyDeleteRef(ctx, pusher, repo, opts.RefFullName)
|
||||
notify_service.DeleteRef(ctx, pusher, repo, opts.RefFullName)
|
||||
} else { // is new tag
|
||||
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
|
||||
if err != nil {
|
||||
@@ -139,7 +139,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
commits.HeadCommit = repo_module.CommitToPushCommit(newCommit)
|
||||
commits.CompareURL = repo.ComposeCompareURL(git.EmptySHA, opts.NewCommitID)
|
||||
|
||||
notification.NotifyPushCommits(
|
||||
notify_service.PushCommits(
|
||||
ctx, pusher, repo,
|
||||
&repo_module.PushUpdateOptions{
|
||||
RefFullName: opts.RefFullName,
|
||||
@@ -148,7 +148,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
}, commits)
|
||||
|
||||
addTags = append(addTags, tagName)
|
||||
notification.NotifyCreateRef(ctx, pusher, repo, opts.RefFullName, opts.NewCommitID)
|
||||
notify_service.CreateRef(ctx, pusher, repo, opts.RefFullName, opts.NewCommitID)
|
||||
}
|
||||
} else if opts.RefFullName.IsBranch() {
|
||||
if pusher == nil || pusher.ID != opts.PusherID {
|
||||
@@ -197,7 +197,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("newCommit.CommitsBeforeLimit: %w", err)
|
||||
}
|
||||
notification.NotifyCreateRef(ctx, pusher, repo, opts.RefFullName, opts.NewCommitID)
|
||||
notify_service.CreateRef(ctx, pusher, repo, opts.RefFullName, opts.NewCommitID)
|
||||
} else {
|
||||
l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID)
|
||||
if err != nil {
|
||||
@@ -261,14 +261,14 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
return fmt.Errorf("git_model.UpdateBranch %s:%s failed: %v", repo.FullName(), branch, err)
|
||||
}
|
||||
|
||||
notification.NotifyPushCommits(ctx, pusher, repo, opts, commits)
|
||||
notify_service.PushCommits(ctx, pusher, repo, opts, commits)
|
||||
|
||||
// Cache for big repository
|
||||
if err := CacheRef(graceful.GetManager().HammerContext(), repo, gitRepo, opts.RefFullName); err != nil {
|
||||
log.Error("repo_module.CacheRef %s/%s failed: %v", repo.ID, branch, err)
|
||||
}
|
||||
} else {
|
||||
notification.NotifyDeleteRef(ctx, pusher, repo, opts.RefFullName)
|
||||
notify_service.DeleteRef(ctx, pusher, repo, opts.RefFullName)
|
||||
if err = pull_service.CloseBranchPulls(ctx, pusher, repo.ID, branch); err != nil {
|
||||
// close all related pulls
|
||||
log.Error("close related pull request failed: %v", err)
|
||||
|
||||
@@ -19,10 +19,10 @@ import (
|
||||
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"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
)
|
||||
|
||||
@@ -47,7 +47,7 @@ func CreateRepository(ctx context.Context, doer, owner *user_model.User, opts re
|
||||
return nil, err
|
||||
}
|
||||
|
||||
notification.NotifyCreateRepository(ctx, doer, owner, repo)
|
||||
notify_service.CreateRepository(ctx, doer, owner, repo)
|
||||
|
||||
return repo, nil
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_mod
|
||||
|
||||
if notify {
|
||||
// If the repo itself has webhooks, we need to trigger them before deleting it...
|
||||
notification.NotifyDeleteRepository(ctx, doer, repo)
|
||||
notify_service.DeleteRepository(ctx, doer, repo)
|
||||
}
|
||||
|
||||
if err := models.DeleteRepository(doer, repo.OwnerID, repo.ID); err != nil {
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// GenerateIssueLabels generates issue labels from a template repository
|
||||
@@ -130,7 +130,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
|
||||
return nil, err
|
||||
}
|
||||
|
||||
notification.NotifyCreateRepository(ctx, doer, owner, generateRepo)
|
||||
notify_service.CreateRepository(ctx, doer, owner, generateRepo)
|
||||
|
||||
return generateRepo, nil
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/sync"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
// repoWorkingPool represents a working pool to order the parallel changes to the same repository
|
||||
@@ -54,7 +54,7 @@ func TransferOwnership(ctx context.Context, doer, newOwner *user_model.User, rep
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyTransferRepository(ctx, doer, repo, oldOwner.Name)
|
||||
notify_service.TransferRepository(ctx, doer, repo, oldOwner.Name)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -77,7 +77,7 @@ func ChangeRepositoryName(ctx context.Context, doer *user_model.User, repo *repo
|
||||
repoWorkingPool.CheckOut(fmt.Sprint(repo.ID))
|
||||
|
||||
repo.Name = newRepoName
|
||||
notification.NotifyRenameRepository(ctx, doer, repo, oldRepoName)
|
||||
notify_service.RenameRepository(ctx, doer, repo, oldRepoName)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -126,7 +126,7 @@ func StartRepositoryTransfer(ctx context.Context, doer, newOwner *user_model.Use
|
||||
}
|
||||
|
||||
// notify users who are able to accept / reject transfer
|
||||
notification.NotifyRepoPendingTransfer(ctx, doer, newOwner, repo)
|
||||
notify_service.RepoPendingTransfer(ctx, doer, newOwner, repo)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ import (
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/notification/action"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/services/feed"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -25,7 +25,7 @@ var notifySync sync.Once
|
||||
|
||||
func registerNotifier() {
|
||||
notifySync.Do(func() {
|
||||
notification.RegisterNotifier(action.NewNotifier())
|
||||
notify_service.RegisterNotifier(feed.NewNotifier())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package secrets
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
secret_model "code.gitea.io/gitea/models/secret"
|
||||
)
|
||||
|
||||
func CreateOrUpdateSecret(ctx context.Context, ownerID, repoID int64, name, data string) (*secret_model.Secret, bool, error) {
|
||||
if err := ValidateName(name); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
s, err := secret_model.FindSecrets(ctx, secret_model.FindSecretsOptions{
|
||||
OwnerID: ownerID,
|
||||
RepoID: repoID,
|
||||
Name: name,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
if len(s) == 0 {
|
||||
s, err := secret_model.InsertEncryptedSecret(ctx, ownerID, repoID, name, data)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
return s, true, nil
|
||||
}
|
||||
|
||||
if err := secret_model.UpdateSecret(ctx, s[0].ID, data); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
|
||||
return s[0], false, nil
|
||||
}
|
||||
|
||||
func DeleteSecretByID(ctx context.Context, ownerID, repoID, secretID int64) error {
|
||||
s, err := secret_model.FindSecrets(ctx, secret_model.FindSecretsOptions{
|
||||
OwnerID: ownerID,
|
||||
RepoID: repoID,
|
||||
SecretID: secretID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(s) != 1 {
|
||||
return secret_model.ErrSecretNotFound{}
|
||||
}
|
||||
|
||||
return deleteSecret(ctx, s[0])
|
||||
}
|
||||
|
||||
func DeleteSecretByName(ctx context.Context, ownerID, repoID int64, name string) error {
|
||||
if err := ValidateName(name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := secret_model.FindSecrets(ctx, secret_model.FindSecretsOptions{
|
||||
OwnerID: ownerID,
|
||||
RepoID: repoID,
|
||||
Name: name,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(s) != 1 {
|
||||
return secret_model.ErrSecretNotFound{}
|
||||
}
|
||||
|
||||
return deleteSecret(ctx, s[0])
|
||||
}
|
||||
|
||||
func deleteSecret(ctx context.Context, s *secret_model.Secret) error {
|
||||
if _, err := db.DeleteByID(ctx, s.ID, s); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package secrets
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
// https://docs.github.com/en/actions/security-guides/encrypted-secrets#naming-your-secrets
|
||||
var (
|
||||
namePattern = regexp.MustCompile("(?i)^[A-Z_][A-Z0-9_]*$")
|
||||
forbiddenPrefixPattern = regexp.MustCompile("(?i)^GIT(EA|HUB)_")
|
||||
|
||||
ErrInvalidName = util.NewInvalidArgumentErrorf("invalid secret name")
|
||||
)
|
||||
|
||||
func ValidateName(name string) error {
|
||||
if !namePattern.MatchString(name) || forbiddenPrefixPattern.MatchString(name) {
|
||||
return ErrInvalidName
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -17,12 +17,12 @@ import (
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/migration"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
"code.gitea.io/gitea/modules/process"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/services/migrations"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
func handleCreateError(owner *user_model.User, err error) error {
|
||||
@@ -50,7 +50,7 @@ func runMigrateTask(t *admin_model.Task) (err error) {
|
||||
if err == nil {
|
||||
err = admin_model.FinishMigrateTask(t)
|
||||
if err == nil {
|
||||
notification.NotifyMigrateRepository(db.DefaultContext, t.Doer, t.Owner, t.Repo)
|
||||
notify_service.MigrateRepository(db.DefaultContext, t.Doer, t.Owner, t.Repo)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
// Copyright 2018 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package uinotification
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/queue"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
type (
|
||||
notificationService struct {
|
||||
notify_service.NullNotifier
|
||||
issueQueue *queue.WorkerPoolQueue[issueNotificationOpts]
|
||||
}
|
||||
|
||||
issueNotificationOpts struct {
|
||||
IssueID int64
|
||||
CommentID int64
|
||||
NotificationAuthorID int64
|
||||
ReceiverID int64 // 0 -- ALL Watcher
|
||||
}
|
||||
)
|
||||
|
||||
func Init() error {
|
||||
notify_service.RegisterNotifier(NewNotifier())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ notify_service.Notifier = ¬ificationService{}
|
||||
|
||||
// NewNotifier create a new notificationService notifier
|
||||
func NewNotifier() notify_service.Notifier {
|
||||
ns := ¬ificationService{}
|
||||
ns.issueQueue = queue.CreateSimpleQueue(graceful.GetManager().ShutdownContext(), "notification-service", handler)
|
||||
if ns.issueQueue == nil {
|
||||
log.Fatal("Unable to create notification-service queue")
|
||||
}
|
||||
return ns
|
||||
}
|
||||
|
||||
func handler(items ...issueNotificationOpts) []issueNotificationOpts {
|
||||
for _, opts := range items {
|
||||
if err := activities_model.CreateOrUpdateIssueNotifications(opts.IssueID, opts.CommentID, opts.NotificationAuthorID, opts.ReceiverID); err != nil {
|
||||
log.Error("Was unable to create issue notification: %v", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ns *notificationService) Run() {
|
||||
go graceful.GetManager().RunWithCancel(ns.issueQueue) // TODO: using "go" here doesn't seem right, just leave it as old code
|
||||
}
|
||||
|
||||
func (ns *notificationService) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
||||
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
|
||||
) {
|
||||
opts := issueNotificationOpts{
|
||||
IssueID: issue.ID,
|
||||
NotificationAuthorID: doer.ID,
|
||||
}
|
||||
if comment != nil {
|
||||
opts.CommentID = comment.ID
|
||||
}
|
||||
_ = ns.issueQueue.Push(opts)
|
||||
for _, mention := range mentions {
|
||||
opts := issueNotificationOpts{
|
||||
IssueID: issue.ID,
|
||||
NotificationAuthorID: doer.ID,
|
||||
ReceiverID: mention.ID,
|
||||
}
|
||||
if comment != nil {
|
||||
opts.CommentID = comment.ID
|
||||
}
|
||||
_ = ns.issueQueue.Push(opts)
|
||||
}
|
||||
}
|
||||
|
||||
func (ns *notificationService) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
|
||||
_ = ns.issueQueue.Push(issueNotificationOpts{
|
||||
IssueID: issue.ID,
|
||||
NotificationAuthorID: issue.Poster.ID,
|
||||
})
|
||||
for _, mention := range mentions {
|
||||
_ = ns.issueQueue.Push(issueNotificationOpts{
|
||||
IssueID: issue.ID,
|
||||
NotificationAuthorID: issue.Poster.ID,
|
||||
ReceiverID: mention.ID,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ns *notificationService) IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
|
||||
_ = ns.issueQueue.Push(issueNotificationOpts{
|
||||
IssueID: issue.ID,
|
||||
NotificationAuthorID: doer.ID,
|
||||
CommentID: actionComment.ID,
|
||||
})
|
||||
}
|
||||
|
||||
func (ns *notificationService) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
|
||||
if err := issue.LoadPullRequest(ctx); err != nil {
|
||||
log.Error("issue.LoadPullRequest: %v", err)
|
||||
return
|
||||
}
|
||||
if issue.IsPull && issues_model.HasWorkInProgressPrefix(oldTitle) && !issue.PullRequest.IsWorkInProgress() {
|
||||
_ = ns.issueQueue.Push(issueNotificationOpts{
|
||||
IssueID: issue.ID,
|
||||
NotificationAuthorID: doer.ID,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ns *notificationService) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
_ = ns.issueQueue.Push(issueNotificationOpts{
|
||||
IssueID: pr.Issue.ID,
|
||||
NotificationAuthorID: doer.ID,
|
||||
})
|
||||
}
|
||||
|
||||
func (ns *notificationService) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
ns.MergePullRequest(ctx, doer, pr)
|
||||
}
|
||||
|
||||
func (ns *notificationService) NewPullRequest(ctx context.Context, pr *issues_model.PullRequest, mentions []*user_model.User) {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
log.Error("Unable to load issue: %d for pr: %d: Error: %v", pr.IssueID, pr.ID, err)
|
||||
return
|
||||
}
|
||||
toNotify := make(container.Set[int64], 32)
|
||||
repoWatchers, err := repo_model.GetRepoWatchersIDs(ctx, pr.Issue.RepoID)
|
||||
if err != nil {
|
||||
log.Error("GetRepoWatchersIDs: %v", err)
|
||||
return
|
||||
}
|
||||
for _, id := range repoWatchers {
|
||||
toNotify.Add(id)
|
||||
}
|
||||
issueParticipants, err := issues_model.GetParticipantsIDsByIssueID(ctx, pr.IssueID)
|
||||
if err != nil {
|
||||
log.Error("GetParticipantsIDsByIssueID: %v", err)
|
||||
return
|
||||
}
|
||||
for _, id := range issueParticipants {
|
||||
toNotify.Add(id)
|
||||
}
|
||||
delete(toNotify, pr.Issue.PosterID)
|
||||
for _, mention := range mentions {
|
||||
toNotify.Add(mention.ID)
|
||||
}
|
||||
for receiverID := range toNotify {
|
||||
_ = ns.issueQueue.Push(issueNotificationOpts{
|
||||
IssueID: pr.Issue.ID,
|
||||
NotificationAuthorID: pr.Issue.PosterID,
|
||||
ReceiverID: receiverID,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ns *notificationService) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, r *issues_model.Review, c *issues_model.Comment, mentions []*user_model.User) {
|
||||
opts := issueNotificationOpts{
|
||||
IssueID: pr.Issue.ID,
|
||||
NotificationAuthorID: r.Reviewer.ID,
|
||||
}
|
||||
if c != nil {
|
||||
opts.CommentID = c.ID
|
||||
}
|
||||
_ = ns.issueQueue.Push(opts)
|
||||
for _, mention := range mentions {
|
||||
opts := issueNotificationOpts{
|
||||
IssueID: pr.Issue.ID,
|
||||
NotificationAuthorID: r.Reviewer.ID,
|
||||
ReceiverID: mention.ID,
|
||||
}
|
||||
if c != nil {
|
||||
opts.CommentID = c.ID
|
||||
}
|
||||
_ = ns.issueQueue.Push(opts)
|
||||
}
|
||||
}
|
||||
|
||||
func (ns *notificationService) PullRequestCodeComment(ctx context.Context, pr *issues_model.PullRequest, c *issues_model.Comment, mentions []*user_model.User) {
|
||||
for _, mention := range mentions {
|
||||
_ = ns.issueQueue.Push(issueNotificationOpts{
|
||||
IssueID: pr.Issue.ID,
|
||||
NotificationAuthorID: c.Poster.ID,
|
||||
CommentID: c.ID,
|
||||
ReceiverID: mention.ID,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ns *notificationService) PullRequestPushCommits(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, comment *issues_model.Comment) {
|
||||
opts := issueNotificationOpts{
|
||||
IssueID: pr.IssueID,
|
||||
NotificationAuthorID: doer.ID,
|
||||
CommentID: comment.ID,
|
||||
}
|
||||
_ = ns.issueQueue.Push(opts)
|
||||
}
|
||||
|
||||
func (ns *notificationService) PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issues_model.Review, comment *issues_model.Comment) {
|
||||
opts := issueNotificationOpts{
|
||||
IssueID: review.IssueID,
|
||||
NotificationAuthorID: doer.ID,
|
||||
CommentID: comment.ID,
|
||||
}
|
||||
_ = ns.issueQueue.Push(opts)
|
||||
}
|
||||
|
||||
func (ns *notificationService) IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
|
||||
if !removed && doer.ID != assignee.ID {
|
||||
opts := issueNotificationOpts{
|
||||
IssueID: issue.ID,
|
||||
NotificationAuthorID: doer.ID,
|
||||
ReceiverID: assignee.ID,
|
||||
}
|
||||
|
||||
if comment != nil {
|
||||
opts.CommentID = comment.ID
|
||||
}
|
||||
|
||||
_ = ns.issueQueue.Push(opts)
|
||||
}
|
||||
}
|
||||
|
||||
func (ns *notificationService) PullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
|
||||
if isRequest {
|
||||
opts := issueNotificationOpts{
|
||||
IssueID: issue.ID,
|
||||
NotificationAuthorID: doer.ID,
|
||||
ReceiverID: reviewer.ID,
|
||||
}
|
||||
|
||||
if comment != nil {
|
||||
opts.CommentID = comment.ID
|
||||
}
|
||||
|
||||
_ = ns.issueQueue.Push(opts)
|
||||
}
|
||||
}
|
||||
|
||||
func (ns *notificationService) RepoPendingTransfer(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) {
|
||||
err := db.WithTx(ctx, func(ctx context.Context) error {
|
||||
return activities_model.CreateRepoTransferNotification(ctx, doer, newOwner, repo)
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("CreateRepoTransferNotification: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -14,31 +14,30 @@ import (
|
||||
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/notification"
|
||||
"code.gitea.io/gitea/modules/notification/base"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
func init() {
|
||||
notification.RegisterNotifier(&webhookNotifier{})
|
||||
notify_service.RegisterNotifier(&webhookNotifier{})
|
||||
}
|
||||
|
||||
type webhookNotifier struct {
|
||||
base.NullNotifier
|
||||
notify_service.NullNotifier
|
||||
}
|
||||
|
||||
var _ base.Notifier = &webhookNotifier{}
|
||||
var _ notify_service.Notifier = &webhookNotifier{}
|
||||
|
||||
// NewNotifier create a new webhookNotifier notifier
|
||||
func NewNotifier() base.Notifier {
|
||||
func NewNotifier() notify_service.Notifier {
|
||||
return &webhookNotifier{}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyIssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) {
|
||||
func (m *webhookNotifier) IssueClearLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue) {
|
||||
if err := issue.LoadPoster(ctx); err != nil {
|
||||
log.Error("LoadPoster: %v", err)
|
||||
return
|
||||
@@ -78,7 +77,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(ctx context.Context, doer *user
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
|
||||
func (m *webhookNotifier) ForkRepository(ctx context.Context, doer *user_model.User, oldRepo, repo *repo_model.Repository) {
|
||||
oldPermission, _ := access_model.GetUserRepoPermission(ctx, oldRepo, doer)
|
||||
permission, _ := access_model.GetUserRepoPermission(ctx, repo, doer)
|
||||
|
||||
@@ -106,7 +105,7 @@ func (m *webhookNotifier) NotifyForkRepository(ctx context.Context, doer *user_m
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyCreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
func (m *webhookNotifier) CreateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
// Add to hook queue for created repo after session commit.
|
||||
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{
|
||||
Action: api.HookRepoCreated,
|
||||
@@ -118,7 +117,7 @@ func (m *webhookNotifier) NotifyCreateRepository(ctx context.Context, doer, u *u
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyDeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) {
|
||||
func (m *webhookNotifier) DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) {
|
||||
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{
|
||||
Action: api.HookRepoDeleted,
|
||||
Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner}),
|
||||
@@ -129,7 +128,7 @@ func (m *webhookNotifier) NotifyDeleteRepository(ctx context.Context, doer *user
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyMigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
func (m *webhookNotifier) MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
|
||||
// Add to hook queue for created repo after session commit.
|
||||
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventRepository, &api.RepositoryPayload{
|
||||
Action: api.HookRepoCreated,
|
||||
@@ -141,7 +140,7 @@ func (m *webhookNotifier) NotifyMigrateRepository(ctx context.Context, doer, u *
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
|
||||
func (m *webhookNotifier) IssueChangeAssignee(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, assignee *user_model.User, removed bool, comment *issues_model.Comment) {
|
||||
if issue.IsPull {
|
||||
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, doer)
|
||||
|
||||
@@ -186,7 +185,7 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *u
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
|
||||
func (m *webhookNotifier) IssueChangeTitle(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldTitle string) {
|
||||
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster)
|
||||
var err error
|
||||
if issue.IsPull {
|
||||
@@ -226,7 +225,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
|
||||
func (m *webhookNotifier) IssueChangeStatus(ctx context.Context, doer *user_model.User, commitID string, issue *issues_model.Issue, actionComment *issues_model.Comment, isClosed bool) {
|
||||
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, issue.Poster)
|
||||
var err error
|
||||
if issue.IsPull {
|
||||
@@ -268,7 +267,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
|
||||
func (m *webhookNotifier) NewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
|
||||
if err := issue.LoadRepo(ctx); err != nil {
|
||||
log.Error("issue.LoadRepo: %v", err)
|
||||
return
|
||||
@@ -290,7 +289,7 @@ func (m *webhookNotifier) NotifyNewIssue(ctx context.Context, issue *issues_mode
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues_model.PullRequest, mentions []*user_model.User) {
|
||||
func (m *webhookNotifier) NewPullRequest(ctx context.Context, pull *issues_model.PullRequest, mentions []*user_model.User) {
|
||||
if err := pull.LoadIssue(ctx); err != nil {
|
||||
log.Error("pull.LoadIssue: %v", err)
|
||||
return
|
||||
@@ -316,7 +315,7 @@ func (m *webhookNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyIssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) {
|
||||
func (m *webhookNotifier) IssueChangeContent(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldContent string) {
|
||||
if err := issue.LoadRepo(ctx); err != nil {
|
||||
log.Error("LoadRepo: %v", err)
|
||||
return
|
||||
@@ -360,7 +359,7 @@ func (m *webhookNotifier) NotifyIssueChangeContent(ctx context.Context, doer *us
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyUpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
|
||||
func (m *webhookNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
|
||||
if err := c.LoadPoster(ctx); err != nil {
|
||||
log.Error("LoadPoster: %v", err)
|
||||
return
|
||||
@@ -400,7 +399,7 @@ func (m *webhookNotifier) NotifyUpdateComment(ctx context.Context, doer *user_mo
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
||||
func (m *webhookNotifier) CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
|
||||
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
|
||||
) {
|
||||
var eventType webhook_module.HookEventType
|
||||
@@ -423,7 +422,7 @@ func (m *webhookNotifier) NotifyCreateIssueComment(ctx context.Context, doer *us
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyDeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) {
|
||||
func (m *webhookNotifier) DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) {
|
||||
var err error
|
||||
|
||||
if err = comment.LoadPoster(ctx); err != nil {
|
||||
@@ -460,7 +459,7 @@ func (m *webhookNotifier) NotifyDeleteComment(ctx context.Context, doer *user_mo
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
|
||||
func (m *webhookNotifier) NewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
|
||||
// Add to hook queue for created wiki page.
|
||||
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{
|
||||
Action: api.HookWikiCreated,
|
||||
@@ -473,7 +472,7 @@ func (m *webhookNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_mode
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
|
||||
func (m *webhookNotifier) EditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
|
||||
// Add to hook queue for edit wiki page.
|
||||
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{
|
||||
Action: api.HookWikiEdited,
|
||||
@@ -486,7 +485,7 @@ func (m *webhookNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_mod
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
|
||||
func (m *webhookNotifier) DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
|
||||
// Add to hook queue for edit wiki page.
|
||||
if err := PrepareWebhooks(ctx, EventSource{Repository: repo}, webhook_module.HookEventWiki, &api.WikiPayload{
|
||||
Action: api.HookWikiDeleted,
|
||||
@@ -498,7 +497,7 @@ func (m *webhookNotifier) NotifyDeleteWikiPage(ctx context.Context, doer *user_m
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
|
||||
func (m *webhookNotifier) IssueChangeLabels(ctx context.Context, doer *user_model.User, issue *issues_model.Issue,
|
||||
addedLabels, removedLabels []*issues_model.Label,
|
||||
) {
|
||||
var err error
|
||||
@@ -544,7 +543,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *use
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyIssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) {
|
||||
func (m *webhookNotifier) IssueChangeMilestone(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, oldMilestoneID int64) {
|
||||
var hookAction api.HookIssueAction
|
||||
var err error
|
||||
if issue.MilestoneID > 0 {
|
||||
@@ -586,7 +585,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(ctx context.Context, doer *
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
func (m *webhookNotifier) PushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
apiPusher := convert.ToUser(ctx, pusher, nil)
|
||||
apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL())
|
||||
if err != nil {
|
||||
@@ -610,12 +609,12 @@ func (m *webhookNotifier) NotifyPushCommits(ctx context.Context, pusher *user_mo
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyAutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
// just redirect to the NotifyMergePullRequest
|
||||
m.NotifyMergePullRequest(ctx, doer, pr)
|
||||
func (m *webhookNotifier) AutoMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
// just redirect to the MergePullRequest
|
||||
m.MergePullRequest(ctx, doer, pr)
|
||||
}
|
||||
|
||||
func (*webhookNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
func (*webhookNotifier) MergePullRequest(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
// Reload pull request information.
|
||||
if err := pr.LoadAttributes(ctx); err != nil {
|
||||
log.Error("LoadAttributes: %v", err)
|
||||
@@ -652,7 +651,7 @@ func (*webhookNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_m
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
|
||||
func (m *webhookNotifier) PullRequestChangeTargetBranch(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest, oldBranch string) {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
log.Error("LoadIssue: %v", err)
|
||||
return
|
||||
@@ -677,7 +676,7 @@ func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Contex
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyPullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
|
||||
func (m *webhookNotifier) PullRequestReview(ctx context.Context, pr *issues_model.PullRequest, review *issues_model.Review, comment *issues_model.Comment, mentions []*user_model.User) {
|
||||
var reviewHookType webhook_module.HookEventType
|
||||
|
||||
switch review.Type {
|
||||
@@ -718,9 +717,9 @@ func (m *webhookNotifier) NotifyPullRequestReview(ctx context.Context, pr *issue
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyPullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
|
||||
func (m *webhookNotifier) PullRequestReviewRequest(ctx context.Context, doer *user_model.User, issue *issues_model.Issue, reviewer *user_model.User, isRequest bool, comment *issues_model.Comment) {
|
||||
if !issue.IsPull {
|
||||
log.Warn("NotifyPullRequestReviewRequest: issue is not a pull request: %v", issue.ID)
|
||||
log.Warn("PullRequestReviewRequest: issue is not a pull request: %v", issue.ID)
|
||||
return
|
||||
}
|
||||
permission, _ := access_model.GetUserRepoPermission(ctx, issue.Repo, doer)
|
||||
@@ -746,7 +745,7 @@ func (m *webhookNotifier) NotifyPullRequestReviewRequest(ctx context.Context, do
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
func (m *webhookNotifier) CreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
apiPusher := convert.ToUser(ctx, pusher, nil)
|
||||
apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeNone})
|
||||
refName := refFullName.ShortName()
|
||||
@@ -762,7 +761,7 @@ func (m *webhookNotifier) NotifyCreateRef(ctx context.Context, pusher *user_mode
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyPullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
func (m *webhookNotifier) PullRequestSynchronized(ctx context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
log.Error("LoadIssue: %v", err)
|
||||
return
|
||||
@@ -783,7 +782,7 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(ctx context.Context, doe
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
func (m *webhookNotifier) DeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
apiPusher := convert.ToUser(ctx, pusher, nil)
|
||||
apiRepo := convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm.AccessModeOwner})
|
||||
refName := refFullName.ShortName()
|
||||
@@ -816,19 +815,19 @@ func sendReleaseHook(ctx context.Context, doer *user_model.User, rel *repo_model
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyNewRelease(ctx context.Context, rel *repo_model.Release) {
|
||||
func (m *webhookNotifier) NewRelease(ctx context.Context, rel *repo_model.Release) {
|
||||
sendReleaseHook(ctx, rel.Publisher, rel, api.HookReleasePublished)
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyUpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
||||
func (m *webhookNotifier) UpdateRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
||||
sendReleaseHook(ctx, doer, rel, api.HookReleaseUpdated)
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyDeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
||||
func (m *webhookNotifier) DeleteRelease(ctx context.Context, doer *user_model.User, rel *repo_model.Release) {
|
||||
sendReleaseHook(ctx, doer, rel, api.HookReleaseDeleted)
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifySyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
func (m *webhookNotifier) SyncPushCommits(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
apiPusher := convert.ToUser(ctx, pusher, nil)
|
||||
apiCommits, apiHeadCommit, err := commits.ToAPIPayloadCommits(ctx, repo.RepoPath(), repo.HTMLURL())
|
||||
if err != nil {
|
||||
@@ -852,19 +851,19 @@ func (m *webhookNotifier) NotifySyncPushCommits(ctx context.Context, pusher *use
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifySyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
m.NotifyCreateRef(ctx, pusher, repo, refFullName, refID)
|
||||
func (m *webhookNotifier) SyncCreateRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName, refID string) {
|
||||
m.CreateRef(ctx, pusher, repo, refFullName, refID)
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifySyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
m.NotifyDeleteRef(ctx, pusher, repo, refFullName)
|
||||
func (m *webhookNotifier) SyncDeleteRef(ctx context.Context, pusher *user_model.User, repo *repo_model.Repository, refFullName git.RefName) {
|
||||
m.DeleteRef(ctx, pusher, repo, refFullName)
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyPackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
||||
func (m *webhookNotifier) PackageCreate(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
||||
notifyPackage(ctx, doer, pd, api.HookPackageCreated)
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyPackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
||||
func (m *webhookNotifier) PackageDelete(ctx context.Context, doer *user_model.User, pd *packages_model.PackageDescriptor) {
|
||||
notifyPackage(ctx, doer, pd, api.HookPackageDeleted)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user