Fix migration (#10641)

Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
John Olheiser 2020-03-06 09:43:37 -06:00 committed by GitHub
parent f7a6763c58
commit 4a4fc73ee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.Events.PullRequest { if events.Issues {
events.Events.PullRequestAssign = true events.IssueAssign = true
events.Events.PullRequestLabel = true events.IssueLabel = true
events.Events.PullRequestMilestone = true events.IssueMilestone = true
events.Events.PullRequestComment = true events.IssueComment = true
events.Events.PullRequestReview = true }
events.Events.PullRequestSync = true
if events.PullRequest {
events.PullRequestAssign = true
events.PullRequestLabel = true
events.PullRequestMilestone = true
events.PullRequestComment = true
events.PullRequestReview = true
events.PullRequestSync = true
} }
if bytes, err = json.Marshal(&events); err != nil { if bytes, err = json.Marshal(&events); err != nil {