|
|
@ -7,17 +7,23 @@ package migrations |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
|
|
|
|
|
|
|
|
"xorm.io/xorm" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
func expandWebhooks(x *xorm.Engine) error { |
|
|
|
func expandWebhooks(x *xorm.Engine) error { |
|
|
|
|
|
|
|
|
|
|
|
type ChooseEvents struct { |
|
|
|
type HookEvents struct { |
|
|
|
|
|
|
|
Create bool `json:"create"` |
|
|
|
|
|
|
|
Delete bool `json:"delete"` |
|
|
|
|
|
|
|
Fork bool `json:"fork"` |
|
|
|
Issues bool `json:"issues"` |
|
|
|
Issues bool `json:"issues"` |
|
|
|
IssueAssign bool `json:"issue_assign"` |
|
|
|
IssueAssign bool `json:"issue_assign"` |
|
|
|
IssueLabel bool `json:"issue_label"` |
|
|
|
IssueLabel bool `json:"issue_label"` |
|
|
|
IssueMilestone bool `json:"issue_milestone"` |
|
|
|
IssueMilestone bool `json:"issue_milestone"` |
|
|
|
IssueComment bool `json:"issue_comment"` |
|
|
|
IssueComment bool `json:"issue_comment"` |
|
|
|
|
|
|
|
Push bool `json:"push"` |
|
|
|
PullRequest bool `json:"pull_request"` |
|
|
|
PullRequest bool `json:"pull_request"` |
|
|
|
PullRequestAssign bool `json:"pull_request_assign"` |
|
|
|
PullRequestAssign bool `json:"pull_request_assign"` |
|
|
|
PullRequestLabel bool `json:"pull_request_label"` |
|
|
|
PullRequestLabel bool `json:"pull_request_label"` |
|
|
@ -25,14 +31,17 @@ func expandWebhooks(x *xorm.Engine) error { |
|
|
|
PullRequestComment bool `json:"pull_request_comment"` |
|
|
|
PullRequestComment bool `json:"pull_request_comment"` |
|
|
|
PullRequestReview bool `json:"pull_request_review"` |
|
|
|
PullRequestReview bool `json:"pull_request_review"` |
|
|
|
PullRequestSync bool `json:"pull_request_sync"` |
|
|
|
PullRequestSync bool `json:"pull_request_sync"` |
|
|
|
|
|
|
|
Repository bool `json:"repository"` |
|
|
|
|
|
|
|
Release bool `json:"release"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type Events struct { |
|
|
|
type HookEvent struct { |
|
|
|
PushOnly bool `json:"push_only"` |
|
|
|
PushOnly bool `json:"push_only"` |
|
|
|
SendEverything bool `json:"send_everything"` |
|
|
|
SendEverything bool `json:"send_everything"` |
|
|
|
ChooseEvents bool `json:"choose_events"` |
|
|
|
ChooseEvents bool `json:"choose_events"` |
|
|
|
BranchFilter string `json:"branch_filter"` |
|
|
|
BranchFilter string `json:"branch_filter"` |
|
|
|
Events ChooseEvents `json:"events"` |
|
|
|
|
|
|
|
|
|
|
|
HookEvents `json:"events"` |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type Webhook struct { |
|
|
|
type Webhook struct { |
|
|
@ -40,10 +49,9 @@ func expandWebhooks(x *xorm.Engine) error { |
|
|
|
Events string |
|
|
|
Events string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var events Events |
|
|
|
|
|
|
|
var bytes []byte |
|
|
|
var bytes []byte |
|
|
|
var last int |
|
|
|
var last int |
|
|
|
const batchSize = 50 |
|
|
|
batchSize := setting.Database.IterateBufferSize |
|
|
|
sess := x.NewSession() |
|
|
|
sess := x.NewSession() |
|
|
|
defer sess.Close() |
|
|
|
defer sess.Close() |
|
|
|
for { |
|
|
|
for { |
|
|
@ -63,24 +71,29 @@ func expandWebhooks(x *xorm.Engine) error { |
|
|
|
last += len(results) |
|
|
|
last += len(results) |
|
|
|
|
|
|
|
|
|
|
|
for _, res := range results { |
|
|
|
for _, res := range results { |
|
|
|
|
|
|
|
var events HookEvent |
|
|
|
if err = json.Unmarshal([]byte(res.Events), &events); err != nil { |
|
|
|
if err = json.Unmarshal([]byte(res.Events), &events); err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if events.Events.Issues { |
|
|
|
if !events.ChooseEvents { |
|
|
|
events.Events.IssueAssign = true |
|
|
|
continue |
|
|
|
events.Events.IssueLabel = true |
|
|
|
} |
|
|
|
events.Events.IssueMilestone = true |
|
|
|
|
|
|
|
events.Events.IssueComment = true |
|
|
|
if events.Issues { |
|
|
|
|
|
|
|
events.IssueAssign = true |
|
|
|
|
|
|
|
events.IssueLabel = true |
|
|
|
|
|
|
|
events.IssueMilestone = true |
|
|
|
|
|
|
|
events.IssueComment = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if events.Events.PullRequest { |
|
|
|
if events.PullRequest { |
|
|
|
events.Events.PullRequestAssign = true |
|
|
|
events.PullRequestAssign = true |
|
|
|
events.Events.PullRequestLabel = true |
|
|
|
events.PullRequestLabel = true |
|
|
|
events.Events.PullRequestMilestone = true |
|
|
|
events.PullRequestMilestone = true |
|
|
|
events.Events.PullRequestComment = true |
|
|
|
events.PullRequestComment = true |
|
|
|
events.Events.PullRequestReview = true |
|
|
|
events.PullRequestReview = true |
|
|
|
events.Events.PullRequestSync = true |
|
|
|
events.PullRequestSync = true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if bytes, err = json.Marshal(&events); err != nil { |
|
|
|
if bytes, err = json.Marshal(&events); err != nil { |
|
|
|