|
|
@ -5,6 +5,7 @@ |
|
|
|
package models |
|
|
|
package models |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"crypto/tls" |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
@ -307,13 +308,14 @@ func DeliverHooks() { |
|
|
|
defer func() { isShooting = false }() |
|
|
|
defer func() { isShooting = false }() |
|
|
|
|
|
|
|
|
|
|
|
tasks := make([]*HookTask, 0, 10) |
|
|
|
tasks := make([]*HookTask, 0, 10) |
|
|
|
timeout := time.Duration(setting.WebhookDeliverTimeout) * time.Second |
|
|
|
timeout := time.Duration(setting.Webhook.DeliverTimeout) * time.Second |
|
|
|
x.Where("is_delivered=?", false).Iterate(new(HookTask), |
|
|
|
x.Where("is_delivered=?", false).Iterate(new(HookTask), |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
func(idx int, bean interface{}) error { |
|
|
|
t := bean.(*HookTask) |
|
|
|
t := bean.(*HookTask) |
|
|
|
req := httplib.Post(t.Url).SetTimeout(timeout, timeout). |
|
|
|
req := httplib.Post(t.Url).SetTimeout(timeout, timeout). |
|
|
|
Header("X-Gogs-Delivery", t.Uuid). |
|
|
|
Header("X-Gogs-Delivery", t.Uuid). |
|
|
|
Header("X-Gogs-Event", string(t.EventType)) |
|
|
|
Header("X-Gogs-Event", string(t.EventType)). |
|
|
|
|
|
|
|
SetTLSClientConfig(&tls.Config{InsecureSkipVerify: setting.Webhook.AllowInsecureCertification}) |
|
|
|
|
|
|
|
|
|
|
|
switch t.ContentType { |
|
|
|
switch t.ContentType { |
|
|
|
case JSON: |
|
|
|
case JSON: |
|
|
@ -329,7 +331,7 @@ func DeliverHooks() { |
|
|
|
case GOGS: |
|
|
|
case GOGS: |
|
|
|
{ |
|
|
|
{ |
|
|
|
if _, err := req.Response(); err != nil { |
|
|
|
if _, err := req.Response(); err != nil { |
|
|
|
log.Error(4, "Delivery: %v", err) |
|
|
|
log.Error(5, "Delivery: %v", err) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
t.IsSucceed = true |
|
|
|
t.IsSucceed = true |
|
|
|
} |
|
|
|
} |
|
|
@ -337,15 +339,15 @@ func DeliverHooks() { |
|
|
|
case SLACK: |
|
|
|
case SLACK: |
|
|
|
{ |
|
|
|
{ |
|
|
|
if res, err := req.Response(); err != nil { |
|
|
|
if res, err := req.Response(); err != nil { |
|
|
|
log.Error(4, "Delivery: %v", err) |
|
|
|
log.Error(5, "Delivery: %v", err) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
defer res.Body.Close() |
|
|
|
defer res.Body.Close() |
|
|
|
contents, err := ioutil.ReadAll(res.Body) |
|
|
|
contents, err := ioutil.ReadAll(res.Body) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Error(4, "%s", err) |
|
|
|
log.Error(5, "%s", err) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if string(contents) != "ok" { |
|
|
|
if string(contents) != "ok" { |
|
|
|
log.Error(4, "slack failed with: %s", string(contents)) |
|
|
|
log.Error(5, "slack failed with: %s", string(contents)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
t.IsSucceed = true |
|
|
|
t.IsSucceed = true |
|
|
|
} |
|
|
|
} |
|
|
|