@ -13,17 +13,21 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
api "code.gitea.io/gitea/modules/structs"
webhook_module "code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/services/convert"
"code.gitea.io/gitea/services/convert"
webhook_services "code.gitea.io/gitea/services/webhook"
)
)
func init ( ) {
notification . RegisterNotifier ( & webhookNotifier { } )
}
type webhookNotifier struct {
type webhookNotifier struct {
base . NullNotifier
base . NullNotifier
}
}
@ -54,7 +58,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(ctx context.Context, doer *user
return
return
}
}
err = webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventPullRequestLabel , & api . PullRequestPayload {
err = PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventPullRequestLabel , & api . PullRequestPayload {
Action : api . HookIssueLabelCleared ,
Action : api . HookIssueLabelCleared ,
Index : issue . Index ,
Index : issue . Index ,
PullRequest : convert . ToAPIPullRequest ( ctx , issue . PullRequest , nil ) ,
PullRequest : convert . ToAPIPullRequest ( ctx , issue . PullRequest , nil ) ,
@ -62,7 +66,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(ctx context.Context, doer *user
Sender : convert . ToUser ( doer , nil ) ,
Sender : convert . ToUser ( doer , nil ) ,
} )
} )
} else {
} else {
err = webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventIssueLabel , & api . IssuePayload {
err = PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventIssueLabel , & api . IssuePayload {
Action : api . HookIssueLabelCleared ,
Action : api . HookIssueLabelCleared ,
Index : issue . Index ,
Index : issue . Index ,
Issue : convert . ToAPIIssue ( ctx , issue ) ,
Issue : convert . ToAPIIssue ( ctx , issue ) ,
@ -80,7 +84,7 @@ func (m *webhookNotifier) NotifyForkRepository(ctx context.Context, doer *user_m
mode , _ := access_model . AccessLevel ( ctx , doer , repo )
mode , _ := access_model . AccessLevel ( ctx , doer , repo )
// forked webhook
// forked webhook
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : oldRepo } , webhook . HookEventFork , & api . ForkPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : oldRepo } , webhook_module . HookEventFork , & api . ForkPayload {
Forkee : convert . ToRepo ( ctx , oldRepo , oldMode ) ,
Forkee : convert . ToRepo ( ctx , oldRepo , oldMode ) ,
Repo : convert . ToRepo ( ctx , repo , mode ) ,
Repo : convert . ToRepo ( ctx , repo , mode ) ,
Sender : convert . ToUser ( doer , nil ) ,
Sender : convert . ToUser ( doer , nil ) ,
@ -92,7 +96,7 @@ func (m *webhookNotifier) NotifyForkRepository(ctx context.Context, doer *user_m
// Add to hook queue for created repo after session commit.
// Add to hook queue for created repo after session commit.
if u . IsOrganization ( ) {
if u . IsOrganization ( ) {
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : repo } , webhook . HookEventRepository , & api . RepositoryPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : repo } , webhook_module . HookEventRepository , & api . RepositoryPayload {
Action : api . HookRepoCreated ,
Action : api . HookRepoCreated ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Organization : convert . ToUser ( u , nil ) ,
Organization : convert . ToUser ( u , nil ) ,
@ -105,7 +109,7 @@ func (m *webhookNotifier) NotifyForkRepository(ctx context.Context, doer *user_m
func ( m * webhookNotifier ) NotifyCreateRepository ( ctx context . Context , doer , u * user_model . User , repo * repo_model . Repository ) {
func ( m * webhookNotifier ) NotifyCreateRepository ( ctx context . Context , doer , u * user_model . User , repo * repo_model . Repository ) {
// Add to hook queue for created repo after session commit.
// Add to hook queue for created repo after session commit.
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : repo } , webhook . HookEventRepository , & api . RepositoryPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : repo } , webhook_module . HookEventRepository , & api . RepositoryPayload {
Action : api . HookRepoCreated ,
Action : api . HookRepoCreated ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Organization : convert . ToUser ( u , nil ) ,
Organization : convert . ToUser ( u , nil ) ,
@ -116,7 +120,7 @@ func (m *webhookNotifier) NotifyCreateRepository(ctx context.Context, doer, u *u
}
}
func ( m * webhookNotifier ) NotifyDeleteRepository ( ctx context . Context , doer * user_model . User , repo * repo_model . Repository ) {
func ( m * webhookNotifier ) NotifyDeleteRepository ( ctx context . Context , doer * user_model . User , repo * repo_model . Repository ) {
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : repo } , webhook . HookEventRepository , & api . RepositoryPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : repo } , webhook_module . HookEventRepository , & api . RepositoryPayload {
Action : api . HookRepoDeleted ,
Action : api . HookRepoDeleted ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Organization : convert . ToUser ( repo . MustOwner ( ctx ) , nil ) ,
Organization : convert . ToUser ( repo . MustOwner ( ctx ) , nil ) ,
@ -128,7 +132,7 @@ func (m *webhookNotifier) NotifyDeleteRepository(ctx context.Context, doer *user
func ( m * webhookNotifier ) NotifyMigrateRepository ( ctx context . Context , doer , u * user_model . User , repo * repo_model . Repository ) {
func ( m * webhookNotifier ) NotifyMigrateRepository ( ctx context . Context , doer , u * user_model . User , repo * repo_model . Repository ) {
// Add to hook queue for created repo after session commit.
// Add to hook queue for created repo after session commit.
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : repo } , webhook . HookEventRepository , & api . RepositoryPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : repo } , webhook_module . HookEventRepository , & api . RepositoryPayload {
Action : api . HookRepoCreated ,
Action : api . HookRepoCreated ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Organization : convert . ToUser ( u , nil ) ,
Organization : convert . ToUser ( u , nil ) ,
@ -159,7 +163,7 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *u
apiPullRequest . Action = api . HookIssueAssigned
apiPullRequest . Action = api . HookIssueAssigned
}
}
// Assignee comment triggers a webhook
// Assignee comment triggers a webhook
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventPullRequestAssign , apiPullRequest ) ; err != nil {
if err := PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventPullRequestAssign , apiPullRequest ) ; err != nil {
log . Error ( "PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v" , issue . IsPull , removed , err )
log . Error ( "PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v" , issue . IsPull , removed , err )
return
return
}
}
@ -177,7 +181,7 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(ctx context.Context, doer *u
apiIssue . Action = api . HookIssueAssigned
apiIssue . Action = api . HookIssueAssigned
}
}
// Assignee comment triggers a webhook
// Assignee comment triggers a webhook
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventIssueAssign , apiIssue ) ; err != nil {
if err := PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventIssueAssign , apiIssue ) ; err != nil {
log . Error ( "PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v" , issue . IsPull , removed , err )
log . Error ( "PrepareWebhooks [is_pull: %v, remove_assignee: %v]: %v" , issue . IsPull , removed , err )
return
return
}
}
@ -193,7 +197,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user
return
return
}
}
issue . PullRequest . Issue = issue
issue . PullRequest . Issue = issue
err = webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventPullRequest , & api . PullRequestPayload {
err = PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventPullRequest , & api . PullRequestPayload {
Action : api . HookIssueEdited ,
Action : api . HookIssueEdited ,
Index : issue . Index ,
Index : issue . Index ,
Changes : & api . ChangesPayload {
Changes : & api . ChangesPayload {
@ -206,7 +210,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(ctx context.Context, doer *user
Sender : convert . ToUser ( doer , nil ) ,
Sender : convert . ToUser ( doer , nil ) ,
} )
} )
} else {
} else {
err = webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventIssues , & api . IssuePayload {
err = PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventIssues , & api . IssuePayload {
Action : api . HookIssueEdited ,
Action : api . HookIssueEdited ,
Index : issue . Index ,
Index : issue . Index ,
Changes : & api . ChangesPayload {
Changes : & api . ChangesPayload {
@ -245,7 +249,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use
} else {
} else {
apiPullRequest . Action = api . HookIssueReOpened
apiPullRequest . Action = api . HookIssueReOpened
}
}
err = webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventPullRequest , apiPullRequest )
err = PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventPullRequest , apiPullRequest )
} else {
} else {
apiIssue := & api . IssuePayload {
apiIssue := & api . IssuePayload {
Index : issue . Index ,
Index : issue . Index ,
@ -258,7 +262,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(ctx context.Context, doer *use
} else {
} else {
apiIssue . Action = api . HookIssueReOpened
apiIssue . Action = api . HookIssueReOpened
}
}
err = webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventIssues , apiIssue )
err = PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventIssues , apiIssue )
}
}
if err != nil {
if err != nil {
log . Error ( "PrepareWebhooks [is_pull: %v, is_closed: %v]: %v" , issue . IsPull , isClosed , err )
log . Error ( "PrepareWebhooks [is_pull: %v, is_closed: %v]: %v" , issue . IsPull , isClosed , err )
@ -276,7 +280,7 @@ func (m *webhookNotifier) NotifyNewIssue(ctx context.Context, issue *issues_mode
}
}
mode , _ := access_model . AccessLevel ( ctx , issue . Poster , issue . Repo )
mode , _ := access_model . AccessLevel ( ctx , issue . Poster , issue . Repo )
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventIssues , & api . IssuePayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventIssues , & api . IssuePayload {
Action : api . HookIssueOpened ,
Action : api . HookIssueOpened ,
Index : issue . Index ,
Index : issue . Index ,
Issue : convert . ToAPIIssue ( ctx , issue ) ,
Issue : convert . ToAPIIssue ( ctx , issue ) ,
@ -302,7 +306,7 @@ func (m *webhookNotifier) NotifyNewPullRequest(ctx context.Context, pull *issues
}
}
mode , _ := access_model . AccessLevel ( ctx , pull . Issue . Poster , pull . Issue . Repo )
mode , _ := access_model . AccessLevel ( ctx , pull . Issue . Poster , pull . Issue . Repo )
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : pull . Issue . Repo } , webhook . HookEventPullRequest , & api . PullRequestPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : pull . Issue . Repo } , webhook_module . HookEventPullRequest , & api . PullRequestPayload {
Action : api . HookIssueOpened ,
Action : api . HookIssueOpened ,
Index : pull . Issue . Index ,
Index : pull . Issue . Index ,
PullRequest : convert . ToAPIPullRequest ( ctx , pull , nil ) ,
PullRequest : convert . ToAPIPullRequest ( ctx , pull , nil ) ,
@ -323,7 +327,7 @@ func (m *webhookNotifier) NotifyIssueChangeContent(ctx context.Context, doer *us
var err error
var err error
if issue . IsPull {
if issue . IsPull {
issue . PullRequest . Issue = issue
issue . PullRequest . Issue = issue
err = webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventPullRequest , & api . PullRequestPayload {
err = PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventPullRequest , & api . PullRequestPayload {
Action : api . HookIssueEdited ,
Action : api . HookIssueEdited ,
Index : issue . Index ,
Index : issue . Index ,
Changes : & api . ChangesPayload {
Changes : & api . ChangesPayload {
@ -336,7 +340,7 @@ func (m *webhookNotifier) NotifyIssueChangeContent(ctx context.Context, doer *us
Sender : convert . ToUser ( doer , nil ) ,
Sender : convert . ToUser ( doer , nil ) ,
} )
} )
} else {
} else {
err = webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventIssues , & api . IssuePayload {
err = PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventIssues , & api . IssuePayload {
Action : api . HookIssueEdited ,
Action : api . HookIssueEdited ,
Index : issue . Index ,
Index : issue . Index ,
Changes : & api . ChangesPayload {
Changes : & api . ChangesPayload {
@ -369,15 +373,15 @@ func (m *webhookNotifier) NotifyUpdateComment(ctx context.Context, doer *user_mo
return
return
}
}
var eventType webhook . HookEventType
var eventType webhook_module . HookEventType
if c . Issue . IsPull {
if c . Issue . IsPull {
eventType = webhook . HookEventPullRequestComment
eventType = webhook_module . HookEventPullRequestComment
} else {
} else {
eventType = webhook . HookEventIssueComment
eventType = webhook_module . HookEventIssueComment
}
}
mode , _ := access_model . AccessLevel ( ctx , doer , c . Issue . Repo )
mode , _ := access_model . AccessLevel ( ctx , doer , c . Issue . Repo )
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : c . Issue . Repo } , eventType , & api . IssueCommentPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : c . Issue . Repo } , eventType , & api . IssueCommentPayload {
Action : api . HookIssueCommentEdited ,
Action : api . HookIssueCommentEdited ,
Issue : convert . ToAPIIssue ( ctx , c . Issue ) ,
Issue : convert . ToAPIIssue ( ctx , c . Issue ) ,
Comment : convert . ToComment ( c ) ,
Comment : convert . ToComment ( c ) ,
@ -397,15 +401,15 @@ func (m *webhookNotifier) NotifyUpdateComment(ctx context.Context, doer *user_mo
func ( m * webhookNotifier ) NotifyCreateIssueComment ( ctx context . Context , doer * user_model . User , repo * repo_model . Repository ,
func ( m * webhookNotifier ) NotifyCreateIssueComment ( ctx context . Context , doer * user_model . User , repo * repo_model . Repository ,
issue * issues_model . Issue , comment * issues_model . Comment , mentions [ ] * user_model . User ,
issue * issues_model . Issue , comment * issues_model . Comment , mentions [ ] * user_model . User ,
) {
) {
var eventType webhook . HookEventType
var eventType webhook_module . HookEventType
if issue . IsPull {
if issue . IsPull {
eventType = webhook . HookEventPullRequestComment
eventType = webhook_module . HookEventPullRequestComment
} else {
} else {
eventType = webhook . HookEventIssueComment
eventType = webhook_module . HookEventIssueComment
}
}
mode , _ := access_model . AccessLevel ( ctx , doer , repo )
mode , _ := access_model . AccessLevel ( ctx , doer , repo )
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , eventType , & api . IssueCommentPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , eventType , & api . IssueCommentPayload {
Action : api . HookIssueCommentCreated ,
Action : api . HookIssueCommentCreated ,
Issue : convert . ToAPIIssue ( ctx , issue ) ,
Issue : convert . ToAPIIssue ( ctx , issue ) ,
Comment : convert . ToComment ( comment ) ,
Comment : convert . ToComment ( comment ) ,
@ -434,15 +438,15 @@ func (m *webhookNotifier) NotifyDeleteComment(ctx context.Context, doer *user_mo
return
return
}
}
var eventType webhook . HookEventType
var eventType webhook_module . HookEventType
if comment . Issue . IsPull {
if comment . Issue . IsPull {
eventType = webhook . HookEventPullRequestComment
eventType = webhook_module . HookEventPullRequestComment
} else {
} else {
eventType = webhook . HookEventIssueComment
eventType = webhook_module . HookEventIssueComment
}
}
mode , _ := access_model . AccessLevel ( ctx , doer , comment . Issue . Repo )
mode , _ := access_model . AccessLevel ( ctx , doer , comment . Issue . Repo )
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : comment . Issue . Repo } , eventType , & api . IssueCommentPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : comment . Issue . Repo } , eventType , & api . IssueCommentPayload {
Action : api . HookIssueCommentDeleted ,
Action : api . HookIssueCommentDeleted ,
Issue : convert . ToAPIIssue ( ctx , comment . Issue ) ,
Issue : convert . ToAPIIssue ( ctx , comment . Issue ) ,
Comment : convert . ToComment ( comment ) ,
Comment : convert . ToComment ( comment ) ,
@ -456,7 +460,7 @@ func (m *webhookNotifier) NotifyDeleteComment(ctx context.Context, doer *user_mo
func ( m * webhookNotifier ) NotifyNewWikiPage ( ctx context . Context , doer * user_model . User , repo * repo_model . Repository , page , comment string ) {
func ( m * webhookNotifier ) NotifyNewWikiPage ( ctx context . Context , doer * user_model . User , repo * repo_model . Repository , page , comment string ) {
// Add to hook queue for created wiki page.
// Add to hook queue for created wiki page.
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : repo } , webhook . HookEventWiki , & api . WikiPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : repo } , webhook_module . HookEventWiki , & api . WikiPayload {
Action : api . HookWikiCreated ,
Action : api . HookWikiCreated ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Sender : convert . ToUser ( doer , nil ) ,
Sender : convert . ToUser ( doer , nil ) ,
@ -469,7 +473,7 @@ func (m *webhookNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_mode
func ( m * webhookNotifier ) NotifyEditWikiPage ( ctx context . Context , doer * user_model . User , repo * repo_model . Repository , page , comment string ) {
func ( m * webhookNotifier ) NotifyEditWikiPage ( ctx context . Context , doer * user_model . User , repo * repo_model . Repository , page , comment string ) {
// Add to hook queue for edit wiki page.
// Add to hook queue for edit wiki page.
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : repo } , webhook . HookEventWiki , & api . WikiPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : repo } , webhook_module . HookEventWiki , & api . WikiPayload {
Action : api . HookWikiEdited ,
Action : api . HookWikiEdited ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Sender : convert . ToUser ( doer , nil ) ,
Sender : convert . ToUser ( doer , nil ) ,
@ -482,7 +486,7 @@ func (m *webhookNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_mod
func ( m * webhookNotifier ) NotifyDeleteWikiPage ( ctx context . Context , doer * user_model . User , repo * repo_model . Repository , page string ) {
func ( m * webhookNotifier ) NotifyDeleteWikiPage ( ctx context . Context , doer * user_model . User , repo * repo_model . Repository , page string ) {
// Add to hook queue for edit wiki page.
// Add to hook queue for edit wiki page.
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : repo } , webhook . HookEventWiki , & api . WikiPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : repo } , webhook_module . HookEventWiki , & api . WikiPayload {
Action : api . HookWikiDeleted ,
Action : api . HookWikiDeleted ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Repository : convert . ToRepo ( ctx , repo , perm . AccessModeOwner ) ,
Sender : convert . ToUser ( doer , nil ) ,
Sender : convert . ToUser ( doer , nil ) ,
@ -517,7 +521,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *use
log . Error ( "LoadIssue: %v" , err )
log . Error ( "LoadIssue: %v" , err )
return
return
}
}
err = webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventPullRequestLabel , & api . PullRequestPayload {
err = PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventPullRequestLabel , & api . PullRequestPayload {
Action : api . HookIssueLabelUpdated ,
Action : api . HookIssueLabelUpdated ,
Index : issue . Index ,
Index : issue . Index ,
PullRequest : convert . ToAPIPullRequest ( ctx , issue . PullRequest , nil ) ,
PullRequest : convert . ToAPIPullRequest ( ctx , issue . PullRequest , nil ) ,
@ -525,7 +529,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(ctx context.Context, doer *use
Sender : convert . ToUser ( doer , nil ) ,
Sender : convert . ToUser ( doer , nil ) ,
} )
} )
} else {
} else {
err = webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventIssueLabel , & api . IssuePayload {
err = PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventIssueLabel , & api . IssuePayload {
Action : api . HookIssueLabelUpdated ,
Action : api . HookIssueLabelUpdated ,
Index : issue . Index ,
Index : issue . Index ,
Issue : convert . ToAPIIssue ( ctx , issue ) ,
Issue : convert . ToAPIIssue ( ctx , issue ) ,
@ -559,7 +563,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(ctx context.Context, doer *
log . Error ( "LoadIssue: %v" , err )
log . Error ( "LoadIssue: %v" , err )
return
return
}
}
err = webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventPullRequestMilestone , & api . PullRequestPayload {
err = PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventPullRequestMilestone , & api . PullRequestPayload {
Action : hookAction ,
Action : hookAction ,
Index : issue . Index ,
Index : issue . Index ,
PullRequest : convert . ToAPIPullRequest ( ctx , issue . PullRequest , nil ) ,
PullRequest : convert . ToAPIPullRequest ( ctx , issue . PullRequest , nil ) ,
@ -567,7 +571,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(ctx context.Context, doer *
Sender : convert . ToUser ( doer , nil ) ,
Sender : convert . ToUser ( doer , nil ) ,
} )
} )
} else {
} else {
err = webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventIssueMilestone , & api . IssuePayload {
err = PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventIssueMilestone , & api . IssuePayload {
Action : hookAction ,
Action : hookAction ,
Index : issue . Index ,
Index : issue . Index ,
Issue : convert . ToAPIIssue ( ctx , issue ) ,
Issue : convert . ToAPIIssue ( ctx , issue ) ,
@ -588,7 +592,7 @@ func (m *webhookNotifier) NotifyPushCommits(ctx context.Context, pusher *user_mo
return
return
}
}
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : repo } , webhook . HookEventPush , & api . PushPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : repo } , webhook_module . HookEventPush , & api . PushPayload {
Ref : opts . RefFullName ,
Ref : opts . RefFullName ,
Before : opts . OldCommitID ,
Before : opts . OldCommitID ,
After : opts . NewCommitID ,
After : opts . NewCommitID ,
@ -641,7 +645,7 @@ func (*webhookNotifier) NotifyMergePullRequest(ctx context.Context, doer *user_m
Action : api . HookIssueClosed ,
Action : api . HookIssueClosed ,
}
}
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : pr . Issue . Repo } , webhook . HookEventPullRequest , apiPullRequest ) ; err != nil {
if err := PrepareWebhooks ( ctx , EventSource { Repository : pr . Issue . Repo } , webhook_module . HookEventPullRequest , apiPullRequest ) ; err != nil {
log . Error ( "PrepareWebhooks: %v" , err )
log . Error ( "PrepareWebhooks: %v" , err )
}
}
}
}
@ -655,7 +659,7 @@ func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Contex
issue := pr . Issue
issue := pr . Issue
mode , _ := access_model . AccessLevel ( ctx , issue . Poster , issue . Repo )
mode , _ := access_model . AccessLevel ( ctx , issue . Poster , issue . Repo )
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : issue . Repo } , webhook . HookEventPullRequest , & api . PullRequestPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : issue . Repo } , webhook_module . HookEventPullRequest , & api . PullRequestPayload {
Action : api . HookIssueEdited ,
Action : api . HookIssueEdited ,
Index : issue . Index ,
Index : issue . Index ,
Changes : & api . ChangesPayload {
Changes : & api . ChangesPayload {
@ -672,15 +676,15 @@ func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Contex
}
}
func ( m * webhookNotifier ) NotifyPullRequestReview ( ctx context . Context , pr * issues_model . PullRequest , review * issues_model . Review , comment * issues_model . Comment , mentions [ ] * user_model . User ) {
func ( m * webhookNotifier ) NotifyPullRequestReview ( ctx context . Context , pr * issues_model . PullRequest , review * issues_model . Review , comment * issues_model . Comment , mentions [ ] * user_model . User ) {
var reviewHookType webhook . HookEventType
var reviewHookType webhook_module . HookEventType
switch review . Type {
switch review . Type {
case issues_model . ReviewTypeApprove :
case issues_model . ReviewTypeApprove :
reviewHookType = webhook . HookEventPullRequestReviewApproved
reviewHookType = webhook_module . HookEventPullRequestReviewApproved
case issues_model . ReviewTypeComment :
case issues_model . ReviewTypeComment :
reviewHookType = webhook . HookEventPullRequestComment
reviewHookType = webhook_module . HookEventPullRequestComment
case issues_model . ReviewTypeReject :
case issues_model . ReviewTypeReject :
reviewHookType = webhook . HookEventPullRequestReviewRejected
reviewHookType = webhook_module . HookEventPullRequestReviewRejected
default :
default :
// unsupported review webhook type here
// unsupported review webhook type here
log . Error ( "Unsupported review webhook type" )
log . Error ( "Unsupported review webhook type" )
@ -697,7 +701,7 @@ func (m *webhookNotifier) NotifyPullRequestReview(ctx context.Context, pr *issue
log . Error ( "models.AccessLevel: %v" , err )
log . Error ( "models.AccessLevel: %v" , err )
return
return
}
}
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : review . Issue . Repo } , reviewHookType , & api . PullRequestPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : review . Issue . Repo } , reviewHookType , & api . PullRequestPayload {
Action : api . HookIssueReviewed ,
Action : api . HookIssueReviewed ,
Index : review . Issue . Index ,
Index : review . Issue . Index ,
PullRequest : convert . ToAPIPullRequest ( ctx , pr , nil ) ,
PullRequest : convert . ToAPIPullRequest ( ctx , pr , nil ) ,
@ -717,7 +721,7 @@ func (m *webhookNotifier) NotifyCreateRef(ctx context.Context, pusher *user_mode
apiRepo := convert . ToRepo ( ctx , repo , perm . AccessModeNone )
apiRepo := convert . ToRepo ( ctx , repo , perm . AccessModeNone )
refName := git . RefEndName ( refFullName )
refName := git . RefEndName ( refFullName )
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : repo } , webhook . HookEventCreate , & api . CreatePayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : repo } , webhook_module . HookEventCreate , & api . CreatePayload {
Ref : refName ,
Ref : refName ,
Sha : refID ,
Sha : refID ,
RefType : refType ,
RefType : refType ,
@ -738,7 +742,7 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(ctx context.Context, doe
return
return
}
}
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : pr . Issue . Repo } , webhook . HookEventPullRequestSync , & api . PullRequestPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : pr . Issue . Repo } , webhook_module . HookEventPullRequestSync , & api . PullRequestPayload {
Action : api . HookIssueSynchronized ,
Action : api . HookIssueSynchronized ,
Index : pr . Issue . Index ,
Index : pr . Issue . Index ,
PullRequest : convert . ToAPIPullRequest ( ctx , pr , nil ) ,
PullRequest : convert . ToAPIPullRequest ( ctx , pr , nil ) ,
@ -754,7 +758,7 @@ func (m *webhookNotifier) NotifyDeleteRef(ctx context.Context, pusher *user_mode
apiRepo := convert . ToRepo ( ctx , repo , perm . AccessModeNone )
apiRepo := convert . ToRepo ( ctx , repo , perm . AccessModeNone )
refName := git . RefEndName ( refFullName )
refName := git . RefEndName ( refFullName )
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : repo } , webhook . HookEventDelete , & api . DeletePayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : repo } , webhook_module . HookEventDelete , & api . DeletePayload {
Ref : refName ,
Ref : refName ,
RefType : refType ,
RefType : refType ,
PusherType : api . PusherTypeUser ,
PusherType : api . PusherTypeUser ,
@ -772,7 +776,7 @@ func sendReleaseHook(ctx context.Context, doer *user_model.User, rel *repo_model
}
}
mode , _ := access_model . AccessLevel ( ctx , doer , rel . Repo )
mode , _ := access_model . AccessLevel ( ctx , doer , rel . Repo )
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : rel . Repo } , webhook . HookEventRelease , & api . ReleasePayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : rel . Repo } , webhook_module . HookEventRelease , & api . ReleasePayload {
Action : action ,
Action : action ,
Release : convert . ToRelease ( rel ) ,
Release : convert . ToRelease ( rel ) ,
Repository : convert . ToRepo ( ctx , rel . Repo , mode ) ,
Repository : convert . ToRepo ( ctx , rel . Repo , mode ) ,
@ -802,7 +806,7 @@ func (m *webhookNotifier) NotifySyncPushCommits(ctx context.Context, pusher *use
return
return
}
}
if err := webhook_services . PrepareWebhooks ( ctx , webhook_services . EventSource { Repository : repo } , webhook . HookEventPush , & api . PushPayload {
if err := PrepareWebhooks ( ctx , EventSource { Repository : repo } , webhook_module . HookEventPush , & api . PushPayload {
Ref : opts . RefFullName ,
Ref : opts . RefFullName ,
Before : opts . OldCommitID ,
Before : opts . OldCommitID ,
After : opts . NewCommitID ,
After : opts . NewCommitID ,
@ -835,7 +839,7 @@ func (m *webhookNotifier) NotifyPackageDelete(ctx context.Context, doer *user_mo
}
}
func notifyPackage ( ctx context . Context , sender * user_model . User , pd * packages_model . PackageDescriptor , action api . HookPackageAction ) {
func notifyPackage ( ctx context . Context , sender * user_model . User , pd * packages_model . PackageDescriptor , action api . HookPackageAction ) {
source := webhook_services . EventSource {
source := EventSource {
Repository : pd . Repository ,
Repository : pd . Repository ,
Owner : pd . Owner ,
Owner : pd . Owner ,
}
}
@ -846,7 +850,7 @@ func notifyPackage(ctx context.Context, sender *user_model.User, pd *packages_mo
return
return
}
}
if err := webhook_services . PrepareWebhooks ( ctx , source , webhook . HookEventPackage , & api . PackagePayload {
if err := PrepareWebhooks ( ctx , source , webhook_module . HookEventPackage , & api . PackagePayload {
Action : action ,
Action : action ,
Package : apiPackage ,
Package : apiPackage ,
Sender : convert . ToUser ( sender , nil ) ,
Sender : convert . ToUser ( sender , nil ) ,