2020-12-09 17:20:13 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-12-09 17:20:13 +00:00
|
|
|
|
2022-11-02 08:54:36 +00:00
|
|
|
package v1_14 //nolint
|
2020-12-09 17:20:13 +00:00
|
|
|
|
|
|
|
import (
|
2022-11-02 08:54:36 +00:00
|
|
|
"code.gitea.io/gitea/models/migrations/base"
|
|
|
|
|
2020-12-09 17:20:13 +00:00
|
|
|
"xorm.io/xorm"
|
|
|
|
)
|
|
|
|
|
2022-11-02 08:54:36 +00:00
|
|
|
func ConvertWebhookTaskTypeToString(x *xorm.Engine) error {
|
2020-12-09 17:20:13 +00:00
|
|
|
const (
|
|
|
|
GOGS int = iota + 1
|
|
|
|
SLACK
|
|
|
|
GITEA
|
|
|
|
DISCORD
|
|
|
|
DINGTALK
|
|
|
|
TELEGRAM
|
|
|
|
MSTEAMS
|
|
|
|
FEISHU
|
|
|
|
MATRIX
|
2021-07-23 04:41:27 +00:00
|
|
|
WECHATWORK
|
2020-12-09 17:20:13 +00:00
|
|
|
)
|
|
|
|
|
2021-03-14 18:52:12 +00:00
|
|
|
hookTaskTypes := map[int]string{
|
2021-07-23 04:41:27 +00:00
|
|
|
GITEA: "gitea",
|
|
|
|
GOGS: "gogs",
|
|
|
|
SLACK: "slack",
|
|
|
|
DISCORD: "discord",
|
|
|
|
DINGTALK: "dingtalk",
|
|
|
|
TELEGRAM: "telegram",
|
|
|
|
MSTEAMS: "msteams",
|
|
|
|
FEISHU: "feishu",
|
|
|
|
MATRIX: "matrix",
|
|
|
|
WECHATWORK: "wechatwork",
|
2020-12-09 17:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Webhook struct {
|
|
|
|
Type string `xorm:"char(16) index"`
|
|
|
|
}
|
|
|
|
if err := x.Sync2(new(Webhook)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, s := range hookTaskTypes {
|
|
|
|
if _, err := x.Exec("UPDATE webhook set type = ? where hook_task_type=?", s, i); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sess := x.NewSession()
|
|
|
|
defer sess.Close()
|
|
|
|
if err := sess.Begin(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-02 08:54:36 +00:00
|
|
|
if err := base.DropTableColumns(sess, "webhook", "hook_task_type"); err != nil {
|
2020-12-09 17:20:13 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sess.Commit()
|
|
|
|
}
|