@ -55,6 +55,7 @@ type OrgRepoCtx struct {
// getOrgRepoCtx determines whether this is a repo context or organization context.
// getOrgRepoCtx determines whether this is a repo context or organization context.
func getOrgRepoCtx ( ctx * context . Context ) ( * OrgRepoCtx , error ) {
func getOrgRepoCtx ( ctx * context . Context ) ( * OrgRepoCtx , error ) {
if len ( ctx . Repo . RepoLink ) > 0 {
if len ( ctx . Repo . RepoLink ) > 0 {
ctx . Data [ "PageIsRepositoryContext" ] = true
return & OrgRepoCtx {
return & OrgRepoCtx {
RepoID : ctx . Repo . Repository . ID ,
RepoID : ctx . Repo . Repository . ID ,
Link : ctx . Repo . RepoLink ,
Link : ctx . Repo . RepoLink ,
@ -63,6 +64,7 @@ func getOrgRepoCtx(ctx *context.Context) (*OrgRepoCtx, error) {
}
}
if len ( ctx . Org . OrgLink ) > 0 {
if len ( ctx . Org . OrgLink ) > 0 {
ctx . Data [ "PageIsOrganizationContext" ] = true
return & OrgRepoCtx {
return & OrgRepoCtx {
OrgID : ctx . Org . Organization . ID ,
OrgID : ctx . Org . Organization . ID ,
Link : ctx . Org . OrgLink ,
Link : ctx . Org . OrgLink ,
@ -284,11 +286,7 @@ func checkWebhook(ctx *context.Context) (*OrgRepoCtx, *models.Webhook) {
w , err = models . GetWebhookByOrgID ( ctx . Org . Organization . ID , ctx . ParamsInt64 ( ":id" ) )
w , err = models . GetWebhookByOrgID ( ctx . Org . Organization . ID , ctx . ParamsInt64 ( ":id" ) )
}
}
if err != nil {
if err != nil {
if models . IsErrWebhookNotExist ( err ) {
ctx . NotFoundOrServerError ( "GetWebhookOfRepoByID/GetWebhookByOrgID" , errors . IsWebhookNotExist , err )
ctx . Handle ( 404 , "GetWebhookByID" , nil )
} else {
ctx . Handle ( 500 , "GetWebhookByID" , err )
}
return nil , nil
return nil , nil
}
}
@ -469,8 +467,7 @@ func TestWebhook(ctx *context.Context) {
if err == nil {
if err == nil {
authorUsername = author . Name
authorUsername = author . Name
} else if ! errors . IsUserNotExist ( err ) {
} else if ! errors . IsUserNotExist ( err ) {
ctx . Flash . Error ( fmt . Sprintf ( "GetUserByEmail.(author) [%s]: %v" , commit . Author . Email , err ) )
ctx . Handle ( 500 , "GetUserByEmail.(author)" , err )
ctx . Status ( 500 )
return
return
}
}
@ -478,16 +475,14 @@ func TestWebhook(ctx *context.Context) {
if err == nil {
if err == nil {
committerUsername = committer . Name
committerUsername = committer . Name
} else if ! errors . IsUserNotExist ( err ) {
} else if ! errors . IsUserNotExist ( err ) {
ctx . Flash . Error ( fmt . Sprintf ( "GetUserByEmail.(committer) [%s]: %v" , commit . Committer . Email , err ) )
ctx . Handle ( 500 , "GetUserByEmail.(committer)" , err )
ctx . Status ( 500 )
return
return
}
}
}
}
fileStatus , err := commit . FileStatus ( )
fileStatus , err := commit . FileStatus ( )
if err != nil {
if err != nil {
ctx . Flash . Error ( "FileStatus: " + err . Error ( ) )
ctx . Handle ( 500 , "FileStatus" , err )
ctx . Status ( 500 )
return
return
}
}
@ -520,15 +515,37 @@ func TestWebhook(ctx *context.Context) {
Pusher : apiUser ,
Pusher : apiUser ,
Sender : apiUser ,
Sender : apiUser ,
}
}
if err := models . TestWebhook ( ctx . Repo . Repository , models . HOOK_EVENT_PUSH , p , ctx . QueryInt64 ( "id" ) ) ; err != nil {
if err := models . TestWebhook ( ctx . Repo . Repository , models . HOOK_EVENT_PUSH , p , ctx . ParamsInt64 ( "id" ) ) ; err != nil {
ctx . Flash . Error ( "TestWebhook: " + err . Error ( ) )
ctx . Handle ( 500 , "TestWebhook" , err )
ctx . Status ( 500 )
} else {
} else {
ctx . Flash . Info ( ctx . Tr ( "repo.settings.webhook.test_delivery_success" ) )
ctx . Flash . Info ( ctx . Tr ( "repo.settings.webhook.test_delivery_success" ) )
ctx . Status ( 200 )
ctx . Status ( 200 )
}
}
}
}
func RedeliveryWebhook ( ctx * context . Context ) {
webhook , err := models . GetWebhookOfRepoByID ( ctx . Repo . Repository . ID , ctx . ParamsInt64 ( ":id" ) )
if err != nil {
ctx . NotFoundOrServerError ( "GetWebhookOfRepoByID/GetWebhookByOrgID" , errors . IsWebhookNotExist , err )
return
}
hookTask , err := models . GetHookTaskOfWebhookByUUID ( webhook . ID , ctx . Query ( "uuid" ) )
if err != nil {
ctx . NotFoundOrServerError ( "GetHookTaskOfWebhookByUUID/GetWebhookByOrgID" , errors . IsHookTaskNotExist , err )
return
}
hookTask . IsDelivered = false
if err = models . UpdateHookTask ( hookTask ) ; err != nil {
ctx . Handle ( 500 , "UpdateHookTask" , err )
} else {
go models . HookQueue . Add ( ctx . Repo . Repository . ID )
ctx . Flash . Info ( ctx . Tr ( "repo.settings.webhook.redelivery_success" , hookTask . UUID ) )
ctx . Status ( 200 )
}
}
func DeleteWebhook ( ctx * context . Context ) {
func DeleteWebhook ( ctx * context . Context ) {
if err := models . DeleteWebhookOfRepoByID ( ctx . Repo . Repository . ID , ctx . QueryInt64 ( "id" ) ) ; err != nil {
if err := models . DeleteWebhookOfRepoByID ( ctx . Repo . Repository . ID , ctx . QueryInt64 ( "id" ) ) ; err != nil {
ctx . Flash . Error ( "DeleteWebhookByRepoID: " + err . Error ( ) )
ctx . Flash . Error ( "DeleteWebhookByRepoID: " + err . Error ( ) )