You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

v162.go 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package v1_14 //nolint
  4. import (
  5. "code.gitea.io/gitea/models/migrations/base"
  6. "xorm.io/xorm"
  7. )
  8. func ConvertWebhookTaskTypeToString(x *xorm.Engine) error {
  9. const (
  10. GOGS int = iota + 1
  11. SLACK
  12. GITEA
  13. DISCORD
  14. DINGTALK
  15. TELEGRAM
  16. MSTEAMS
  17. FEISHU
  18. MATRIX
  19. WECHATWORK
  20. )
  21. hookTaskTypes := map[int]string{
  22. GITEA: "gitea",
  23. GOGS: "gogs",
  24. SLACK: "slack",
  25. DISCORD: "discord",
  26. DINGTALK: "dingtalk",
  27. TELEGRAM: "telegram",
  28. MSTEAMS: "msteams",
  29. FEISHU: "feishu",
  30. MATRIX: "matrix",
  31. WECHATWORK: "wechatwork",
  32. }
  33. type Webhook struct {
  34. Type string `xorm:"char(16) index"`
  35. }
  36. if err := x.Sync(new(Webhook)); err != nil {
  37. return err
  38. }
  39. for i, s := range hookTaskTypes {
  40. if _, err := x.Exec("UPDATE webhook set type = ? where hook_task_type=?", s, i); err != nil {
  41. return err
  42. }
  43. }
  44. sess := x.NewSession()
  45. defer sess.Close()
  46. if err := sess.Begin(); err != nil {
  47. return err
  48. }
  49. if err := base.DropTableColumns(sess, "webhook", "hook_task_type"); err != nil {
  50. return err
  51. }
  52. return sess.Commit()
  53. }