diff --git a/integrations/integration_test.go b/integrations/integration_test.go index c6a4169751b5c..c082e2cc65e64 100644 --- a/integrations/integration_test.go +++ b/integrations/integration_test.go @@ -213,6 +213,7 @@ func initIntegrationTest() { defer db.Close() } routers.GlobalInit(graceful.GetManager().HammerContext()) + NotifierListenerInit() } func prepareTestEnv(t testing.TB, skip ...int) func() { diff --git a/integrations/mssql.ini.tmpl b/integrations/mssql.ini.tmpl index 063c41972bc77..18bb975a7efd9 100644 --- a/integrations/mssql.ini.tmpl +++ b/integrations/mssql.ini.tmpl @@ -82,3 +82,10 @@ LEVEL = Debug INSTALL_LOCK = true SECRET_KEY = 9pCviYTWSb INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ + +[queue] +TYPE=channel + +[queue.test-notifier] +BATCH_LENGTH=1 +LENGTH=20 diff --git a/integrations/mysql.ini.tmpl b/integrations/mysql.ini.tmpl index beff736606362..dcd9f5c1ba9e1 100644 --- a/integrations/mysql.ini.tmpl +++ b/integrations/mysql.ini.tmpl @@ -84,3 +84,10 @@ LEVEL = Debug INSTALL_LOCK = true SECRET_KEY = 9pCviYTWSb INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ + +[queue] +TYPE=channel + +[queue.test-notifier] +BATCH_LENGTH=1 +LENGTH=20 diff --git a/integrations/mysql8.ini.tmpl b/integrations/mysql8.ini.tmpl index a135ecb9812b8..692d85bce3c05 100644 --- a/integrations/mysql8.ini.tmpl +++ b/integrations/mysql8.ini.tmpl @@ -80,3 +80,10 @@ LEVEL = Debug INSTALL_LOCK = true SECRET_KEY = 9pCviYTWSb INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ + +[queue] +TYPE=channel + +[queue.test-notifier] +BATCH_LENGTH=1 +LENGTH=20 diff --git a/integrations/notification_helper_test.go b/integrations/notification_helper_test.go new file mode 100644 index 0000000000000..12a631ac13df5 --- /dev/null +++ b/integrations/notification_helper_test.go @@ -0,0 +1,117 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package integrations + +import ( + "encoding/json" + "reflect" + "sync" + "testing" + + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/notification" + "code.gitea.io/gitea/modules/notification/base" + "code.gitea.io/gitea/modules/queue" +) + +var notifierListener *NotifierListener + +var once = sync.Once{} + +type NotifierListener struct { + lock sync.RWMutex + callbacks map[string][]*func(string, [][]byte) + notifier base.Notifier +} + +func NotifierListenerInit() { + once.Do(func() { + notifierListener = &NotifierListener{ + callbacks: map[string][]*func(string, [][]byte){}, + } + notifierListener.notifier = base.NewQueueNotifierWithHandle("test-notifier", notifierListener.handle) + notification.RegisterNotifier(notifierListener.notifier) + }) +} + +// Register will register a callback with the provided notifier function +func (n *NotifierListener) Register(functionName string, callback *func(string, [][]byte)) { + n.lock.Lock() + n.callbacks[functionName] = append(n.callbacks[functionName], callback) + n.lock.Unlock() +} + +// Deregister will remove the provided callback from the provided notifier function +func (n *NotifierListener) Deregister(functionName string, callback *func(string, [][]byte)) { + n.lock.Lock() + defer n.lock.Unlock() + for i, callbackPtr := range n.callbacks[functionName] { + if callbackPtr == callback { + n.callbacks[functionName] = append(n.callbacks[functionName][0:i], n.callbacks[functionName][i+1:]...) + return + } + } +} + +// RegisterChannel will return a registered channel with function name and return a function to deregister it and close the channel at the end +func (n *NotifierListener) RegisterChannel(name string, argNumber int, exemplar interface{}) (<-chan interface{}, func()) { + t := reflect.TypeOf(exemplar) + channel := make(chan interface{}, 10) + callback := func(_ string, args [][]byte) { + n := reflect.New(t).Elem() + err := json.Unmarshal(args[argNumber], n.Addr().Interface()) + if err != nil { + log.Error("Wrong Argument passed to register channel: %v ", err) + } + channel <- n.Interface() + } + n.Register(name, &callback) + + return channel, func() { + n.Deregister(name, &callback) + close(channel) + } +} + +func (n *NotifierListener) handle(data ...queue.Data) { + n.lock.RLock() + defer n.lock.RUnlock() + for _, datum := range data { + call := datum.(*base.FunctionCall) + callbacks, ok := n.callbacks[call.Name] + if ok && len(callbacks) > 0 { + for _, callback := range callbacks { + (*callback)(call.Name, call.Args) + } + } + } +} + +func TestNotifierListener(t *testing.T) { + defer prepareTestEnv(t)() + + createPullNotified, deregister := notifierListener.RegisterChannel("NotifyNewPullRequest", 0, &models.PullRequest{}) + + bs, _ := json.Marshal(&models.PullRequest{}) + notifierListener.handle(&base.FunctionCall{ + Name: "NotifyNewPullRequest", + Args: [][]byte{ + bs, + }, + }) + <-createPullNotified + + notifierListener.notifier.NotifyNewPullRequest(&models.PullRequest{}) + <-createPullNotified + + notification.NotifyNewPullRequest(&models.PullRequest{}) + <-createPullNotified + + deregister() + + notification.NotifyNewPullRequest(&models.PullRequest{}) + // would panic if not deregistered +} diff --git a/integrations/pgsql.ini.tmpl b/integrations/pgsql.ini.tmpl index 80258437e54c7..fbe7b04311fdd 100644 --- a/integrations/pgsql.ini.tmpl +++ b/integrations/pgsql.ini.tmpl @@ -83,3 +83,10 @@ LEVEL = Debug INSTALL_LOCK = true SECRET_KEY = 9pCviYTWSb INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTU1NTE2MTh9.hhSVGOANkaKk3vfCd2jDOIww4pUk0xtg9JRde5UogyQ + +[queue] +TYPE=channel + +[queue.test-notifier] +BATCH_LENGTH=1 +LENGTH=20 diff --git a/integrations/pull_merge_test.go b/integrations/pull_merge_test.go index b5ac9406aceef..ced959c2294e5 100644 --- a/integrations/pull_merge_test.go +++ b/integrations/pull_merge_test.go @@ -59,33 +59,67 @@ func testPullCleanUp(t *testing.T, session *TestSession, user, repo, pullnum str return resp } +func checkChannelWithTimeout(c <-chan interface{}, timeout time.Duration, callback func(interface{}) bool) bool { + timer := time.NewTimer(500 * time.Millisecond) + for { + select { + case received := <-c: + if callback(received) { + if !timer.Stop() { + select { + case <-timer.C: + default: + } + } + return true + } + case <-timer.C: + return false + } + } +} + func TestPullMerge(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { - hookTasks, err := models.HookTasks(1, 1) //Retrieve previous hook number - assert.NoError(t, err) - hookTasksLenBefore := len(hookTasks) + createPullNotified, unregisterNewPull := notifierListener.RegisterChannel("NotifyNewPullRequest", 0, &models.PullRequest{}) + defer unregisterNewPull() + + mergePullNotified, unregisterMergePull := notifierListener.RegisterChannel("NotifyMergePullRequest", 0, &models.PullRequest{}) + defer unregisterMergePull() session := loginUser(t, "user1") - testRepoFork(t, session, "user2", "repo1", "user1", "repo1") - testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") + testRepoFork(t, session, "user2", "repo1", "user1", "repo1-TestPullMerge") + testEditFile(t, session, "user1", "repo1-TestPullMerge", "master", "README.md", "Hello, World (Edited)\n") - resp := testPullCreate(t, session, "user1", "repo1", "master", "This is a pull title") + resp := testPullCreate(t, session, "user1", "repo1-TestPullMerge", "master", "This is a pull title") + + isOurPR := func(received interface{}) bool { + pr := received.(*models.PullRequest) + pr.LoadBaseRepo() + pr.LoadHeadRepo() + return pr.BaseRepo.FullName() == "user2/repo1" && + pr.BaseBranch == "master" && + pr.HeadRepo.FullName() == "user1/repo1-TestPullMerge" && + pr.HeadBranch == "master" + } + + assert.True(t, checkChannelWithTimeout(createPullNotified, 500*time.Millisecond, isOurPR), "Failed to be notified pull created") elem := strings.Split(test.RedirectURL(resp), "/") assert.EqualValues(t, "pulls", elem[3]) + testPullMerge(t, session, elem[1], elem[2], elem[4], models.MergeStyleMerge) + assert.True(t, checkChannelWithTimeout(mergePullNotified, 500*time.Millisecond, isOurPR), "Failed to be notified pull merged") - hookTasks, err = models.HookTasks(1, 1) - assert.NoError(t, err) - assert.Len(t, hookTasks, hookTasksLenBefore+1) + assert.False(t, checkChannelWithTimeout(createPullNotified, 100*time.Millisecond, isOurPR), "Duplicate notified pull created") + assert.False(t, checkChannelWithTimeout(mergePullNotified, 100*time.Millisecond, isOurPR), "Duplicate notified pull merged") }) } func TestPullRebase(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { - hookTasks, err := models.HookTasks(1, 1) //Retrieve previous hook number - assert.NoError(t, err) - hookTasksLenBefore := len(hookTasks) + mergePullNotified, deferable := notifierListener.RegisterChannel("NotifyMergePullRequest", 0, &models.PullRequest{}) + defer deferable() session := loginUser(t, "user1") testRepoFork(t, session, "user2", "repo1", "user1", "repo1") @@ -96,18 +130,18 @@ func TestPullRebase(t *testing.T) { elem := strings.Split(test.RedirectURL(resp), "/") assert.EqualValues(t, "pulls", elem[3]) testPullMerge(t, session, elem[1], elem[2], elem[4], models.MergeStyleRebase) - - hookTasks, err = models.HookTasks(1, 1) - assert.NoError(t, err) - assert.Len(t, hookTasks, hookTasksLenBefore+1) + select { + case <-mergePullNotified: + case <-time.After(500 * time.Millisecond): + assert.Fail(t, "Took too long to notify!") + } }) } func TestPullRebaseMerge(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { - hookTasks, err := models.HookTasks(1, 1) //Retrieve previous hook number - assert.NoError(t, err) - hookTasksLenBefore := len(hookTasks) + mergePullNotified, deferable := notifierListener.RegisterChannel("NotifyMergePullRequest", 0, &models.PullRequest{}) + defer deferable() session := loginUser(t, "user1") testRepoFork(t, session, "user2", "repo1", "user1", "repo1") @@ -119,17 +153,18 @@ func TestPullRebaseMerge(t *testing.T) { assert.EqualValues(t, "pulls", elem[3]) testPullMerge(t, session, elem[1], elem[2], elem[4], models.MergeStyleRebaseMerge) - hookTasks, err = models.HookTasks(1, 1) - assert.NoError(t, err) - assert.Len(t, hookTasks, hookTasksLenBefore+1) + select { + case <-mergePullNotified: + case <-time.After(500 * time.Millisecond): + assert.Fail(t, "Took too long to notify!") + } }) } func TestPullSquash(t *testing.T) { onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { - hookTasks, err := models.HookTasks(1, 1) //Retrieve previous hook number - assert.NoError(t, err) - hookTasksLenBefore := len(hookTasks) + mergePullNotified, deferable := notifierListener.RegisterChannel("NotifyMergePullRequest", 0, &models.PullRequest{}) + defer deferable() session := loginUser(t, "user1") testRepoFork(t, session, "user2", "repo1", "user1", "repo1") @@ -142,9 +177,11 @@ func TestPullSquash(t *testing.T) { assert.EqualValues(t, "pulls", elem[3]) testPullMerge(t, session, elem[1], elem[2], elem[4], models.MergeStyleSquash) - hookTasks, err = models.HookTasks(1, 1) - assert.NoError(t, err) - assert.Len(t, hookTasks, hookTasksLenBefore+1) + select { + case <-mergePullNotified: + case <-time.After(500 * time.Millisecond): + assert.Fail(t, "Took too long to notify!") + } }) } diff --git a/integrations/sqlite.ini.tmpl b/integrations/sqlite.ini.tmpl index 38736818428a0..f347cd3aa3ade 100644 --- a/integrations/sqlite.ini.tmpl +++ b/integrations/sqlite.ini.tmpl @@ -80,3 +80,11 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTI3OTU5ODN9.O [oauth2] JWT_SECRET = KZb_QLUd4fYVyxetjxC4eZkrBgWM2SndOOWDNtgUUko + +[queue] +TYPE=channel + +[queue.test-notifier] +BATCH_LENGTH=1 +LENGTH=20 + diff --git a/models/issue.go b/models/issue.go index d9f8e929c7b75..350d06ccbf323 100644 --- a/models/issue.go +++ b/models/issue.go @@ -47,7 +47,7 @@ type Issue struct { IsClosed bool `xorm:"INDEX"` IsRead bool `xorm:"-"` IsPull bool `xorm:"INDEX"` // Indicates whether is a pull request or not. - PullRequest *PullRequest `xorm:"-"` + PullRequest *PullRequest `xorm:"-" json:"-"` NumComments int Ref string diff --git a/models/repo_unit.go b/models/repo_unit.go index 42ce8f6c8dc98..c7a56cf8ac2e4 100644 --- a/models/repo_unit.go +++ b/models/repo_unit.go @@ -6,6 +6,8 @@ package models import ( "encoding/json" + "fmt" + "reflect" "code.gitea.io/gitea/modules/timeutil" @@ -169,6 +171,57 @@ func (r *RepoUnit) ExternalTrackerConfig() *ExternalTrackerConfig { return r.Config.(*ExternalTrackerConfig) } +// MarshalJSON implements json.Marshaler +func (r *RepoUnit) MarshalJSON() ([]byte, error) { + tmp := map[string]interface{}{} + tmp["ID"] = r.ID + tmp["RepoID"] = r.RepoID + var err error + tmp["Config"], err = r.Config.ToDB() + if err != nil { + return nil, err + } + tmp["CreatedUnix"] = r.CreatedUnix + bs, err := json.Marshal(tmp) + return bs, err +} + +// UnmarshalJSON implements json.UnMarshaler +func (r *RepoUnit) UnmarshalJSON(bs []byte) (err error) { + tmp := struct { + ID int64 + RepoID int64 + Type UnitType + Config []byte + CreatedUnix timeutil.TimeStamp + }{} + err = json.Unmarshal(bs, &tmp) + if err != nil { + return err + } + + r.ID = tmp.ID + r.RepoID = tmp.RepoID + r.Type = tmp.Type + if r.Type != 0 { + defer func() { + panicked := recover() + if panicked == nil { + return + } + // Panicing is not very nice... + err = fmt.Errorf("%v", panicked) + r.Config = new(UnitConfig) + }() + typeInt64 := int64(r.Type) + typeInterface := reflect.ValueOf(typeInt64).Interface() + r.BeforeSet("type", xorm.Cell(&typeInterface)) + return json.Unmarshal(tmp.Config, &(r.Config)) + } + r.Config = new(UnitConfig) + return nil +} + func getUnitsByRepoID(e Engine, repoID int64) (units []*RepoUnit, err error) { var tmpUnits []*RepoUnit if err := e.Where("repo_id = ?", repoID).Find(&tmpUnits); err != nil { diff --git a/models/user.go b/models/user.go index 01cce2506d23e..0a1d298039ccd 100644 --- a/models/user.go +++ b/models/user.go @@ -114,9 +114,9 @@ type User struct { LoginSource int64 `xorm:"NOT NULL DEFAULT 0"` LoginName string Type UserType - OwnedOrgs []*User `xorm:"-"` - Orgs []*User `xorm:"-"` - Repos []*Repository `xorm:"-"` + OwnedOrgs []*User `xorm:"-" json:"-"` + Orgs []*User `xorm:"-" json:"-"` + Repos []*Repository `xorm:"-" json:"-"` Location string Website string Rands string `xorm:"VARCHAR(10)"` @@ -156,9 +156,9 @@ type User struct { // For organization NumTeams int NumMembers int - Teams []*Team `xorm:"-"` - Members UserList `xorm:"-"` - MembersIsPublic map[int64]bool `xorm:"-"` + Teams []*Team `xorm:"-" json:"-"` + Members UserList `xorm:"-" json:"-"` + MembersIsPublic map[int64]bool `xorm:"-" json:"-"` Visibility structs.VisibleType `xorm:"NOT NULL DEFAULT 0"` RepoAdminChangeTeamAccess bool `xorm:"NOT NULL DEFAULT false"` diff --git a/modules/convert/pull.go b/modules/convert/pull.go index 6ff88c4d8aac2..6df6aed8f54d2 100644 --- a/modules/convert/pull.go +++ b/modules/convert/pull.go @@ -25,6 +25,10 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest { err error ) + if pr.Issue.PullRequest == nil { + pr.Issue.PullRequest = pr + } + if err = pr.Issue.LoadRepo(); err != nil { log.Error("pr.Issue.LoadRepo[%d]: %v", pr.ID, err) return nil diff --git a/modules/notification/base/main.go b/modules/notification/base/main.go new file mode 100644 index 0000000000000..18e61963509c1 --- /dev/null +++ b/modules/notification/base/main.go @@ -0,0 +1,312 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +// +build ignore + +package main + +import ( + "bytes" + "fmt" + "go/ast" + "go/format" + "go/parser" + "go/token" + "io/ioutil" + "sort" + "strings" + "text/template" + "time" +) + +// funcDef are a semi-generic function definitions +type funcDef struct { + Name string + Args []funcDefArg +} + +// funcDefArg describe an argument to a function +type funcDefArg struct { + Name string + Type string +} + +// main will generate two files that implement the Notifier interface +// defined in notifier.go +// +// * the NullNotifier which is a basic Notifier that does nothing +// when each of its methods is called +// +// * the QueueNotifier which is a notifier that sends its commands down +// a queue. +// +// The main benefit of this generation is that we never need to keep these +// up to date again. Add a new function to Notifier and the NullNotifier and +// the NotifierQueue will gain these functions automatically. +// +// There are two caveat: +// * All notifier functions must not return anything. +// * If you add a new import you will need to add it to the templates below +func main() { + + // OK build the AST from the notifier.go file + fset := token.NewFileSet() // positions are relative to fset + f, err := parser.ParseFile(fset, "notifier.go", nil, 0) + if err != nil { + panic(err) + } + + // func will collect all the function definitions from the Notifier interface + funcs := make([]funcDef, 0) + + ast.Inspect(f, func(n ast.Node) bool { + spec, ok := n.(*ast.TypeSpec) + if !ok || spec.Name.Name != "Notifier" { // We only care about the Notifier interface declaration + return true // If we are not a type decl or aren't looking at the Notifier decl keep looking + } + + // We're at: `type Notifier ...` so now we need check that it's an interface + child, ok := spec.Type.(*ast.InterfaceType) + if !ok { + return false // There's no point looking in non interface types. + } + + // OK we're in the declaration of the Notifier, e.g. + // type Notifier interface { ... } + + // Let's look at each Method in turn, but first we redefine + // funcs now we know how big it's supposed to be + funcs = make([]funcDef, len(child.Methods.List)) + for i, method := range child.Methods.List { + // example: NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) + + // method here is looking at the NotifyPushCommits... + + // We know that interfaces have FuncType for the method + methodFuncDef := method.Type.(*ast.FuncType) // eg. (...) + + // Extract the function definition from the method + def := funcDef{} + def.Name = method.Names[0].Name // methods only have one name in interfaces <- NotifyPushCommits + + // Now construct the args + def.Args = make([]funcDefArg, 0, len(methodFuncDef.Params.List)) + for j, param := range methodFuncDef.Params.List { + + // interfaces don't have to name their arguments e.g. NotifyNewIssue(*models.Issue) + // but we need a name to make a function call + defaultName := fmt.Sprintf("unknown%d", j) + + // Now get the type - here we will just use what is used in source file. (See caveat 2.) + sb := strings.Builder{} + format.Node(&sb, fset, param.Type) + + // If our parameter is unnamed + if len(param.Names) == 0 { + def.Args = append(def.Args, funcDefArg{ + Name: defaultName, + Type: sb.String(), + }) + } else { + // Now in the example NotifyPushCommits we see that refname, oldCommitID etc don't have type following them + // The AST creates these as a single param with mulitple names + // Therefore iterate through the param.Names + for _, ident := range param.Names { + def.Args = append(def.Args, funcDefArg{ + Name: ident.Name, + Type: sb.String(), + }) + } + } + } + funcs[i] = def + } + + // We're done so stop walking + return false + }) + + sort.Slice(funcs, func(i, j int) bool { + return funcs[i].Name < funcs[j].Name + }) + + // First lets create the NullNotifier + buf := bytes.Buffer{} + nullTemplate.Execute(&buf, struct { + Timestamp time.Time + Funcs []funcDef + }{ + Timestamp: time.Now(), + Funcs: funcs, + }) + + bs, err := format.Source(buf.Bytes()) + if err != nil { + panic(err) + } + + err = ioutil.WriteFile("null.go", bs, 0644) + if err != nil { + panic(err) + } + + // Then create the NotifierQueue + buf = bytes.Buffer{} + queueTemplate.Execute(&buf, struct { + Timestamp time.Time + Funcs []funcDef + }{ + Timestamp: time.Now(), + Funcs: funcs, + }) + + bs, err = format.Source(buf.Bytes()) + if err != nil { + ioutil.WriteFile("queue.go", buf.Bytes(), 0644) + panic(err) + } + + err = ioutil.WriteFile("queue.go", bs, 0644) + if err != nil { + panic(err) + } + +} + +var queueTemplate = template.Must(template.New("").Parse(`// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. +// Code generated by go generate; DO NOT EDIT. +package base + +import ( + "encoding/json" + + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/graceful" + "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/repository" + "code.gitea.io/gitea/modules/queue" +) + +// FunctionCall represents a function call with json.Marshaled arguments +type FunctionCall struct { + Name string + Args [][]byte +} + +// QueueNotifier is a notifier queue +type QueueNotifier struct { + name string + notifiers []Notifier + internal queue.Queue +} + +// Ensure that QueueNotifier fulfils the Notifier interface +var ( + _ Notifier = &QueueNotifier{} +) + +// NewQueueNotifier creates a notifier that queues notifications and on dequeueing sends them to the provided notifiers +func NewQueueNotifier(name string, notifiers []Notifier) Notifier { + q := &QueueNotifier{ + name: name, + notifiers: notifiers, + } + q.internal = queue.CreateQueue(name, q.handle, &FunctionCall{}) + return q +} + +// NewQueueNotifierWithHandle creates a notifier queue with a specific handler function +func NewQueueNotifierWithHandle(name string, handle queue.HandlerFunc) Notifier { + q := &QueueNotifier{ + name: name, + } + q.internal = queue.CreateQueue(name, handle, &FunctionCall{}) + return q +} + +func (q *QueueNotifier) handle(data ...queue.Data) { + for _, datum := range data { + call := datum.(*FunctionCall) + var err error + switch call.Name { + {{- range .Funcs }} + case "{{.Name}}": + {{$p := .Name}} + {{- range $i, $e := .Args }} + var {{$e.Name}} {{$e.Type}} + err = json.Unmarshal(call.Args[{{$i}}], &{{$e.Name}}) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[{{$i}}]), "{{$e.Type}}", "{{$p}}", err) + continue + } + {{- end }} + for _, notifier := range q.notifiers { + notifier.{{.Name}}({{- range $i, $e := .Args}}{{ if $i }}, {{ end }}{{$e.Name}}{{end}}) + } + {{- end }} + default: + log.Error("Unknown notifier function %s with %d arguments", call.Name, len(call.Args)) + } + } +} + +func (q *QueueNotifier) Run() { + for _, notifier := range q.notifiers { + go notifier.Run() + } + graceful.GetManager().RunWithShutdownFns(q.internal.Run) +} +{{- range .Funcs}} +{{if ne .Name "Run"}} + +// {{ .Name }} is a placeholder function +func (q *QueueNotifier) {{ .Name }}({{ range $i, $e := .Args }}{{ if $i }}, {{ end }}{{$e.Name}} {{$e.Type}}{{end}}) { + args := make([][]byte, 0) + var err error + var bs []byte + {{- range .Args }} + bs, err = json.Marshal(&{{.Name}}) + if err != nil { + log.Error("Unable to marshall {{.Name}}: %v", err) + return + } + args = append(args, bs) + {{- end }} + + q.internal.Push(&FunctionCall{ + Name: "{{.Name}}", + Args: args, + }) +} +{{end}} +{{- end }} +`)) + +var nullTemplate = template.Must(template.New("").Parse(`// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. +// Code generated by go generate; DO NOT EDIT. +package base + +import ( + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/repository" +) + +// NullNotifier implements a blank notifier +type NullNotifier struct { +} + +// Ensure that NullNotifier fulfils the Notifier interface +var ( + _ Notifier = &NullNotifier{} +) +{{- range .Funcs}} + +// {{ .Name }} is a placeholder function +func (*NullNotifier) {{ .Name }}({{ range $i, $e := .Args }}{{ if $i }}, {{ end }}{{$e.Name}} {{$e.Type}}{{end}}) {} +{{- end }} +`)) diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go index 0b3e1173b3f05..75016619548f2 100644 --- a/modules/notification/base/notifier.go +++ b/modules/notification/base/notifier.go @@ -9,6 +9,10 @@ import ( "code.gitea.io/gitea/modules/repository" ) +//go:generate go run -mod=vendor main.go + +// If you change the below definition you must run go generate - see main.go + // Notifier defines an interface to notify receiver type Notifier interface { Run() diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go index d2fd51d713b82..496bedd61c611 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -1,7 +1,7 @@ -// Copyright 2019 The Gitea Authors. All rights reserved. +// Copyright 2020 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. - +// Code generated by go generate; DO NOT EDIT. package base import ( @@ -13,140 +13,128 @@ import ( type NullNotifier struct { } +// Ensure that NullNotifier fulfils the Notifier interface var ( _ Notifier = &NullNotifier{} ) -// Run places a place holder function -func (*NullNotifier) Run() { +// NotifyCreateIssueComment is a placeholder function +func (*NullNotifier) NotifyCreateIssueComment(unknown0 *models.User, unknown1 *models.Repository, unknown2 *models.Issue, unknown3 *models.Comment) { } -// NotifyCreateIssueComment places a place holder function -func (*NullNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository, - issue *models.Issue, comment *models.Comment) { +// NotifyCreateRef is a placeholder function +func (*NullNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { } -// NotifyNewIssue places a place holder function -func (*NullNotifier) NotifyNewIssue(issue *models.Issue) { +// NotifyCreateRepository is a placeholder function +func (*NullNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) { } -// NotifyIssueChangeStatus places a place holder function -func (*NullNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, actionComment *models.Comment, isClosed bool) { -} +// NotifyDeleteComment is a placeholder function +func (*NullNotifier) NotifyDeleteComment(unknown0 *models.User, unknown1 *models.Comment) {} -// NotifyNewPullRequest places a place holder function -func (*NullNotifier) NotifyNewPullRequest(pr *models.PullRequest) { +// NotifyDeleteRef is a placeholder function +func (*NullNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { } -// NotifyPullRequestReview places a place holder function -func (*NullNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment) { -} +// NotifyDeleteRelease is a placeholder function +func (*NullNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) {} -// NotifyMergePullRequest places a place holder function -func (*NullNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) { -} +// NotifyDeleteRepository is a placeholder function +func (*NullNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {} -// NotifyPullRequestSynchronized places a place holder function -func (*NullNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) { +// NotifyForkRepository is a placeholder function +func (*NullNotifier) NotifyForkRepository(doer *models.User, oldRepo *models.Repository, repo *models.Repository) { } -// NotifyPullRequestChangeTargetBranch places a place holder function -func (*NullNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) { +// NotifyIssueChangeAssignee is a placeholder function +func (*NullNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { } -// NotifyUpdateComment places a place holder function -func (*NullNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) { +// NotifyIssueChangeContent is a placeholder function +func (*NullNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { } -// NotifyDeleteComment places a place holder function -func (*NullNotifier) NotifyDeleteComment(doer *models.User, c *models.Comment) { +// NotifyIssueChangeLabels is a placeholder function +func (*NullNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, addedLabels []*models.Label, removedLabels []*models.Label) { } -// NotifyNewRelease places a place holder function -func (*NullNotifier) NotifyNewRelease(rel *models.Release) { +// NotifyIssueChangeMilestone is a placeholder function +func (*NullNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) { } -// NotifyUpdateRelease places a place holder function -func (*NullNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) { +// NotifyIssueChangeStatus is a placeholder function +func (*NullNotifier) NotifyIssueChangeStatus(unknown0 *models.User, unknown1 *models.Issue, unknown2 *models.Comment, unknown3 bool) { } -// NotifyDeleteRelease places a place holder function -func (*NullNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) { +// NotifyIssueChangeTitle is a placeholder function +func (*NullNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) { } -// NotifyIssueChangeMilestone places a place holder function -func (*NullNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) { -} +// NotifyIssueClearLabels is a placeholder function +func (*NullNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {} -// NotifyIssueChangeContent places a place holder function -func (*NullNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { -} +// NotifyMergePullRequest is a placeholder function +func (*NullNotifier) NotifyMergePullRequest(unknown0 *models.PullRequest, unknown1 *models.User) {} -// NotifyIssueChangeAssignee places a place holder function -func (*NullNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { +// NotifyMigrateRepository is a placeholder function +func (*NullNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) { } -// NotifyPullReviewRequest places a place holder function -func (*NullNotifier) NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) { -} +// NotifyNewIssue is a placeholder function +func (*NullNotifier) NotifyNewIssue(unknown0 *models.Issue) {} -// NotifyIssueClearLabels places a place holder function -func (*NullNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) { -} +// NotifyNewPullRequest is a placeholder function +func (*NullNotifier) NotifyNewPullRequest(unknown0 *models.PullRequest) {} -// NotifyIssueChangeTitle places a place holder function -func (*NullNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) { -} +// NotifyNewRelease is a placeholder function +func (*NullNotifier) NotifyNewRelease(rel *models.Release) {} -// NotifyIssueChangeLabels places a place holder function -func (*NullNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, - addedLabels []*models.Label, removedLabels []*models.Label) { +// NotifyPullRequestChangeTargetBranch is a placeholder function +func (*NullNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) { } -// NotifyCreateRepository places a place holder function -func (*NullNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) { +// NotifyPullRequestReview is a placeholder function +func (*NullNotifier) NotifyPullRequestReview(unknown0 *models.PullRequest, unknown1 *models.Review, unknown2 *models.Comment) { } -// NotifyDeleteRepository places a place holder function -func (*NullNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) { -} +// NotifyPullRequestSynchronized is a placeholder function +func (*NullNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) {} -// NotifyForkRepository places a place holder function -func (*NullNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) { +// NotifyPullReviewRequest is a placeholder function +func (*NullNotifier) NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) { } -// NotifyMigrateRepository places a place holder function -func (*NullNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) { +// NotifyPushCommits is a placeholder function +func (*NullNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName string, oldCommitID string, newCommitID string, commits *repository.PushCommits) { } -// NotifyPushCommits notifies commits pushed to notifiers -func (*NullNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) { +// NotifyRenameRepository is a placeholder function +func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { } -// NotifyCreateRef notifies branch or tag creation to notifiers -func (*NullNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) { +// NotifySyncCreateRef is a placeholder function +func (*NullNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { } -// NotifyDeleteRef notifies branch or tag deleteion to notifiers -func (*NullNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) { +// NotifySyncDeleteRef is a placeholder function +func (*NullNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { } -// NotifyRenameRepository places a place holder function -func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { +// NotifySyncPushCommits is a placeholder function +func (*NullNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName string, oldCommitID string, newCommitID string, commits *repository.PushCommits) { } -// NotifyTransferRepository places a place holder function +// NotifyTransferRepository is a placeholder function func (*NullNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { } -// NotifySyncPushCommits places a place holder function -func (*NullNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) { +// NotifyUpdateComment is a placeholder function +func (*NullNotifier) NotifyUpdateComment(unknown0 *models.User, unknown1 *models.Comment, unknown2 string) { } -// NotifySyncCreateRef places a place holder function -func (*NullNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) { -} +// NotifyUpdateRelease is a placeholder function +func (*NullNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {} -// NotifySyncDeleteRef places a place holder function -func (*NullNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) { -} +// Run is a placeholder function +func (*NullNotifier) Run() {} diff --git a/modules/notification/base/queue.go b/modules/notification/base/queue.go new file mode 100644 index 0000000000000..ad2b172c5a57b --- /dev/null +++ b/modules/notification/base/queue.go @@ -0,0 +1,1819 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. +// Code generated by go generate; DO NOT EDIT. +package base + +import ( + "encoding/json" + + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/graceful" + "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/queue" + "code.gitea.io/gitea/modules/repository" +) + +// FunctionCall represents a function call with json.Marshaled arguments +type FunctionCall struct { + Name string + Args [][]byte +} + +// QueueNotifier is a notifier queue +type QueueNotifier struct { + name string + notifiers []Notifier + internal queue.Queue +} + +// Ensure that QueueNotifier fulfils the Notifier interface +var ( + _ Notifier = &QueueNotifier{} +) + +// NewQueueNotifier creates a notifier that queues notifications and on dequeueing sends them to the provided notifiers +func NewQueueNotifier(name string, notifiers []Notifier) Notifier { + q := &QueueNotifier{ + name: name, + notifiers: notifiers, + } + q.internal = queue.CreateQueue(name, q.handle, &FunctionCall{}) + return q +} + +// NewQueueNotifierWithHandle creates a notifier queue with a specific handler function +func NewQueueNotifierWithHandle(name string, handle queue.HandlerFunc) Notifier { + q := &QueueNotifier{ + name: name, + } + q.internal = queue.CreateQueue(name, handle, &FunctionCall{}) + return q +} + +func (q *QueueNotifier) handle(data ...queue.Data) { + for _, datum := range data { + call := datum.(*FunctionCall) + var err error + switch call.Name { + case "NotifyCreateIssueComment": + + var unknown0 *models.User + err = json.Unmarshal(call.Args[0], &unknown0) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyCreateIssueComment", err) + continue + } + var unknown1 *models.Repository + err = json.Unmarshal(call.Args[1], &unknown1) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyCreateIssueComment", err) + continue + } + var unknown2 *models.Issue + err = json.Unmarshal(call.Args[2], &unknown2) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "*models.Issue", "NotifyCreateIssueComment", err) + continue + } + var unknown3 *models.Comment + err = json.Unmarshal(call.Args[3], &unknown3) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[3]), "*models.Comment", "NotifyCreateIssueComment", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyCreateIssueComment(unknown0, unknown1, unknown2, unknown3) + } + case "NotifyCreateRef": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyCreateRef", err) + continue + } + var repo *models.Repository + err = json.Unmarshal(call.Args[1], &repo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyCreateRef", err) + continue + } + var refType string + err = json.Unmarshal(call.Args[2], &refType) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifyCreateRef", err) + continue + } + var refFullName string + err = json.Unmarshal(call.Args[3], &refFullName) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[3]), "string", "NotifyCreateRef", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyCreateRef(doer, repo, refType, refFullName) + } + case "NotifyCreateRepository": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyCreateRepository", err) + continue + } + var u *models.User + err = json.Unmarshal(call.Args[1], &u) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.User", "NotifyCreateRepository", err) + continue + } + var repo *models.Repository + err = json.Unmarshal(call.Args[2], &repo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "*models.Repository", "NotifyCreateRepository", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyCreateRepository(doer, u, repo) + } + case "NotifyDeleteComment": + + var unknown0 *models.User + err = json.Unmarshal(call.Args[0], &unknown0) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyDeleteComment", err) + continue + } + var unknown1 *models.Comment + err = json.Unmarshal(call.Args[1], &unknown1) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Comment", "NotifyDeleteComment", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyDeleteComment(unknown0, unknown1) + } + case "NotifyDeleteRef": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyDeleteRef", err) + continue + } + var repo *models.Repository + err = json.Unmarshal(call.Args[1], &repo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyDeleteRef", err) + continue + } + var refType string + err = json.Unmarshal(call.Args[2], &refType) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifyDeleteRef", err) + continue + } + var refFullName string + err = json.Unmarshal(call.Args[3], &refFullName) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[3]), "string", "NotifyDeleteRef", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyDeleteRef(doer, repo, refType, refFullName) + } + case "NotifyDeleteRelease": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyDeleteRelease", err) + continue + } + var rel *models.Release + err = json.Unmarshal(call.Args[1], &rel) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Release", "NotifyDeleteRelease", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyDeleteRelease(doer, rel) + } + case "NotifyDeleteRepository": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyDeleteRepository", err) + continue + } + var repo *models.Repository + err = json.Unmarshal(call.Args[1], &repo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyDeleteRepository", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyDeleteRepository(doer, repo) + } + case "NotifyForkRepository": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyForkRepository", err) + continue + } + var oldRepo *models.Repository + err = json.Unmarshal(call.Args[1], &oldRepo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyForkRepository", err) + continue + } + var repo *models.Repository + err = json.Unmarshal(call.Args[2], &repo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "*models.Repository", "NotifyForkRepository", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyForkRepository(doer, oldRepo, repo) + } + case "NotifyIssueChangeAssignee": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyIssueChangeAssignee", err) + continue + } + var issue *models.Issue + err = json.Unmarshal(call.Args[1], &issue) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Issue", "NotifyIssueChangeAssignee", err) + continue + } + var assignee *models.User + err = json.Unmarshal(call.Args[2], &assignee) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "*models.User", "NotifyIssueChangeAssignee", err) + continue + } + var removed bool + err = json.Unmarshal(call.Args[3], &removed) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[3]), "bool", "NotifyIssueChangeAssignee", err) + continue + } + var comment *models.Comment + err = json.Unmarshal(call.Args[4], &comment) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[4]), "*models.Comment", "NotifyIssueChangeAssignee", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyIssueChangeAssignee(doer, issue, assignee, removed, comment) + } + case "NotifyIssueChangeContent": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyIssueChangeContent", err) + continue + } + var issue *models.Issue + err = json.Unmarshal(call.Args[1], &issue) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Issue", "NotifyIssueChangeContent", err) + continue + } + var oldContent string + err = json.Unmarshal(call.Args[2], &oldContent) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifyIssueChangeContent", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyIssueChangeContent(doer, issue, oldContent) + } + case "NotifyIssueChangeLabels": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyIssueChangeLabels", err) + continue + } + var issue *models.Issue + err = json.Unmarshal(call.Args[1], &issue) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Issue", "NotifyIssueChangeLabels", err) + continue + } + var addedLabels []*models.Label + err = json.Unmarshal(call.Args[2], &addedLabels) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "[]*models.Label", "NotifyIssueChangeLabels", err) + continue + } + var removedLabels []*models.Label + err = json.Unmarshal(call.Args[3], &removedLabels) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[3]), "[]*models.Label", "NotifyIssueChangeLabels", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels) + } + case "NotifyIssueChangeMilestone": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyIssueChangeMilestone", err) + continue + } + var issue *models.Issue + err = json.Unmarshal(call.Args[1], &issue) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Issue", "NotifyIssueChangeMilestone", err) + continue + } + var oldMilestoneID int64 + err = json.Unmarshal(call.Args[2], &oldMilestoneID) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "int64", "NotifyIssueChangeMilestone", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID) + } + case "NotifyIssueChangeStatus": + + var unknown0 *models.User + err = json.Unmarshal(call.Args[0], &unknown0) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyIssueChangeStatus", err) + continue + } + var unknown1 *models.Issue + err = json.Unmarshal(call.Args[1], &unknown1) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Issue", "NotifyIssueChangeStatus", err) + continue + } + var unknown2 *models.Comment + err = json.Unmarshal(call.Args[2], &unknown2) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "*models.Comment", "NotifyIssueChangeStatus", err) + continue + } + var unknown3 bool + err = json.Unmarshal(call.Args[3], &unknown3) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[3]), "bool", "NotifyIssueChangeStatus", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyIssueChangeStatus(unknown0, unknown1, unknown2, unknown3) + } + case "NotifyIssueChangeTitle": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyIssueChangeTitle", err) + continue + } + var issue *models.Issue + err = json.Unmarshal(call.Args[1], &issue) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Issue", "NotifyIssueChangeTitle", err) + continue + } + var oldTitle string + err = json.Unmarshal(call.Args[2], &oldTitle) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifyIssueChangeTitle", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyIssueChangeTitle(doer, issue, oldTitle) + } + case "NotifyIssueClearLabels": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyIssueClearLabels", err) + continue + } + var issue *models.Issue + err = json.Unmarshal(call.Args[1], &issue) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Issue", "NotifyIssueClearLabels", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyIssueClearLabels(doer, issue) + } + case "NotifyMergePullRequest": + + var unknown0 *models.PullRequest + err = json.Unmarshal(call.Args[0], &unknown0) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.PullRequest", "NotifyMergePullRequest", err) + continue + } + var unknown1 *models.User + err = json.Unmarshal(call.Args[1], &unknown1) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.User", "NotifyMergePullRequest", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyMergePullRequest(unknown0, unknown1) + } + case "NotifyMigrateRepository": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyMigrateRepository", err) + continue + } + var u *models.User + err = json.Unmarshal(call.Args[1], &u) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.User", "NotifyMigrateRepository", err) + continue + } + var repo *models.Repository + err = json.Unmarshal(call.Args[2], &repo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "*models.Repository", "NotifyMigrateRepository", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyMigrateRepository(doer, u, repo) + } + case "NotifyNewIssue": + + var unknown0 *models.Issue + err = json.Unmarshal(call.Args[0], &unknown0) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.Issue", "NotifyNewIssue", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyNewIssue(unknown0) + } + case "NotifyNewPullRequest": + + var unknown0 *models.PullRequest + err = json.Unmarshal(call.Args[0], &unknown0) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.PullRequest", "NotifyNewPullRequest", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyNewPullRequest(unknown0) + } + case "NotifyNewRelease": + + var rel *models.Release + err = json.Unmarshal(call.Args[0], &rel) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.Release", "NotifyNewRelease", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyNewRelease(rel) + } + case "NotifyPullRequestChangeTargetBranch": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyPullRequestChangeTargetBranch", err) + continue + } + var pr *models.PullRequest + err = json.Unmarshal(call.Args[1], &pr) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.PullRequest", "NotifyPullRequestChangeTargetBranch", err) + continue + } + var oldBranch string + err = json.Unmarshal(call.Args[2], &oldBranch) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifyPullRequestChangeTargetBranch", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyPullRequestChangeTargetBranch(doer, pr, oldBranch) + } + case "NotifyPullRequestReview": + + var unknown0 *models.PullRequest + err = json.Unmarshal(call.Args[0], &unknown0) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.PullRequest", "NotifyPullRequestReview", err) + continue + } + var unknown1 *models.Review + err = json.Unmarshal(call.Args[1], &unknown1) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Review", "NotifyPullRequestReview", err) + continue + } + var unknown2 *models.Comment + err = json.Unmarshal(call.Args[2], &unknown2) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "*models.Comment", "NotifyPullRequestReview", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyPullRequestReview(unknown0, unknown1, unknown2) + } + case "NotifyPullRequestSynchronized": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyPullRequestSynchronized", err) + continue + } + var pr *models.PullRequest + err = json.Unmarshal(call.Args[1], &pr) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.PullRequest", "NotifyPullRequestSynchronized", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyPullRequestSynchronized(doer, pr) + } + case "NotifyPullReviewRequest": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyPullReviewRequest", err) + continue + } + var issue *models.Issue + err = json.Unmarshal(call.Args[1], &issue) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Issue", "NotifyPullReviewRequest", err) + continue + } + var reviewer *models.User + err = json.Unmarshal(call.Args[2], &reviewer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "*models.User", "NotifyPullReviewRequest", err) + continue + } + var isRequest bool + err = json.Unmarshal(call.Args[3], &isRequest) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[3]), "bool", "NotifyPullReviewRequest", err) + continue + } + var comment *models.Comment + err = json.Unmarshal(call.Args[4], &comment) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[4]), "*models.Comment", "NotifyPullReviewRequest", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyPullReviewRequest(doer, issue, reviewer, isRequest, comment) + } + case "NotifyPushCommits": + + var pusher *models.User + err = json.Unmarshal(call.Args[0], &pusher) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyPushCommits", err) + continue + } + var repo *models.Repository + err = json.Unmarshal(call.Args[1], &repo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyPushCommits", err) + continue + } + var refName string + err = json.Unmarshal(call.Args[2], &refName) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifyPushCommits", err) + continue + } + var oldCommitID string + err = json.Unmarshal(call.Args[3], &oldCommitID) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[3]), "string", "NotifyPushCommits", err) + continue + } + var newCommitID string + err = json.Unmarshal(call.Args[4], &newCommitID) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[4]), "string", "NotifyPushCommits", err) + continue + } + var commits *repository.PushCommits + err = json.Unmarshal(call.Args[5], &commits) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[5]), "*repository.PushCommits", "NotifyPushCommits", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyPushCommits(pusher, repo, refName, oldCommitID, newCommitID, commits) + } + case "NotifyRenameRepository": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyRenameRepository", err) + continue + } + var repo *models.Repository + err = json.Unmarshal(call.Args[1], &repo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyRenameRepository", err) + continue + } + var oldRepoName string + err = json.Unmarshal(call.Args[2], &oldRepoName) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifyRenameRepository", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyRenameRepository(doer, repo, oldRepoName) + } + case "NotifySyncCreateRef": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifySyncCreateRef", err) + continue + } + var repo *models.Repository + err = json.Unmarshal(call.Args[1], &repo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifySyncCreateRef", err) + continue + } + var refType string + err = json.Unmarshal(call.Args[2], &refType) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifySyncCreateRef", err) + continue + } + var refFullName string + err = json.Unmarshal(call.Args[3], &refFullName) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[3]), "string", "NotifySyncCreateRef", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifySyncCreateRef(doer, repo, refType, refFullName) + } + case "NotifySyncDeleteRef": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifySyncDeleteRef", err) + continue + } + var repo *models.Repository + err = json.Unmarshal(call.Args[1], &repo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifySyncDeleteRef", err) + continue + } + var refType string + err = json.Unmarshal(call.Args[2], &refType) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifySyncDeleteRef", err) + continue + } + var refFullName string + err = json.Unmarshal(call.Args[3], &refFullName) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[3]), "string", "NotifySyncDeleteRef", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifySyncDeleteRef(doer, repo, refType, refFullName) + } + case "NotifySyncPushCommits": + + var pusher *models.User + err = json.Unmarshal(call.Args[0], &pusher) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifySyncPushCommits", err) + continue + } + var repo *models.Repository + err = json.Unmarshal(call.Args[1], &repo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifySyncPushCommits", err) + continue + } + var refName string + err = json.Unmarshal(call.Args[2], &refName) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifySyncPushCommits", err) + continue + } + var oldCommitID string + err = json.Unmarshal(call.Args[3], &oldCommitID) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[3]), "string", "NotifySyncPushCommits", err) + continue + } + var newCommitID string + err = json.Unmarshal(call.Args[4], &newCommitID) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[4]), "string", "NotifySyncPushCommits", err) + continue + } + var commits *repository.PushCommits + err = json.Unmarshal(call.Args[5], &commits) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[5]), "*repository.PushCommits", "NotifySyncPushCommits", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifySyncPushCommits(pusher, repo, refName, oldCommitID, newCommitID, commits) + } + case "NotifyTransferRepository": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyTransferRepository", err) + continue + } + var repo *models.Repository + err = json.Unmarshal(call.Args[1], &repo) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyTransferRepository", err) + continue + } + var oldOwnerName string + err = json.Unmarshal(call.Args[2], &oldOwnerName) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifyTransferRepository", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyTransferRepository(doer, repo, oldOwnerName) + } + case "NotifyUpdateComment": + + var unknown0 *models.User + err = json.Unmarshal(call.Args[0], &unknown0) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyUpdateComment", err) + continue + } + var unknown1 *models.Comment + err = json.Unmarshal(call.Args[1], &unknown1) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Comment", "NotifyUpdateComment", err) + continue + } + var unknown2 string + err = json.Unmarshal(call.Args[2], &unknown2) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifyUpdateComment", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyUpdateComment(unknown0, unknown1, unknown2) + } + case "NotifyUpdateRelease": + + var doer *models.User + err = json.Unmarshal(call.Args[0], &doer) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyUpdateRelease", err) + continue + } + var rel *models.Release + err = json.Unmarshal(call.Args[1], &rel) + if err != nil { + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Release", "NotifyUpdateRelease", err) + continue + } + for _, notifier := range q.notifiers { + notifier.NotifyUpdateRelease(doer, rel) + } + case "Run": + + for _, notifier := range q.notifiers { + notifier.Run() + } + default: + log.Error("Unknown notifier function %s with %d arguments", call.Name, len(call.Args)) + } + } +} + +func (q *QueueNotifier) Run() { + for _, notifier := range q.notifiers { + go notifier.Run() + } + graceful.GetManager().RunWithShutdownFns(q.internal.Run) +} + +// NotifyCreateIssueComment is a placeholder function +func (q *QueueNotifier) NotifyCreateIssueComment(unknown0 *models.User, unknown1 *models.Repository, unknown2 *models.Issue, unknown3 *models.Comment) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&unknown0) + if err != nil { + log.Error("Unable to marshall unknown0: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&unknown1) + if err != nil { + log.Error("Unable to marshall unknown1: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&unknown2) + if err != nil { + log.Error("Unable to marshall unknown2: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&unknown3) + if err != nil { + log.Error("Unable to marshall unknown3: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyCreateIssueComment", + Args: args, + }) +} + +// NotifyCreateRef is a placeholder function +func (q *QueueNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&repo) + if err != nil { + log.Error("Unable to marshall repo: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&refType) + if err != nil { + log.Error("Unable to marshall refType: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&refFullName) + if err != nil { + log.Error("Unable to marshall refFullName: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyCreateRef", + Args: args, + }) +} + +// NotifyCreateRepository is a placeholder function +func (q *QueueNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&u) + if err != nil { + log.Error("Unable to marshall u: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&repo) + if err != nil { + log.Error("Unable to marshall repo: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyCreateRepository", + Args: args, + }) +} + +// NotifyDeleteComment is a placeholder function +func (q *QueueNotifier) NotifyDeleteComment(unknown0 *models.User, unknown1 *models.Comment) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&unknown0) + if err != nil { + log.Error("Unable to marshall unknown0: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&unknown1) + if err != nil { + log.Error("Unable to marshall unknown1: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyDeleteComment", + Args: args, + }) +} + +// NotifyDeleteRef is a placeholder function +func (q *QueueNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&repo) + if err != nil { + log.Error("Unable to marshall repo: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&refType) + if err != nil { + log.Error("Unable to marshall refType: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&refFullName) + if err != nil { + log.Error("Unable to marshall refFullName: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyDeleteRef", + Args: args, + }) +} + +// NotifyDeleteRelease is a placeholder function +func (q *QueueNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&rel) + if err != nil { + log.Error("Unable to marshall rel: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyDeleteRelease", + Args: args, + }) +} + +// NotifyDeleteRepository is a placeholder function +func (q *QueueNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&repo) + if err != nil { + log.Error("Unable to marshall repo: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyDeleteRepository", + Args: args, + }) +} + +// NotifyForkRepository is a placeholder function +func (q *QueueNotifier) NotifyForkRepository(doer *models.User, oldRepo *models.Repository, repo *models.Repository) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&oldRepo) + if err != nil { + log.Error("Unable to marshall oldRepo: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&repo) + if err != nil { + log.Error("Unable to marshall repo: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyForkRepository", + Args: args, + }) +} + +// NotifyIssueChangeAssignee is a placeholder function +func (q *QueueNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&issue) + if err != nil { + log.Error("Unable to marshall issue: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&assignee) + if err != nil { + log.Error("Unable to marshall assignee: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&removed) + if err != nil { + log.Error("Unable to marshall removed: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&comment) + if err != nil { + log.Error("Unable to marshall comment: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyIssueChangeAssignee", + Args: args, + }) +} + +// NotifyIssueChangeContent is a placeholder function +func (q *QueueNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&issue) + if err != nil { + log.Error("Unable to marshall issue: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&oldContent) + if err != nil { + log.Error("Unable to marshall oldContent: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyIssueChangeContent", + Args: args, + }) +} + +// NotifyIssueChangeLabels is a placeholder function +func (q *QueueNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, addedLabels []*models.Label, removedLabels []*models.Label) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&issue) + if err != nil { + log.Error("Unable to marshall issue: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&addedLabels) + if err != nil { + log.Error("Unable to marshall addedLabels: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&removedLabels) + if err != nil { + log.Error("Unable to marshall removedLabels: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyIssueChangeLabels", + Args: args, + }) +} + +// NotifyIssueChangeMilestone is a placeholder function +func (q *QueueNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&issue) + if err != nil { + log.Error("Unable to marshall issue: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&oldMilestoneID) + if err != nil { + log.Error("Unable to marshall oldMilestoneID: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyIssueChangeMilestone", + Args: args, + }) +} + +// NotifyIssueChangeStatus is a placeholder function +func (q *QueueNotifier) NotifyIssueChangeStatus(unknown0 *models.User, unknown1 *models.Issue, unknown2 *models.Comment, unknown3 bool) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&unknown0) + if err != nil { + log.Error("Unable to marshall unknown0: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&unknown1) + if err != nil { + log.Error("Unable to marshall unknown1: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&unknown2) + if err != nil { + log.Error("Unable to marshall unknown2: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&unknown3) + if err != nil { + log.Error("Unable to marshall unknown3: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyIssueChangeStatus", + Args: args, + }) +} + +// NotifyIssueChangeTitle is a placeholder function +func (q *QueueNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&issue) + if err != nil { + log.Error("Unable to marshall issue: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&oldTitle) + if err != nil { + log.Error("Unable to marshall oldTitle: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyIssueChangeTitle", + Args: args, + }) +} + +// NotifyIssueClearLabels is a placeholder function +func (q *QueueNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&issue) + if err != nil { + log.Error("Unable to marshall issue: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyIssueClearLabels", + Args: args, + }) +} + +// NotifyMergePullRequest is a placeholder function +func (q *QueueNotifier) NotifyMergePullRequest(unknown0 *models.PullRequest, unknown1 *models.User) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&unknown0) + if err != nil { + log.Error("Unable to marshall unknown0: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&unknown1) + if err != nil { + log.Error("Unable to marshall unknown1: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyMergePullRequest", + Args: args, + }) +} + +// NotifyMigrateRepository is a placeholder function +func (q *QueueNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&u) + if err != nil { + log.Error("Unable to marshall u: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&repo) + if err != nil { + log.Error("Unable to marshall repo: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyMigrateRepository", + Args: args, + }) +} + +// NotifyNewIssue is a placeholder function +func (q *QueueNotifier) NotifyNewIssue(unknown0 *models.Issue) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&unknown0) + if err != nil { + log.Error("Unable to marshall unknown0: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyNewIssue", + Args: args, + }) +} + +// NotifyNewPullRequest is a placeholder function +func (q *QueueNotifier) NotifyNewPullRequest(unknown0 *models.PullRequest) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&unknown0) + if err != nil { + log.Error("Unable to marshall unknown0: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyNewPullRequest", + Args: args, + }) +} + +// NotifyNewRelease is a placeholder function +func (q *QueueNotifier) NotifyNewRelease(rel *models.Release) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&rel) + if err != nil { + log.Error("Unable to marshall rel: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyNewRelease", + Args: args, + }) +} + +// NotifyPullRequestChangeTargetBranch is a placeholder function +func (q *QueueNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&pr) + if err != nil { + log.Error("Unable to marshall pr: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&oldBranch) + if err != nil { + log.Error("Unable to marshall oldBranch: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyPullRequestChangeTargetBranch", + Args: args, + }) +} + +// NotifyPullRequestReview is a placeholder function +func (q *QueueNotifier) NotifyPullRequestReview(unknown0 *models.PullRequest, unknown1 *models.Review, unknown2 *models.Comment) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&unknown0) + if err != nil { + log.Error("Unable to marshall unknown0: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&unknown1) + if err != nil { + log.Error("Unable to marshall unknown1: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&unknown2) + if err != nil { + log.Error("Unable to marshall unknown2: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyPullRequestReview", + Args: args, + }) +} + +// NotifyPullRequestSynchronized is a placeholder function +func (q *QueueNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&pr) + if err != nil { + log.Error("Unable to marshall pr: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyPullRequestSynchronized", + Args: args, + }) +} + +// NotifyPullReviewRequest is a placeholder function +func (q *QueueNotifier) NotifyPullReviewRequest(doer *models.User, issue *models.Issue, reviewer *models.User, isRequest bool, comment *models.Comment) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&issue) + if err != nil { + log.Error("Unable to marshall issue: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&reviewer) + if err != nil { + log.Error("Unable to marshall reviewer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&isRequest) + if err != nil { + log.Error("Unable to marshall isRequest: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&comment) + if err != nil { + log.Error("Unable to marshall comment: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyPullReviewRequest", + Args: args, + }) +} + +// NotifyPushCommits is a placeholder function +func (q *QueueNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName string, oldCommitID string, newCommitID string, commits *repository.PushCommits) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&pusher) + if err != nil { + log.Error("Unable to marshall pusher: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&repo) + if err != nil { + log.Error("Unable to marshall repo: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&refName) + if err != nil { + log.Error("Unable to marshall refName: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&oldCommitID) + if err != nil { + log.Error("Unable to marshall oldCommitID: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&newCommitID) + if err != nil { + log.Error("Unable to marshall newCommitID: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&commits) + if err != nil { + log.Error("Unable to marshall commits: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyPushCommits", + Args: args, + }) +} + +// NotifyRenameRepository is a placeholder function +func (q *QueueNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&repo) + if err != nil { + log.Error("Unable to marshall repo: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&oldRepoName) + if err != nil { + log.Error("Unable to marshall oldRepoName: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyRenameRepository", + Args: args, + }) +} + +// NotifySyncCreateRef is a placeholder function +func (q *QueueNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&repo) + if err != nil { + log.Error("Unable to marshall repo: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&refType) + if err != nil { + log.Error("Unable to marshall refType: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&refFullName) + if err != nil { + log.Error("Unable to marshall refFullName: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifySyncCreateRef", + Args: args, + }) +} + +// NotifySyncDeleteRef is a placeholder function +func (q *QueueNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&repo) + if err != nil { + log.Error("Unable to marshall repo: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&refType) + if err != nil { + log.Error("Unable to marshall refType: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&refFullName) + if err != nil { + log.Error("Unable to marshall refFullName: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifySyncDeleteRef", + Args: args, + }) +} + +// NotifySyncPushCommits is a placeholder function +func (q *QueueNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName string, oldCommitID string, newCommitID string, commits *repository.PushCommits) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&pusher) + if err != nil { + log.Error("Unable to marshall pusher: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&repo) + if err != nil { + log.Error("Unable to marshall repo: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&refName) + if err != nil { + log.Error("Unable to marshall refName: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&oldCommitID) + if err != nil { + log.Error("Unable to marshall oldCommitID: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&newCommitID) + if err != nil { + log.Error("Unable to marshall newCommitID: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&commits) + if err != nil { + log.Error("Unable to marshall commits: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifySyncPushCommits", + Args: args, + }) +} + +// NotifyTransferRepository is a placeholder function +func (q *QueueNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&repo) + if err != nil { + log.Error("Unable to marshall repo: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&oldOwnerName) + if err != nil { + log.Error("Unable to marshall oldOwnerName: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyTransferRepository", + Args: args, + }) +} + +// NotifyUpdateComment is a placeholder function +func (q *QueueNotifier) NotifyUpdateComment(unknown0 *models.User, unknown1 *models.Comment, unknown2 string) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&unknown0) + if err != nil { + log.Error("Unable to marshall unknown0: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&unknown1) + if err != nil { + log.Error("Unable to marshall unknown1: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&unknown2) + if err != nil { + log.Error("Unable to marshall unknown2: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyUpdateComment", + Args: args, + }) +} + +// NotifyUpdateRelease is a placeholder function +func (q *QueueNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) { + args := make([][]byte, 0) + var err error + var bs []byte + bs, err = json.Marshal(&doer) + if err != nil { + log.Error("Unable to marshall doer: %v", err) + return + } + args = append(args, bs) + bs, err = json.Marshal(&rel) + if err != nil { + log.Error("Unable to marshall rel: %v", err) + return + } + args = append(args, bs) + + q.internal.Push(&FunctionCall{ + Name: "NotifyUpdateRelease", + Args: args, + }) +} diff --git a/modules/notification/indexer/indexer.go b/modules/notification/indexer/indexer.go index f292d7339b20c..aef9124664010 100644 --- a/modules/notification/indexer/indexer.go +++ b/modules/notification/indexer/indexer.go @@ -50,6 +50,10 @@ func (r *indexerNotifier) NotifyNewIssue(issue *models.Issue) { } func (r *indexerNotifier) NotifyNewPullRequest(pr *models.PullRequest) { + if err := pr.LoadIssue(); err != nil { + log.Error("Unable to load issue: %d for pr: %d, error: %v", pr.IssueID, pr.ID, err) + return + } issue_indexer.UpdateIssueIndexer(pr.Issue) } diff --git a/modules/notification/mail/mail.go b/modules/notification/mail/mail.go index b980db7e4b423..2217c26fdbd01 100644 --- a/modules/notification/mail/mail.go +++ b/modules/notification/mail/mail.go @@ -45,6 +45,10 @@ func (m *mailNotifier) NotifyCreateIssueComment(doer *models.User, repo *models. } func (m *mailNotifier) NotifyNewIssue(issue *models.Issue) { + if err := issue.LoadPoster(); err != nil { + log.Error("Unable to load poster: %d for issue: %d: Error: %v", issue.PosterID, issue.ID, err) + return + } if err := mailer.MailParticipants(issue, issue.Poster, models.ActionCreateIssue); err != nil { log.Error("MailParticipants: %v", err) } @@ -73,6 +77,14 @@ func (m *mailNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models. } func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest) { + if err := pr.LoadIssue(); err != nil { + log.Error("Unable to load issue: %d for pr: %d: Error: %v", pr.IssueID, pr.ID, err) + return + } + if err := pr.Issue.LoadPoster(); err != nil { + log.Error("Unable to load poster: %d for pr: %d, issue: %d: Error: %v", pr.Issue.PosterID, pr.ID, pr.IssueID, err) + return + } if err := mailer.MailParticipants(pr.Issue, pr.Issue.Poster, models.ActionCreatePullRequest); err != nil { log.Error("MailParticipants: %v", err) } diff --git a/modules/notification/notification.go b/modules/notification/notification.go index d120246634306..6775b21deb967 100644 --- a/modules/notification/notification.go +++ b/modules/notification/notification.go @@ -5,6 +5,8 @@ package notification import ( + "sync" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/notification/action" "code.gitea.io/gitea/modules/notification/base" @@ -18,6 +20,7 @@ import ( var ( notifiers []base.Notifier + once = sync.Once{} ) // RegisterNotifier providers method to receive notify messages @@ -28,13 +31,18 @@ func RegisterNotifier(notifier base.Notifier) { // NewContext registers notification handlers func NewContext() { - RegisterNotifier(ui.NewNotifier()) - if setting.Service.EnableNotifyMail { - RegisterNotifier(mail.NewNotifier()) - } - RegisterNotifier(indexer.NewNotifier()) - RegisterNotifier(webhook.NewNotifier()) - RegisterNotifier(action.NewNotifier()) + once.Do(func() { + var ns []base.Notifier + ns = append(ns, ui.NewNotifier()) + if setting.Service.EnableNotifyMail { + ns = append(ns, mail.NewNotifier()) + } + ns = append(ns, indexer.NewNotifier()) + ns = append(ns, webhook.NewNotifier()) + ns = append(ns, action.NewNotifier()) + + RegisterNotifier(base.NewQueueNotifier("notification", ns)) + }) } // NotifyCreateIssueComment notifies issue comment related message to notifiers diff --git a/modules/notification/ui/ui.go b/modules/notification/ui/ui.go index 7f7de10bedd6d..dbbbb680de55d 100644 --- a/modules/notification/ui/ui.go +++ b/modules/notification/ui/ui.go @@ -65,7 +65,7 @@ func (ns *notificationService) NotifyCreateIssueComment(doer *models.User, repo func (ns *notificationService) NotifyNewIssue(issue *models.Issue) { _ = ns.issueQueue.Push(issueNotificationOpts{ IssueID: issue.ID, - NotificationAuthorID: issue.Poster.ID, + NotificationAuthorID: issue.PosterID, }) } @@ -78,7 +78,7 @@ func (ns *notificationService) NotifyIssueChangeStatus(doer *models.User, issue func (ns *notificationService) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) { _ = ns.issueQueue.Push(issueNotificationOpts{ - IssueID: pr.Issue.ID, + IssueID: pr.IssueID, NotificationAuthorID: doer.ID, }) } @@ -89,15 +89,15 @@ func (ns *notificationService) NotifyNewPullRequest(pr *models.PullRequest) { return } _ = ns.issueQueue.Push(issueNotificationOpts{ - IssueID: pr.Issue.ID, + IssueID: pr.IssueID, NotificationAuthorID: pr.Issue.PosterID, }) } func (ns *notificationService) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, c *models.Comment) { var opts = issueNotificationOpts{ - IssueID: pr.Issue.ID, - NotificationAuthorID: r.Reviewer.ID, + IssueID: pr.IssueID, + NotificationAuthorID: r.ReviewerID, } if c != nil { opts.CommentID = c.ID diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 6b7c2beac4b5d..6713a8a78e2f0 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -413,6 +413,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) ctx.Error(http.StatusInternalServerError, "UpdateComment", err) return } + _ = comment.LoadPoster() ctx.JSON(http.StatusOK, comment.APIFormat()) }