summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Olheiser <john.olheiser@gmail.com>2020-03-06 09:43:37 -0600
committerGitHub <noreply@github.com>2020-03-06 17:43:37 +0200
commit4a4fc73ee10c80993d02afe7128a0f4824b7d122 (patch)
treea14a6c85e8affcd2da76cfb41975dd5c704a9d2d
parentf7a6763c5850fc5c53b34c2456ec9888bf8d523e (diff)
downloadgitea-4a4fc73ee10c80993d02afe7128a0f4824b7d122.tar.gz
gitea-4a4fc73ee10c80993d02afe7128a0f4824b7d122.zip
Fix migration (#10641)
Signed-off-by: jolheiser <john.olheiser@gmail.com>
-rw-r--r--models/migrations/v130.go55
1 files changed, 34 insertions, 21 deletions
diff --git a/models/migrations/v130.go b/models/migrations/v130.go
index 3a7efedf86..f7be11c400 100644
--- a/models/migrations/v130.go
+++ b/models/migrations/v130.go
@@ -7,17 +7,23 @@ package migrations
import (
"encoding/json"
+ "code.gitea.io/gitea/modules/setting"
+
"xorm.io/xorm"
)
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"`
IssueAssign bool `json:"issue_assign"`
IssueLabel bool `json:"issue_label"`
IssueMilestone bool `json:"issue_milestone"`
IssueComment bool `json:"issue_comment"`
+ Push bool `json:"push"`
PullRequest bool `json:"pull_request"`
PullRequestAssign bool `json:"pull_request_assign"`
PullRequestLabel bool `json:"pull_request_label"`
@@ -25,14 +31,17 @@ func expandWebhooks(x *xorm.Engine) error {
PullRequestComment bool `json:"pull_request_comment"`
PullRequestReview bool `json:"pull_request_review"`
PullRequestSync bool `json:"pull_request_sync"`
+ Repository bool `json:"repository"`
+ Release bool `json:"release"`
}
- type Events struct {
- PushOnly bool `json:"push_only"`
- SendEverything bool `json:"send_everything"`
- ChooseEvents bool `json:"choose_events"`
- BranchFilter string `json:"branch_filter"`
- Events ChooseEvents `json:"events"`
+ type HookEvent struct {
+ PushOnly bool `json:"push_only"`
+ SendEverything bool `json:"send_everything"`
+ ChooseEvents bool `json:"choose_events"`
+ BranchFilter string `json:"branch_filter"`
+
+ HookEvents `json:"events"`
}
type Webhook struct {
@@ -40,10 +49,9 @@ func expandWebhooks(x *xorm.Engine) error {
Events string
}
- var events Events
var bytes []byte
var last int
- const batchSize = 50
+ batchSize := setting.Database.IterateBufferSize
sess := x.NewSession()
defer sess.Close()
for {
@@ -63,24 +71,29 @@ func expandWebhooks(x *xorm.Engine) error {
last += len(results)
for _, res := range results {
+ var events HookEvent
if err = json.Unmarshal([]byte(res.Events), &events); err != nil {
return err
}
- if events.Events.Issues {
- events.Events.IssueAssign = true
- events.Events.IssueLabel = true
- events.Events.IssueMilestone = true
- events.Events.IssueComment = true
+ if !events.ChooseEvents {
+ continue
+ }
+
+ if events.Issues {
+ events.IssueAssign = true
+ events.IssueLabel = true
+ events.IssueMilestone = true
+ events.IssueComment = true
}
- if events.Events.PullRequest {
- events.Events.PullRequestAssign = true
- events.Events.PullRequestLabel = true
- events.Events.PullRequestMilestone = true
- events.Events.PullRequestComment = 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 {