From 5d8a52c32fd312991a197efc7dd15519f1c3e9d7 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Mon, 20 Jan 2020 20:55:19 +0000 Subject: [PATCH 1/8] Ensure things are json marshalable --- models/issue.go | 2 +- models/repo_unit.go | 53 ++++++++++++++++++++++++++++ models/user.go | 12 +++---- modules/convert/pull.go | 4 +++ routers/api/v1/repo/issue_comment.go | 2 ++ 5 files changed, 66 insertions(+), 7 deletions(-) diff --git a/models/issue.go b/models/issue.go index afd110e06ddc8..27caa5a3dbe3f 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 ec680c395e09a..791a110588407 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 d77a54b06983b..06a5209479c4b 100644 --- a/models/user.go +++ b/models/user.go @@ -110,9 +110,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)"` @@ -152,9 +152,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 fa22977d027e0..ed1da9f9978fe 100644 --- a/modules/convert/pull.go +++ b/modules/convert/pull.go @@ -26,6 +26,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/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 6b7c2beac4b5d..18c25b6fd29cb 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -413,6 +413,8 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) ctx.Error(http.StatusInternalServerError, "UpdateComment", err) return } + _ = comment.LoadAssigneeUser() + _ = comment.LoadPoster() ctx.JSON(http.StatusOK, comment.APIFormat()) } From 7138650baca41bbabde8cca59f3e46436ecefc3d Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Mon, 20 Jan 2020 20:56:16 +0000 Subject: [PATCH 2/8] Notification: move to use a queue --- integrations/integration_test.go | 1 + integrations/mssql.ini.tmpl | 7 + integrations/mysql.ini.tmpl | 7 + integrations/mysql8.ini.tmpl | 7 + integrations/notification_helper_test.go | 121 ++ integrations/pgsql.ini.tmpl | 7 + integrations/pull_merge_test.go | 97 +- integrations/sqlite.ini | 7 + modules/notification/base/main.go | 246 +++ modules/notification/base/notifier.go | 2 + modules/notification/base/null.go | 147 +- modules/notification/base/queue.go | 1735 ++++++++++++++++++++++ modules/notification/indexer/indexer.go | 4 + modules/notification/mail/mail.go | 12 + modules/notification/notification.go | 22 +- modules/notification/ui/ui.go | 10 +- 16 files changed, 2313 insertions(+), 119 deletions(-) create mode 100644 integrations/notification_helper_test.go create mode 100644 modules/notification/base/main.go create mode 100644 modules/notification/base/queue.go diff --git a/integrations/integration_test.go b/integrations/integration_test.go index 138d751859d5a..491959adb6328 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 931e923cf4871..70b882834efe2 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 304434dbd6185..4eefd958905a6 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 1b1d3d243670e..2173e6cf0eb43 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..d7ef5f74678d2 --- /dev/null +++ b/integrations/notification_helper_test.go @@ -0,0 +1,121 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package 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() + found := -1 + for i, callbackPtr := range n.callbacks[functionName] { + if callbackPtr == callback { + found = i + break + } + } + if found > -1 { + n.callbacks[functionName] = append(n.callbacks[functionName][0:found], n.callbacks[functionName][found+1:]...) + } + n.lock.Unlock() +} + +// 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 f337d98fb4b3d..be1a42cddb423 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 5a9283edcfa55..8b7a206194dbc 100644 --- a/integrations/pull_merge_test.go +++ b/integrations/pull_merge_test.go @@ -61,31 +61,75 @@ func testPullCleanUp(t *testing.T, session *TestSession, user, repo, pullnum str 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, deferableCreate := notifierListener.RegisterChannel("NotifyNewPullRequest", 0, &models.PullRequest{}) + defer deferableCreate() + + mergePullNotified, deferableMerge := notifierListener.RegisterChannel("NotifyMergePullRequest", 0, &models.PullRequest{}) + defer deferableMerge() session := loginUser(t, "user1") testRepoFork(t, session, "user2", "repo1", "user1", "repo1") testEditFile(t, session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") + var prInterface interface{} + resp := testPullCreate(t, session, "user1", "repo1", "master", "This is a pull title") + select { + case prInterface = <-createPullNotified: + case <-time.After(500 * time.Millisecond): + assert.Fail(t, "Took too long to notify!") + } + pr := prInterface.(*models.PullRequest) + pr.LoadBaseRepo() + pr.LoadHeadRepo() + pr.BaseRepo.MustOwner() + pr.HeadRepo.MustOwner() + + assert.EqualValues(t, "user1", pr.HeadRepo.Owner.Name) + assert.EqualValues(t, "repo1", pr.HeadRepo.Name) + assert.EqualValues(t, "user2", pr.BaseRepo.Owner.Name) + assert.EqualValues(t, "repo1", pr.BaseRepo.Name) elem := strings.Split(test.RedirectURL(resp), "/") assert.EqualValues(t, "pulls", elem[3]) + testPullMerge(t, session, elem[1], elem[2], elem[4], models.MergeStyleMerge) - hookTasks, err = models.HookTasks(1, 1) - assert.NoError(t, err) - assert.Len(t, hookTasks, hookTasksLenBefore+1) + select { + case prInterface = <-mergePullNotified: + case <-time.After(500 * time.Millisecond): + assert.Fail(t, "Took too long to notify!") + } + + pr = prInterface.(*models.PullRequest) + pr.LoadBaseRepo() + pr.LoadHeadRepo() + pr.BaseRepo.MustOwner() + pr.HeadRepo.MustOwner() + + assert.EqualValues(t, "user1", pr.HeadRepo.Owner.Name) + assert.EqualValues(t, "repo1", pr.HeadRepo.Name) + assert.EqualValues(t, "user2", pr.BaseRepo.Owner.Name) + assert.EqualValues(t, "repo1", pr.BaseRepo.Name) + + time.Sleep(100 * time.Millisecond) + select { + case prInterface = <-createPullNotified: + assert.Fail(t, "Should only have one pull create notification: %v", prInterface) + default: + } + select { + case prInterface = <-mergePullNotified: + assert.Fail(t, "Should only have one pull merge notification: %v", prInterface) + default: + } }) } 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 +140,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 +163,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 +187,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 b/integrations/sqlite.ini index de3355c166b03..b27b123957d3e 100644 --- a/integrations/sqlite.ini +++ b/integrations/sqlite.ini @@ -81,3 +81,10 @@ INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE0OTI3OTU5ODN9.O [oauth2] JWT_SECRET = KZb_QLUd4fYVyxetjxC4eZkrBgWM2SndOOWDNtgUUko +[queue] +TYPE=channel + +[queue.test-notifier] +BATCH_LENGTH=1 +LENGTH=20 + diff --git a/modules/notification/base/main.go b/modules/notification/base/main.go new file mode 100644 index 0000000000000..899676fd0735c --- /dev/null +++ b/modules/notification/base/main.go @@ -0,0 +1,246 @@ +// Copyright 2019 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +// +build ignore + +package main + +import ( + "bytes" + "fmt" + "go/ast" + "go/format" + "go/parser" + "go/token" + "io/ioutil" + "strings" + "text/template" + "time" +) + +type funcDef struct { + Name string + Args []funcDefArg +} + +type funcDefArg struct { + Name string + Type string +} + +func main() { + fset := token.NewFileSet() // positions are relative to fset + f, err := parser.ParseFile(fset, "notifier.go", nil, 0) + if err != nil { + panic(err) + } + funcs := make([]funcDef, 0) + //currentFunc := funcDef{} + ast.Inspect(f, func(n ast.Node) bool { + spec, ok := n.(*ast.TypeSpec) + if !ok || spec.Name.Name != "Notifier" { + return true + } + child, ok := spec.Type.(*ast.InterfaceType) + if !ok { + return false + } + funcs = make([]funcDef, len(child.Methods.List)) + for i, method := range child.Methods.List { + methodFuncDef := method.Type.(*ast.FuncType) + def := funcDef{} + def.Name = method.Names[0].Name + def.Args = make([]funcDefArg, 0, len(methodFuncDef.Params.List)) + for j, param := range methodFuncDef.Params.List { + defaultName := fmt.Sprintf("unknown%d", j) + sb := strings.Builder{} + format.Node(&sb, fset, param.Type) + + if len(param.Names) == 0 { + def.Args = append(def.Args, funcDefArg{ + Name: defaultName, + Type: sb.String(), + }) + } else { + for _, ident := range param.Names { + def.Args = append(def.Args, funcDefArg{ + Name: ident.Name, + Type: sb.String(), + }) + } + } + } + funcs[i] = def + } + + return true + }) + + 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) + } + + 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(` +// 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 is function call with json.Marshaled arguments +type FunctionCall struct { + Name string + Args [][]byte +} + +type QueueNotifier struct { + name string + notifiers []Notifier + internal queue.Queue +} + +var ( + _ Notifier = &QueueNotifier{} +) + +func NewQueueNotifier(name string, notifiers []Notifier) Notifier { + q := &QueueNotifier{ + name: name, + notifiers: notifiers, + } + q.internal = queue.CreateQueue(name, q.handle, &FunctionCall{}) + return q +} + +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(`// 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 { +} + +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 1c607ded3b250..8ca30799a08eb 100644 --- a/modules/notification/base/notifier.go +++ b/modules/notification/base/notifier.go @@ -9,6 +9,8 @@ import ( "code.gitea.io/gitea/modules/repository" ) +//go:generate go run -mod=vendor 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 f6c423b4694c4..d494735f0e3d5 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -1,7 +1,4 @@ -// Copyright 2019 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - +// Code generated by go generate; DO NOT EDIT. package base import ( @@ -17,132 +14,118 @@ var ( _ Notifier = &NullNotifier{} ) -// Run places a place holder function -func (*NullNotifier) Run() { -} +// Run is a placeholder function +func (*NullNotifier) Run() {} -// NotifyCreateIssueComment places a place holder function -func (*NullNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository, - issue *models.Issue, comment *models.Comment) { +// NotifyCreateRepository is a placeholder function +func (*NullNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) { } -// NotifyNewIssue places a place holder function -func (*NullNotifier) NotifyNewIssue(issue *models.Issue) { +// NotifyMigrateRepository is a placeholder function +func (*NullNotifier) NotifyMigrateRepository(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) { -} +// NotifyDeleteRepository is a placeholder function +func (*NullNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {} -// NotifyNewPullRequest places a place holder function -func (*NullNotifier) NotifyNewPullRequest(pr *models.PullRequest) { +// NotifyForkRepository is a placeholder function +func (*NullNotifier) NotifyForkRepository(doer *models.User, oldRepo *models.Repository, repo *models.Repository) { } -// NotifyPullRequestReview places a place holder function -func (*NullNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment) { +// NotifyRenameRepository is a placeholder function +func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { } -// NotifyMergePullRequest places a place holder function -func (*NullNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User) { +// NotifyTransferRepository is a placeholder function +func (*NullNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { } -// NotifyPullRequestSynchronized places a place holder function -func (*NullNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) { -} +// NotifyNewIssue is a placeholder function +func (*NullNotifier) NotifyNewIssue(unknown0 *models.Issue) {} -// NotifyPullRequestChangeTargetBranch places a place holder function -func (*NullNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) { +// NotifyIssueChangeStatus is a placeholder function +func (*NullNotifier) NotifyIssueChangeStatus(unknown0 *models.User, unknown1 *models.Issue, unknown2 *models.Comment, unknown3 bool) { } -// NotifyUpdateComment places a place holder function -func (*NullNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) { +// NotifyIssueChangeMilestone is a placeholder function +func (*NullNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) { } -// NotifyDeleteComment places a place holder function -func (*NullNotifier) NotifyDeleteComment(doer *models.User, c *models.Comment) { +// NotifyIssueChangeAssignee is a placeholder function +func (*NullNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { } -// NotifyNewRelease places a place holder function -func (*NullNotifier) NotifyNewRelease(rel *models.Release) { +// NotifyIssueChangeContent is a placeholder function +func (*NullNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { } -// NotifyUpdateRelease places a place holder function -func (*NullNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) { -} +// NotifyIssueClearLabels is a placeholder function +func (*NullNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {} -// 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) { +// NotifyIssueChangeLabels is a placeholder function +func (*NullNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, addedLabels []*models.Label, removedLabels []*models.Label) { } -// NotifyIssueChangeContent places a place holder function -func (*NullNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { -} +// NotifyNewPullRequest is a placeholder function +func (*NullNotifier) NotifyNewPullRequest(unknown0 *models.PullRequest) {} -// NotifyIssueChangeAssignee places a place holder function -func (*NullNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { -} +// NotifyMergePullRequest is a placeholder function +func (*NullNotifier) NotifyMergePullRequest(unknown0 *models.PullRequest, unknown1 *models.User) {} -// NotifyIssueClearLabels places a place holder function -func (*NullNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) { -} +// NotifyPullRequestSynchronized is a placeholder function +func (*NullNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) {} -// NotifyIssueChangeTitle places a place holder function -func (*NullNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) { +// NotifyPullRequestReview is a placeholder function +func (*NullNotifier) NotifyPullRequestReview(unknown0 *models.PullRequest, unknown1 *models.Review, unknown2 *models.Comment) { } -// 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) { +// NotifyCreateIssueComment is a placeholder function +func (*NullNotifier) NotifyCreateIssueComment(unknown0 *models.User, unknown1 *models.Repository, unknown2 *models.Issue, unknown3 *models.Comment) { } -// NotifyDeleteRepository places a place holder function -func (*NullNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) { +// NotifyUpdateComment is a placeholder function +func (*NullNotifier) NotifyUpdateComment(unknown0 *models.User, unknown1 *models.Comment, unknown2 string) { } -// NotifyForkRepository places a place holder function -func (*NullNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) { -} +// NotifyDeleteComment is a placeholder function +func (*NullNotifier) NotifyDeleteComment(unknown0 *models.User, unknown1 *models.Comment) {} -// NotifyMigrateRepository places a place holder function -func (*NullNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) { -} +// NotifyNewRelease is a placeholder function +func (*NullNotifier) NotifyNewRelease(rel *models.Release) {} -// NotifyPushCommits notifies commits pushed to notifiers -func (*NullNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) { -} +// NotifyUpdateRelease is a placeholder function +func (*NullNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {} -// NotifyCreateRef notifies branch or tag creation to notifiers -func (*NullNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType, refFullName string) { -} +// NotifyDeleteRelease is a placeholder function +func (*NullNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) {} -// NotifyDeleteRef notifies branch or tag deleteion to notifiers -func (*NullNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType, refFullName string) { +// NotifyPushCommits is a placeholder function +func (*NullNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName string, oldCommitID string, newCommitID string, commits *repository.PushCommits) { } -// NotifyRenameRepository places a place holder function -func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { +// NotifyCreateRef is a placeholder function +func (*NullNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { } -// NotifyTransferRepository places a place holder function -func (*NullNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { +// NotifyDeleteRef is a placeholder function +func (*NullNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { } -// NotifySyncPushCommits places a place holder function -func (*NullNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName, oldCommitID, newCommitID string, commits *repository.PushCommits) { +// NotifySyncPushCommits is a placeholder function +func (*NullNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName string, oldCommitID string, newCommitID string, commits *repository.PushCommits) { } -// NotifySyncCreateRef places a place holder function -func (*NullNotifier) NotifySyncCreateRef(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) { } -// NotifySyncDeleteRef places a place holder function -func (*NullNotifier) NotifySyncDeleteRef(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) { } diff --git a/modules/notification/base/queue.go b/modules/notification/base/queue.go new file mode 100644 index 0000000000000..04e254cbf61b8 --- /dev/null +++ b/modules/notification/base/queue.go @@ -0,0 +1,1735 @@ +// 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 is function call with json.Marshaled arguments +type FunctionCall struct { + Name string + Args [][]byte +} + +type QueueNotifier struct { + name string + notifiers []Notifier + internal queue.Queue +} + +var ( + _ Notifier = &QueueNotifier{} +) + +func NewQueueNotifier(name string, notifiers []Notifier) Notifier { + q := &QueueNotifier{ + name: name, + notifiers: notifiers, + } + q.internal = queue.CreateQueue(name, q.handle, &FunctionCall{}) + return q +} + +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 "Run": + + for _, notifier := range q.notifiers { + notifier.Run() + } + 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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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 "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) + } + 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) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} + +// 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, + }) +} diff --git a/modules/notification/indexer/indexer.go b/modules/notification/indexer/indexer.go index 6caae6fa65a12..f4e949c933d84 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 ec7d9d617e572..f68cd8ddda670 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 8c5d7d60358e2..677915cf77c83 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 525753425a4ab..9fe61a5bc2ecd 100644 --- a/modules/notification/ui/ui.go +++ b/modules/notification/ui/ui.go @@ -64,7 +64,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, }) } @@ -77,7 +77,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, }) } @@ -88,15 +88,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 From d313a4e20ba84dcb3b24d56832e9b1af6100ebcf Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 21 Jan 2020 21:46:12 +0000 Subject: [PATCH 3/8] Add some more comments --- integrations/notification_helper_test.go | 2 +- modules/notification/base/main.go | 84 ++++++++++++++++++++---- modules/notification/base/notifier.go | 2 + modules/notification/base/null.go | 1 + modules/notification/base/queue.go | 6 +- 5 files changed, 79 insertions(+), 16 deletions(-) diff --git a/integrations/notification_helper_test.go b/integrations/notification_helper_test.go index d7ef5f74678d2..3317cd8f570a4 100644 --- a/integrations/notification_helper_test.go +++ b/integrations/notification_helper_test.go @@ -1,4 +1,4 @@ -// 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. diff --git a/modules/notification/base/main.go b/modules/notification/base/main.go index 899676fd0735c..1624742efe53f 100644 --- a/modules/notification/base/main.go +++ b/modules/notification/base/main.go @@ -1,4 +1,4 @@ -// 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. @@ -19,64 +19,114 @@ import ( "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) - //currentFunc := funcDef{} + ast.Inspect(f, func(n ast.Node) bool { spec, ok := n.(*ast.TypeSpec) - if !ok || spec.Name.Name != "Notifier" { - return true + 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 + 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 { - methodFuncDef := method.Type.(*ast.FuncType) + // 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 + 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(), - }) + def.Args = append(def.Args, funcDefArg{ + Name: ident.Name, + Type: sb.String(), + }) + } } - } } funcs[i] = def } - return true + // We're done so stop walking + return false }) + // First lets create the NullNotifier buf := bytes.Buffer{} nullTemplate.Execute(&buf, struct { Timestamp time.Time @@ -96,6 +146,7 @@ func main() { panic(err) } + // Then create the NotifierQueue buf = bytes.Buffer{} queueTemplate.Execute(&buf, struct { Timestamp time.Time @@ -132,22 +183,25 @@ import ( "code.gitea.io/gitea/modules/queue" ) -// FunctionCall represents is function call with json.Marshaled arguments +// 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, @@ -157,6 +211,7 @@ func NewQueueNotifier(name string, notifiers []Notifier) Notifier { return q } +// NewQueueNotifierWithHandle creates a notifier queue with a specific handler function func NewQueueNotifierWithHandle(name string, handle queue.HandlerFunc) Notifier { q := &QueueNotifier{ name: name, @@ -235,6 +290,7 @@ import ( type NullNotifier struct { } +// Ensure that NullNotifier fulfils the Notifier interface var ( _ Notifier = &NullNotifier{} ) diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go index 8ca30799a08eb..4de520f39ede5 100644 --- a/modules/notification/base/notifier.go +++ b/modules/notification/base/notifier.go @@ -11,6 +11,8 @@ import ( //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 d494735f0e3d5..e3f514820e407 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -10,6 +10,7 @@ import ( type NullNotifier struct { } +// Ensure that NullNotifier fulfils the Notifier interface var ( _ Notifier = &NullNotifier{} ) diff --git a/modules/notification/base/queue.go b/modules/notification/base/queue.go index 04e254cbf61b8..cb360c50b61bc 100644 --- a/modules/notification/base/queue.go +++ b/modules/notification/base/queue.go @@ -11,22 +11,25 @@ import ( "code.gitea.io/gitea/modules/repository" ) -// FunctionCall represents is function call with json.Marshaled arguments +// 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, @@ -36,6 +39,7 @@ func NewQueueNotifier(name string, notifiers []Notifier) Notifier { return q } +// NewQueueNotifierWithHandle creates a notifier queue with a specific handler function func NewQueueNotifierWithHandle(name string, handle queue.HandlerFunc) Notifier { q := &QueueNotifier{ name: name, From 7e9930171ad9502b9dcdfb90e34cbcc6ad500c71 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 21 Jan 2020 22:21:28 +0000 Subject: [PATCH 4/8] Improve pull_merge_test --- integrations/notification_helper_test.go | 10 +-- integrations/pull_merge_test.go | 84 +++++++++++------------- 2 files changed, 40 insertions(+), 54 deletions(-) diff --git a/integrations/notification_helper_test.go b/integrations/notification_helper_test.go index 3317cd8f570a4..12a631ac13df5 100644 --- a/integrations/notification_helper_test.go +++ b/integrations/notification_helper_test.go @@ -47,17 +47,13 @@ func (n *NotifierListener) Register(functionName string, callback *func(string, // Deregister will remove the provided callback from the provided notifier function func (n *NotifierListener) Deregister(functionName string, callback *func(string, [][]byte)) { n.lock.Lock() - found := -1 + defer n.lock.Unlock() for i, callbackPtr := range n.callbacks[functionName] { if callbackPtr == callback { - found = i - break + n.callbacks[functionName] = append(n.callbacks[functionName][0:i], n.callbacks[functionName][i+1:]...) + return } } - if found > -1 { - n.callbacks[functionName] = append(n.callbacks[functionName][0:found], n.callbacks[functionName][found+1:]...) - } - n.lock.Unlock() } // RegisterChannel will return a registered channel with function name and return a function to deregister it and close the channel at the end diff --git a/integrations/pull_merge_test.go b/integrations/pull_merge_test.go index 8b7a206194dbc..47cb6e9cbecfb 100644 --- a/integrations/pull_merge_test.go +++ b/integrations/pull_merge_test.go @@ -59,70 +59,60 @@ 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) { - createPullNotified, deferableCreate := notifierListener.RegisterChannel("NotifyNewPullRequest", 0, &models.PullRequest{}) - defer deferableCreate() + createPullNotified, unregisterNewPull := notifierListener.RegisterChannel("NotifyNewPullRequest", 0, &models.PullRequest{}) + defer unregisterNewPull() - mergePullNotified, deferableMerge := notifierListener.RegisterChannel("NotifyMergePullRequest", 0, &models.PullRequest{}) - defer deferableMerge() + 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") - var prInterface interface{} - resp := testPullCreate(t, session, "user1", "repo1", "master", "This is a pull title") - select { - case prInterface = <-createPullNotified: - case <-time.After(500 * time.Millisecond): - assert.Fail(t, "Took too long to notify!") + + 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" && + pr.HeadBranch == "master" } - pr := prInterface.(*models.PullRequest) - pr.LoadBaseRepo() - pr.LoadHeadRepo() - pr.BaseRepo.MustOwner() - pr.HeadRepo.MustOwner() - assert.EqualValues(t, "user1", pr.HeadRepo.Owner.Name) - assert.EqualValues(t, "repo1", pr.HeadRepo.Name) - assert.EqualValues(t, "user2", pr.BaseRepo.Owner.Name) - assert.EqualValues(t, "repo1", pr.BaseRepo.Name) + 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") - select { - case prInterface = <-mergePullNotified: - case <-time.After(500 * time.Millisecond): - assert.Fail(t, "Took too long to notify!") - } - - pr = prInterface.(*models.PullRequest) - pr.LoadBaseRepo() - pr.LoadHeadRepo() - pr.BaseRepo.MustOwner() - pr.HeadRepo.MustOwner() - - assert.EqualValues(t, "user1", pr.HeadRepo.Owner.Name) - assert.EqualValues(t, "repo1", pr.HeadRepo.Name) - assert.EqualValues(t, "user2", pr.BaseRepo.Owner.Name) - assert.EqualValues(t, "repo1", pr.BaseRepo.Name) - - time.Sleep(100 * time.Millisecond) - select { - case prInterface = <-createPullNotified: - assert.Fail(t, "Should only have one pull create notification: %v", prInterface) - default: - } - select { - case prInterface = <-mergePullNotified: - assert.Fail(t, "Should only have one pull merge notification: %v", prInterface) - default: - } + 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") }) } From 569c7d76086938861f0a31d856986e8c3bffd911 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 21 Jan 2020 22:26:48 +0000 Subject: [PATCH 5/8] Sort func names --- modules/notification/base/main.go | 5 + modules/notification/base/null.go | 112 +-- modules/notification/base/queue.go | 1056 ++++++++++++++-------------- 3 files changed, 589 insertions(+), 584 deletions(-) diff --git a/modules/notification/base/main.go b/modules/notification/base/main.go index 1624742efe53f..dc22145ec7fd0 100644 --- a/modules/notification/base/main.go +++ b/modules/notification/base/main.go @@ -14,6 +14,7 @@ import ( "go/parser" "go/token" "io/ioutil" + "sort" "strings" "text/template" "time" @@ -126,6 +127,10 @@ func main() { 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 { diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go index e3f514820e407..3ead5d467bb94 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -15,17 +15,28 @@ var ( _ Notifier = &NullNotifier{} ) -// Run is a placeholder function -func (*NullNotifier) Run() {} +// NotifyCreateIssueComment is a placeholder function +func (*NullNotifier) NotifyCreateIssueComment(unknown0 *models.User, unknown1 *models.Repository, unknown2 *models.Issue, unknown3 *models.Comment) { +} + +// NotifyCreateRef is a placeholder function +func (*NullNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { +} // NotifyCreateRepository is a placeholder function func (*NullNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) { } -// NotifyMigrateRepository is a placeholder function -func (*NullNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) { +// NotifyDeleteComment is a placeholder function +func (*NullNotifier) NotifyDeleteComment(unknown0 *models.User, unknown1 *models.Comment) {} + +// NotifyDeleteRef is a placeholder function +func (*NullNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { } +// NotifyDeleteRelease is a placeholder function +func (*NullNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) {} + // NotifyDeleteRepository is a placeholder function func (*NullNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {} @@ -33,100 +44,89 @@ func (*NullNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repo func (*NullNotifier) NotifyForkRepository(doer *models.User, oldRepo *models.Repository, repo *models.Repository) { } -// NotifyRenameRepository is a placeholder function -func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { +// NotifyIssueChangeAssignee is a placeholder function +func (*NullNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { } -// NotifyTransferRepository is a placeholder function -func (*NullNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { +// NotifyIssueChangeContent is a placeholder function +func (*NullNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { } -// NotifyNewIssue is a placeholder function -func (*NullNotifier) NotifyNewIssue(unknown0 *models.Issue) {} - -// NotifyIssueChangeStatus is a placeholder function -func (*NullNotifier) NotifyIssueChangeStatus(unknown0 *models.User, unknown1 *models.Issue, unknown2 *models.Comment, unknown3 bool) { +// NotifyIssueChangeLabels is a placeholder function +func (*NullNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, addedLabels []*models.Label, removedLabels []*models.Label) { } // NotifyIssueChangeMilestone is a placeholder function func (*NullNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) { } -// NotifyIssueChangeAssignee is a placeholder function -func (*NullNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, assignee *models.User, removed bool, comment *models.Comment) { +// NotifyIssueChangeStatus is a placeholder function +func (*NullNotifier) NotifyIssueChangeStatus(unknown0 *models.User, unknown1 *models.Issue, unknown2 *models.Comment, unknown3 bool) { } -// NotifyIssueChangeContent is a placeholder function -func (*NullNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) { -} +// NotifyIssueChangeTitle is a placeholder function +func (*NullNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {} // NotifyIssueClearLabels is a placeholder function func (*NullNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {} -// NotifyIssueChangeTitle is a placeholder function -func (*NullNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {} +// NotifyMergePullRequest is a placeholder function +func (*NullNotifier) NotifyMergePullRequest(unknown0 *models.PullRequest, unknown1 *models.User) {} -// NotifyIssueChangeLabels is a placeholder function -func (*NullNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue, addedLabels []*models.Label, removedLabels []*models.Label) { +// NotifyMigrateRepository is a placeholder function +func (*NullNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) { } +// NotifyNewIssue is a placeholder function +func (*NullNotifier) NotifyNewIssue(unknown0 *models.Issue) {} + // NotifyNewPullRequest is a placeholder function func (*NullNotifier) NotifyNewPullRequest(unknown0 *models.PullRequest) {} -// NotifyMergePullRequest is a placeholder function -func (*NullNotifier) NotifyMergePullRequest(unknown0 *models.PullRequest, unknown1 *models.User) {} - -// NotifyPullRequestSynchronized is a placeholder function -func (*NullNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) {} - -// NotifyPullRequestReview is a placeholder function -func (*NullNotifier) NotifyPullRequestReview(unknown0 *models.PullRequest, unknown1 *models.Review, unknown2 *models.Comment) { -} +// NotifyNewRelease is a placeholder function +func (*NullNotifier) NotifyNewRelease(rel *models.Release) {} // NotifyPullRequestChangeTargetBranch is a placeholder function func (*NullNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) { } -// NotifyCreateIssueComment is a placeholder function -func (*NullNotifier) NotifyCreateIssueComment(unknown0 *models.User, unknown1 *models.Repository, unknown2 *models.Issue, unknown3 *models.Comment) { -} - -// NotifyUpdateComment is a placeholder function -func (*NullNotifier) NotifyUpdateComment(unknown0 *models.User, unknown1 *models.Comment, unknown2 string) { +// NotifyPullRequestReview is a placeholder function +func (*NullNotifier) NotifyPullRequestReview(unknown0 *models.PullRequest, unknown1 *models.Review, unknown2 *models.Comment) { } -// NotifyDeleteComment is a placeholder function -func (*NullNotifier) NotifyDeleteComment(unknown0 *models.User, unknown1 *models.Comment) {} - -// NotifyNewRelease is a placeholder function -func (*NullNotifier) NotifyNewRelease(rel *models.Release) {} - -// NotifyUpdateRelease is a placeholder function -func (*NullNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {} - -// NotifyDeleteRelease is a placeholder function -func (*NullNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) {} +// NotifyPullRequestSynchronized is a placeholder function +func (*NullNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *models.PullRequest) {} // NotifyPushCommits is a placeholder function func (*NullNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, refName string, oldCommitID string, newCommitID string, commits *repository.PushCommits) { } -// NotifyCreateRef is a placeholder function -func (*NullNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { +// NotifyRenameRepository is a placeholder function +func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { } -// NotifyDeleteRef is a placeholder function -func (*NullNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { +// NotifySyncCreateRef is a placeholder function +func (*NullNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { +} + +// NotifySyncDeleteRef is a placeholder function +func (*NullNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { } // NotifySyncPushCommits is a placeholder function func (*NullNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, refName string, oldCommitID string, newCommitID string, commits *repository.PushCommits) { } -// NotifySyncCreateRef is a placeholder function -func (*NullNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { +// NotifyTransferRepository is a placeholder function +func (*NullNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { } -// NotifySyncDeleteRef is a placeholder function -func (*NullNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { +// NotifyUpdateComment is a placeholder function +func (*NullNotifier) NotifyUpdateComment(unknown0 *models.User, unknown1 *models.Comment, unknown2 string) { } + +// NotifyUpdateRelease is a placeholder function +func (*NullNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {} + +// Run is a placeholder function +func (*NullNotifier) Run() {} diff --git a/modules/notification/base/queue.go b/modules/notification/base/queue.go index cb360c50b61bc..f2c83cdb2a0ad 100644 --- a/modules/notification/base/queue.go +++ b/modules/notification/base/queue.go @@ -53,205 +53,189 @@ func (q *QueueNotifier) handle(data ...queue.Data) { call := datum.(*FunctionCall) var err error switch call.Name { - case "Run": + case "NotifyCreateIssueComment": - for _, notifier := range q.notifiers { - notifier.Run() + 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 } - case "NotifyCreateRepository": - - var doer *models.User - err = json.Unmarshal(call.Args[0], &doer) + 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[0]), "*models.User", "NotifyCreateRepository", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyCreateIssueComment", err) continue } - var u *models.User - err = json.Unmarshal(call.Args[1], &u) + 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[1]), "*models.User", "NotifyCreateRepository", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "*models.Issue", "NotifyCreateIssueComment", err) continue } - var repo *models.Repository - err = json.Unmarshal(call.Args[2], &repo) + 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[2]), "*models.Repository", "NotifyCreateRepository", err) + 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.NotifyCreateRepository(doer, u, repo) + notifier.NotifyCreateIssueComment(unknown0, unknown1, unknown2, unknown3) } - case "NotifyMigrateRepository": + 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", "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) + 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[2], &repo) + 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[2]), "*models.Repository", "NotifyMigrateRepository", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyCreateRef", err) continue } - for _, notifier := range q.notifiers { - notifier.NotifyMigrateRepository(doer, u, repo) - } - case "NotifyDeleteRepository": - - var doer *models.User - err = json.Unmarshal(call.Args[0], &doer) + 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[0]), "*models.User", "NotifyDeleteRepository", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifyCreateRef", err) continue } - var repo *models.Repository - err = json.Unmarshal(call.Args[1], &repo) + 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[1]), "*models.Repository", "NotifyDeleteRepository", err) + 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.NotifyDeleteRepository(doer, repo) + notifier.NotifyCreateRef(doer, repo, refType, refFullName) } - case "NotifyForkRepository": + 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", "NotifyForkRepository", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyCreateRepository", err) continue } - var oldRepo *models.Repository - err = json.Unmarshal(call.Args[1], &oldRepo) + 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.Repository", "NotifyForkRepository", err) + 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", "NotifyForkRepository", err) + 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.NotifyForkRepository(doer, oldRepo, repo) + notifier.NotifyCreateRepository(doer, u, repo) } - case "NotifyRenameRepository": + case "NotifyDeleteComment": - 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) + 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[1]), "*models.Repository", "NotifyRenameRepository", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyDeleteComment", err) continue } - var oldRepoName string - err = json.Unmarshal(call.Args[2], &oldRepoName) + 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[2]), "string", "NotifyRenameRepository", err) + 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.NotifyRenameRepository(doer, repo, oldRepoName) + notifier.NotifyDeleteComment(unknown0, unknown1) } - case "NotifyTransferRepository": + 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", "NotifyTransferRepository", err) + 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", "NotifyTransferRepository", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyDeleteRef", err) continue } - var oldOwnerName string - err = json.Unmarshal(call.Args[2], &oldOwnerName) + 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", "NotifyTransferRepository", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifyDeleteRef", err) continue } - for _, notifier := range q.notifiers { - notifier.NotifyTransferRepository(doer, repo, oldOwnerName) - } - case "NotifyNewIssue": - - var unknown0 *models.Issue - err = json.Unmarshal(call.Args[0], &unknown0) + 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[0]), "*models.Issue", "NotifyNewIssue", err) + 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.NotifyNewIssue(unknown0) + notifier.NotifyDeleteRef(doer, repo, refType, refFullName) } - case "NotifyIssueChangeStatus": + case "NotifyDeleteRelease": - var unknown0 *models.User - err = json.Unmarshal(call.Args[0], &unknown0) + 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", "NotifyIssueChangeStatus", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyDeleteRelease", err) continue } - var unknown1 *models.Issue - err = json.Unmarshal(call.Args[1], &unknown1) + 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.Issue", "NotifyIssueChangeStatus", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Release", "NotifyDeleteRelease", err) continue } - var unknown2 *models.Comment - err = json.Unmarshal(call.Args[2], &unknown2) + 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[2]), "*models.Comment", "NotifyIssueChangeStatus", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyDeleteRepository", err) continue } - var unknown3 bool - err = json.Unmarshal(call.Args[3], &unknown3) + 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[3]), "bool", "NotifyIssueChangeStatus", err) + 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.NotifyIssueChangeStatus(unknown0, unknown1, unknown2, unknown3) + notifier.NotifyDeleteRepository(doer, repo) } - case "NotifyIssueChangeMilestone": + 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", "NotifyIssueChangeMilestone", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyForkRepository", err) continue } - var issue *models.Issue - err = json.Unmarshal(call.Args[1], &issue) + 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.Issue", "NotifyIssueChangeMilestone", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyForkRepository", err) continue } - var oldMilestoneID int64 - err = json.Unmarshal(call.Args[2], &oldMilestoneID) + 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]), "int64", "NotifyIssueChangeMilestone", err) + 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.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID) + notifier.NotifyForkRepository(doer, oldRepo, repo) } case "NotifyIssueChangeAssignee": @@ -311,46 +295,6 @@ func (q *QueueNotifier) handle(data ...queue.Data) { for _, notifier := range q.notifiers { notifier.NotifyIssueChangeContent(doer, issue, oldContent) } - 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 "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 "NotifyIssueChangeLabels": var doer *models.User @@ -380,165 +324,159 @@ func (q *QueueNotifier) handle(data ...queue.Data) { for _, notifier := range q.notifiers { notifier.NotifyIssueChangeLabels(doer, issue, addedLabels, removedLabels) } - 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 "NotifyMergePullRequest": + case "NotifyIssueChangeMilestone": - 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) + 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[1]), "*models.User", "NotifyMergePullRequest", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyIssueChangeMilestone", err) continue } - for _, notifier := range q.notifiers { - notifier.NotifyMergePullRequest(unknown0, unknown1) - } - case "NotifyPullRequestSynchronized": - - var doer *models.User - err = json.Unmarshal(call.Args[0], &doer) + 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[0]), "*models.User", "NotifyPullRequestSynchronized", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Issue", "NotifyIssueChangeMilestone", err) continue } - var pr *models.PullRequest - err = json.Unmarshal(call.Args[1], &pr) + 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[1]), "*models.PullRequest", "NotifyPullRequestSynchronized", err) + 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.NotifyPullRequestSynchronized(doer, pr) + notifier.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID) } - case "NotifyPullRequestReview": + case "NotifyIssueChangeStatus": - var unknown0 *models.PullRequest + 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.PullRequest", "NotifyPullRequestReview", err) + 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.Review + 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.Review", "NotifyPullRequestReview", err) + 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", "NotifyPullRequestReview", err) + 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.NotifyPullRequestReview(unknown0, unknown1, unknown2) + notifier.NotifyIssueChangeStatus(unknown0, unknown1, unknown2, unknown3) } - case "NotifyPullRequestChangeTargetBranch": + 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", "NotifyPullRequestChangeTargetBranch", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyIssueChangeTitle", err) continue } - var pr *models.PullRequest - err = json.Unmarshal(call.Args[1], &pr) + 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.PullRequest", "NotifyPullRequestChangeTargetBranch", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Issue", "NotifyIssueChangeTitle", err) continue } - var oldBranch string - err = json.Unmarshal(call.Args[2], &oldBranch) + 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", "NotifyPullRequestChangeTargetBranch", err) + 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.NotifyPullRequestChangeTargetBranch(doer, pr, oldBranch) + notifier.NotifyIssueChangeTitle(doer, issue, oldTitle) } - case "NotifyCreateIssueComment": + case "NotifyIssueClearLabels": - var unknown0 *models.User - err = json.Unmarshal(call.Args[0], &unknown0) + 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", "NotifyCreateIssueComment", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyIssueClearLabels", err) continue } - var unknown1 *models.Repository - err = json.Unmarshal(call.Args[1], &unknown1) + 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.Repository", "NotifyCreateIssueComment", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Issue", "NotifyIssueClearLabels", err) continue } - var unknown2 *models.Issue - err = json.Unmarshal(call.Args[2], &unknown2) + 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[2]), "*models.Issue", "NotifyCreateIssueComment", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.PullRequest", "NotifyMergePullRequest", err) continue } - var unknown3 *models.Comment - err = json.Unmarshal(call.Args[3], &unknown3) + 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[3]), "*models.Comment", "NotifyCreateIssueComment", err) + 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.NotifyCreateIssueComment(unknown0, unknown1, unknown2, unknown3) + notifier.NotifyMergePullRequest(unknown0, unknown1) } - case "NotifyUpdateComment": + case "NotifyMigrateRepository": - var unknown0 *models.User - err = json.Unmarshal(call.Args[0], &unknown0) + 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", "NotifyUpdateComment", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyMigrateRepository", err) continue } - var unknown1 *models.Comment - err = json.Unmarshal(call.Args[1], &unknown1) + 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.Comment", "NotifyUpdateComment", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.User", "NotifyMigrateRepository", err) continue } - var unknown2 string - err = json.Unmarshal(call.Args[2], &unknown2) + 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]), "string", "NotifyUpdateComment", err) + 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.NotifyUpdateComment(unknown0, unknown1, unknown2) + notifier.NotifyMigrateRepository(doer, u, repo) } - case "NotifyDeleteComment": + case "NotifyNewIssue": - var unknown0 *models.User + 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.User", "NotifyDeleteComment", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.Issue", "NotifyNewIssue", err) continue } - var unknown1 *models.Comment - err = json.Unmarshal(call.Args[1], &unknown1) + 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[1]), "*models.Comment", "NotifyDeleteComment", err) + 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.NotifyDeleteComment(unknown0, unknown1) + notifier.NotifyNewPullRequest(unknown0) } case "NotifyNewRelease": @@ -551,39 +489,68 @@ func (q *QueueNotifier) handle(data ...queue.Data) { for _, notifier := range q.notifiers { notifier.NotifyNewRelease(rel) } - case "NotifyUpdateRelease": + 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", "NotifyUpdateRelease", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyPullRequestChangeTargetBranch", err) continue } - var rel *models.Release - err = json.Unmarshal(call.Args[1], &rel) + 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.Release", "NotifyUpdateRelease", err) + 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.NotifyUpdateRelease(doer, rel) + notifier.NotifyPullRequestChangeTargetBranch(doer, pr, oldBranch) } - case "NotifyDeleteRelease": + 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", "NotifyDeleteRelease", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyPullRequestSynchronized", err) continue } - var rel *models.Release - err = json.Unmarshal(call.Args[1], &rel) + 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.Release", "NotifyDeleteRelease", err) + 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.NotifyDeleteRelease(doer, rel) + notifier.NotifyPullRequestSynchronized(doer, pr) } case "NotifyPushCommits": @@ -626,63 +593,86 @@ func (q *QueueNotifier) handle(data ...queue.Data) { for _, notifier := range q.notifiers { notifier.NotifyPushCommits(pusher, repo, refName, oldCommitID, newCommitID, commits) } - case "NotifyCreateRef": + 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", "NotifyCreateRef", err) + 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", "NotifyCreateRef", err) + 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", "NotifyCreateRef", err) + 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", "NotifyCreateRef", err) + 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.NotifyCreateRef(doer, repo, refType, refFullName) + notifier.NotifySyncCreateRef(doer, repo, refType, refFullName) } - case "NotifyDeleteRef": + 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", "NotifyDeleteRef", err) + 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", "NotifyDeleteRef", err) + 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", "NotifyDeleteRef", err) + 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", "NotifyDeleteRef", err) + 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.NotifyDeleteRef(doer, repo, refType, refFullName) + notifier.NotifySyncDeleteRef(doer, repo, refType, refFullName) } case "NotifySyncPushCommits": @@ -725,63 +715,73 @@ func (q *QueueNotifier) handle(data ...queue.Data) { for _, notifier := range q.notifiers { notifier.NotifySyncPushCommits(pusher, repo, refName, oldCommitID, newCommitID, commits) } - case "NotifySyncCreateRef": + 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", "NotifySyncCreateRef", err) + 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", "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) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Repository", "NotifyTransferRepository", err) continue } - var refFullName string - err = json.Unmarshal(call.Args[3], &refFullName) + 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[3]), "string", "NotifySyncCreateRef", err) + 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.NotifySyncCreateRef(doer, repo, refType, refFullName) + notifier.NotifyTransferRepository(doer, repo, oldOwnerName) } - case "NotifySyncDeleteRef": + case "NotifyUpdateComment": - var doer *models.User - err = json.Unmarshal(call.Args[0], &doer) + 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", "NotifySyncDeleteRef", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[0]), "*models.User", "NotifyUpdateComment", err) continue } - var repo *models.Repository - err = json.Unmarshal(call.Args[1], &repo) + 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.Repository", "NotifySyncDeleteRef", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[1]), "*models.Comment", "NotifyUpdateComment", err) continue } - var refType string - err = json.Unmarshal(call.Args[2], &refType) + 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", "NotifySyncDeleteRef", err) + log.Error("Unable to unmarshal %s to %s in call to %s: %v", string(call.Args[2]), "string", "NotifyUpdateComment", err) continue } - var refFullName string - err = json.Unmarshal(call.Args[3], &refFullName) + 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[3]), "string", "NotifySyncDeleteRef", err) + 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.NotifySyncDeleteRef(doer, repo, refType, refFullName) + 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)) @@ -796,38 +796,44 @@ func (q *QueueNotifier) Run() { graceful.GetManager().RunWithShutdownFns(q.internal.Run) } -// NotifyCreateRepository is a placeholder function -func (q *QueueNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) { +// 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(&doer) + 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 doer: %v", err) + log.Error("Unable to marshall unknown1: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&u) + bs, err = json.Marshal(&unknown2) if err != nil { - log.Error("Unable to marshall u: %v", err) + log.Error("Unable to marshall unknown2: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&repo) + bs, err = json.Marshal(&unknown3) if err != nil { - log.Error("Unable to marshall repo: %v", err) + log.Error("Unable to marshall unknown3: %v", err) return } args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyCreateRepository", + Name: "NotifyCreateIssueComment", Args: args, }) } -// NotifyMigrateRepository is a placeholder function -func (q *QueueNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) { +// 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 @@ -837,51 +843,33 @@ func (q *QueueNotifier) NotifyMigrateRepository(doer *models.User, u *models.Use 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, - }) -} - -// 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) + bs, err = json.Marshal(&refType) if err != nil { - log.Error("Unable to marshall doer: %v", err) + log.Error("Unable to marshall refType: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&repo) + bs, err = json.Marshal(&refFullName) if err != nil { - log.Error("Unable to marshall repo: %v", err) + log.Error("Unable to marshall refFullName: %v", err) return } args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyDeleteRepository", + Name: "NotifyCreateRef", Args: args, }) } -// NotifyForkRepository is a placeholder function -func (q *QueueNotifier) NotifyForkRepository(doer *models.User, oldRepo *models.Repository, repo *models.Repository) { +// 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 @@ -891,9 +879,9 @@ func (q *QueueNotifier) NotifyForkRepository(doer *models.User, oldRepo *models. return } args = append(args, bs) - bs, err = json.Marshal(&oldRepo) + bs, err = json.Marshal(&u) if err != nil { - log.Error("Unable to marshall oldRepo: %v", err) + log.Error("Unable to marshall u: %v", err) return } args = append(args, bs) @@ -905,43 +893,37 @@ func (q *QueueNotifier) NotifyForkRepository(doer *models.User, oldRepo *models. args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyForkRepository", + Name: "NotifyCreateRepository", Args: args, }) } -// NotifyRenameRepository is a placeholder function -func (q *QueueNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldRepoName string) { +// 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(&doer) - if err != nil { - log.Error("Unable to marshall doer: %v", err) - return - } - args = append(args, bs) - bs, err = json.Marshal(&repo) + bs, err = json.Marshal(&unknown0) if err != nil { - log.Error("Unable to marshall repo: %v", err) + log.Error("Unable to marshall unknown0: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&oldRepoName) + bs, err = json.Marshal(&unknown1) if err != nil { - log.Error("Unable to marshall oldRepoName: %v", err) + log.Error("Unable to marshall unknown1: %v", err) return } args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyRenameRepository", + Name: "NotifyDeleteComment", Args: args, }) } -// NotifyTransferRepository is a placeholder function -func (q *QueueNotifier) NotifyTransferRepository(doer *models.User, repo *models.Repository, oldOwnerName string) { +// 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 @@ -957,75 +939,75 @@ func (q *QueueNotifier) NotifyTransferRepository(doer *models.User, repo *models return } args = append(args, bs) - bs, err = json.Marshal(&oldOwnerName) + bs, err = json.Marshal(&refType) if err != nil { - log.Error("Unable to marshall oldOwnerName: %v", err) + 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: "NotifyTransferRepository", + Name: "NotifyDeleteRef", Args: args, }) } -// NotifyNewIssue is a placeholder function -func (q *QueueNotifier) NotifyNewIssue(unknown0 *models.Issue) { +// 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(&unknown0) + bs, err = json.Marshal(&doer) if err != nil { - log.Error("Unable to marshall unknown0: %v", err) + 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: "NotifyNewIssue", + Name: "NotifyDeleteRelease", Args: args, }) } -// NotifyIssueChangeStatus is a placeholder function -func (q *QueueNotifier) NotifyIssueChangeStatus(unknown0 *models.User, unknown1 *models.Issue, unknown2 *models.Comment, unknown3 bool) { +// 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(&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) + bs, err = json.Marshal(&doer) if err != nil { - log.Error("Unable to marshall unknown2: %v", err) + log.Error("Unable to marshall doer: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&unknown3) + bs, err = json.Marshal(&repo) if err != nil { - log.Error("Unable to marshall unknown3: %v", err) + log.Error("Unable to marshall repo: %v", err) return } args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyIssueChangeStatus", + Name: "NotifyDeleteRepository", Args: args, }) } -// NotifyIssueChangeMilestone is a placeholder function -func (q *QueueNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue, oldMilestoneID int64) { +// 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 @@ -1035,21 +1017,21 @@ func (q *QueueNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *mod return } args = append(args, bs) - bs, err = json.Marshal(&issue) + bs, err = json.Marshal(&oldRepo) if err != nil { - log.Error("Unable to marshall issue: %v", err) + log.Error("Unable to marshall oldRepo: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&oldMilestoneID) + bs, err = json.Marshal(&repo) if err != nil { - log.Error("Unable to marshall oldMilestoneID: %v", err) + log.Error("Unable to marshall repo: %v", err) return } args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyIssueChangeMilestone", + Name: "NotifyForkRepository", Args: args, }) } @@ -1126,60 +1108,6 @@ func (q *QueueNotifier) NotifyIssueChangeContent(doer *models.User, issue *model }) } -// 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, - }) -} - -// 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, - }) -} - // 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) @@ -1216,74 +1144,38 @@ func (q *QueueNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models }) } -// 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, - }) -} - -// NotifyMergePullRequest is a placeholder function -func (q *QueueNotifier) NotifyMergePullRequest(unknown0 *models.PullRequest, unknown1 *models.User) { +// 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(&unknown0) - if err != nil { - log.Error("Unable to marshall unknown0: %v", err) - return - } - args = append(args, bs) - bs, err = json.Marshal(&unknown1) + bs, err = json.Marshal(&doer) if err != nil { - log.Error("Unable to marshall unknown1: %v", err) + log.Error("Unable to marshall doer: %v", err) return } args = append(args, bs) - - q.internal.Push(&FunctionCall{ - Name: "NotifyMergePullRequest", - 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) + bs, err = json.Marshal(&issue) if err != nil { - log.Error("Unable to marshall doer: %v", err) + log.Error("Unable to marshall issue: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&pr) + bs, err = json.Marshal(&oldMilestoneID) if err != nil { - log.Error("Unable to marshall pr: %v", err) + log.Error("Unable to marshall oldMilestoneID: %v", err) return } args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyPullRequestSynchronized", + Name: "NotifyIssueChangeMilestone", Args: args, }) } -// NotifyPullRequestReview is a placeholder function -func (q *QueueNotifier) NotifyPullRequestReview(unknown0 *models.PullRequest, unknown1 *models.Review, unknown2 *models.Comment) { +// 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 @@ -1305,15 +1197,21 @@ func (q *QueueNotifier) NotifyPullRequestReview(unknown0 *models.PullRequest, un 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: "NotifyPullRequestReview", + Name: "NotifyIssueChangeStatus", Args: args, }) } -// NotifyPullRequestChangeTargetBranch is a placeholder function -func (q *QueueNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, pr *models.PullRequest, oldBranch string) { +// 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 @@ -1323,93 +1221,105 @@ func (q *QueueNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User, p return } args = append(args, bs) - bs, err = json.Marshal(&pr) + bs, err = json.Marshal(&issue) if err != nil { - log.Error("Unable to marshall pr: %v", err) + log.Error("Unable to marshall issue: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&oldBranch) + bs, err = json.Marshal(&oldTitle) if err != nil { - log.Error("Unable to marshall oldBranch: %v", err) + log.Error("Unable to marshall oldTitle: %v", err) return } args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyPullRequestChangeTargetBranch", + Name: "NotifyIssueChangeTitle", Args: args, }) } -// NotifyCreateIssueComment is a placeholder function -func (q *QueueNotifier) NotifyCreateIssueComment(unknown0 *models.User, unknown1 *models.Repository, unknown2 *models.Issue, unknown3 *models.Comment) { +// 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(&unknown0) + bs, err = json.Marshal(&doer) if err != nil { - log.Error("Unable to marshall unknown0: %v", err) + log.Error("Unable to marshall doer: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&unknown1) + bs, err = json.Marshal(&issue) if err != nil { - log.Error("Unable to marshall unknown1: %v", err) + log.Error("Unable to marshall issue: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&unknown2) + + 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 unknown2: %v", err) + log.Error("Unable to marshall unknown0: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&unknown3) + bs, err = json.Marshal(&unknown1) if err != nil { - log.Error("Unable to marshall unknown3: %v", err) + log.Error("Unable to marshall unknown1: %v", err) return } args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyCreateIssueComment", + Name: "NotifyMergePullRequest", Args: args, }) } -// NotifyUpdateComment is a placeholder function -func (q *QueueNotifier) NotifyUpdateComment(unknown0 *models.User, unknown1 *models.Comment, unknown2 string) { +// 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(&unknown0) + bs, err = json.Marshal(&doer) if err != nil { - log.Error("Unable to marshall unknown0: %v", err) + log.Error("Unable to marshall doer: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&unknown1) + bs, err = json.Marshal(&u) if err != nil { - log.Error("Unable to marshall unknown1: %v", err) + log.Error("Unable to marshall u: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&unknown2) + bs, err = json.Marshal(&repo) if err != nil { - log.Error("Unable to marshall unknown2: %v", err) + log.Error("Unable to marshall repo: %v", err) return } args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyUpdateComment", + Name: "NotifyMigrateRepository", Args: args, }) } -// NotifyDeleteComment is a placeholder function -func (q *QueueNotifier) NotifyDeleteComment(unknown0 *models.User, unknown1 *models.Comment) { +// NotifyNewIssue is a placeholder function +func (q *QueueNotifier) NotifyNewIssue(unknown0 *models.Issue) { args := make([][]byte, 0) var err error var bs []byte @@ -1419,15 +1329,27 @@ func (q *QueueNotifier) NotifyDeleteComment(unknown0 *models.User, unknown1 *mod return } args = append(args, bs) - bs, err = json.Marshal(&unknown1) + + 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 unknown1: %v", err) + log.Error("Unable to marshall unknown0: %v", err) return } args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyDeleteComment", + Name: "NotifyNewPullRequest", Args: args, }) } @@ -1450,8 +1372,8 @@ func (q *QueueNotifier) NotifyNewRelease(rel *models.Release) { }) } -// NotifyUpdateRelease is a placeholder function -func (q *QueueNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) { +// 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 @@ -1461,21 +1383,57 @@ func (q *QueueNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Relea return } args = append(args, bs) - bs, err = json.Marshal(&rel) + bs, err = json.Marshal(&pr) if err != nil { - log.Error("Unable to marshall rel: %v", err) + 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: "NotifyUpdateRelease", + Name: "NotifyPullRequestChangeTargetBranch", Args: args, }) } -// NotifyDeleteRelease is a placeholder function -func (q *QueueNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) { +// 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 @@ -1485,15 +1443,15 @@ func (q *QueueNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Relea return } args = append(args, bs) - bs, err = json.Marshal(&rel) + bs, err = json.Marshal(&pr) if err != nil { - log.Error("Unable to marshall rel: %v", err) + log.Error("Unable to marshall pr: %v", err) return } args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyDeleteRelease", + Name: "NotifyPullRequestSynchronized", Args: args, }) } @@ -1546,8 +1504,38 @@ func (q *QueueNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repo }) } -// NotifyCreateRef is a placeholder function -func (q *QueueNotifier) NotifyCreateRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { +// 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 @@ -1577,13 +1565,13 @@ func (q *QueueNotifier) NotifyCreateRef(doer *models.User, repo *models.Reposito args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyCreateRef", + Name: "NotifySyncCreateRef", Args: args, }) } -// NotifyDeleteRef is a placeholder function -func (q *QueueNotifier) NotifyDeleteRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { +// 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 @@ -1613,7 +1601,7 @@ func (q *QueueNotifier) NotifyDeleteRef(doer *models.User, repo *models.Reposito args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifyDeleteRef", + Name: "NotifySyncDeleteRef", Args: args, }) } @@ -1666,8 +1654,8 @@ func (q *QueueNotifier) NotifySyncPushCommits(pusher *models.User, repo *models. }) } -// NotifySyncCreateRef is a placeholder function -func (q *QueueNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { +// 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 @@ -1683,57 +1671,69 @@ func (q *QueueNotifier) NotifySyncCreateRef(doer *models.User, repo *models.Repo 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) + bs, err = json.Marshal(&oldOwnerName) if err != nil { - log.Error("Unable to marshall refFullName: %v", err) + log.Error("Unable to marshall oldOwnerName: %v", err) return } args = append(args, bs) q.internal.Push(&FunctionCall{ - Name: "NotifySyncCreateRef", + Name: "NotifyTransferRepository", Args: args, }) } -// NotifySyncDeleteRef is a placeholder function -func (q *QueueNotifier) NotifySyncDeleteRef(doer *models.User, repo *models.Repository, refType string, refFullName string) { +// 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(&doer) + bs, err = json.Marshal(&unknown0) if err != nil { - log.Error("Unable to marshall doer: %v", err) + log.Error("Unable to marshall unknown0: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&repo) + bs, err = json.Marshal(&unknown1) if err != nil { - log.Error("Unable to marshall repo: %v", err) + log.Error("Unable to marshall unknown1: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&refType) + bs, err = json.Marshal(&unknown2) if err != nil { - log.Error("Unable to marshall refType: %v", err) + log.Error("Unable to marshall unknown2: %v", err) return } args = append(args, bs) - bs, err = json.Marshal(&refFullName) + + 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 refFullName: %v", err) + 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: "NotifySyncDeleteRef", + Name: "NotifyUpdateRelease", Args: args, }) } From e090f8e06f47abab8051b9bd3e6d1781fdd6dab6 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Wed, 22 Jan 2020 17:21:50 +0000 Subject: [PATCH 6/8] Ensure fork has unique name in pull_merge_test --- integrations/pull_merge_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/integrations/pull_merge_test.go b/integrations/pull_merge_test.go index 47cb6e9cbecfb..71667b0f95e48 100644 --- a/integrations/pull_merge_test.go +++ b/integrations/pull_merge_test.go @@ -88,10 +88,10 @@ func TestPullMerge(t *testing.T) { 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) @@ -99,7 +99,7 @@ func TestPullMerge(t *testing.T) { pr.LoadHeadRepo() return pr.BaseRepo.FullName() == "user2/repo1" && pr.BaseBranch == "master" && - pr.HeadRepo.FullName() == "user1/repo1" && + pr.HeadRepo.FullName() == "user1/repo1-TestPullMerge" && pr.HeadBranch == "master" } From a7ad2ab4604fca9218e21d6841df9d30f883812f Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sat, 15 Feb 2020 12:10:46 +0000 Subject: [PATCH 7/8] Remove unnecessary load of assignee --- routers/api/v1/repo/issue_comment.go | 1 - 1 file changed, 1 deletion(-) diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 18c25b6fd29cb..6713a8a78e2f0 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -413,7 +413,6 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) ctx.Error(http.StatusInternalServerError, "UpdateComment", err) return } - _ = comment.LoadAssigneeUser() _ = comment.LoadPoster() ctx.JSON(http.StatusOK, comment.APIFormat()) From c21e6e9d8ac374ddb3d0a2903d0c3fec64675e7e Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Thu, 30 Apr 2020 19:54:32 +0100 Subject: [PATCH 8/8] placate lint Signed-off-by: Andrew Thornton --- modules/notification/base/main.go | 19 ++++++++++++------- modules/notification/base/null.go | 3 +++ modules/notification/base/queue.go | 3 +++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/modules/notification/base/main.go b/modules/notification/base/main.go index dc22145ec7fd0..18e61963509c1 100644 --- a/modules/notification/base/main.go +++ b/modules/notification/base/main.go @@ -113,12 +113,12 @@ func main() { // 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(), - }) - } + def.Args = append(def.Args, funcDefArg{ + Name: ident.Name, + Type: sb.String(), + }) } + } } funcs[i] = def } @@ -174,7 +174,9 @@ func main() { } -var queueTemplate = template.Must(template.New("").Parse(` +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 @@ -283,7 +285,10 @@ func (q *QueueNotifier) {{ .Name }}({{ range $i, $e := .Args }}{{ if $i }}, {{ e {{- end }} `)) -var nullTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT. +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 ( diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go index 36f27fb370ce4..da756fe6dc5e6 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -1,3 +1,6 @@ +// 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 diff --git a/modules/notification/base/queue.go b/modules/notification/base/queue.go index 50a1ac5a3099e..19a54cfa21e45 100644 --- a/modules/notification/base/queue.go +++ b/modules/notification/base/queue.go @@ -1,3 +1,6 @@ +// 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