Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0aa8cde

Browse files
authoredJan 6, 2021
Merge branch 'master' into lunny/add_close_back
2 parents 484a6b3 + 8688c2b commit 0aa8cde

File tree

6 files changed

+120
-14
lines changed

6 files changed

+120
-14
lines changed
 

‎models/migrations/migrations.go

+40
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package migrations
77

88
import (
9+
"context"
910
"fmt"
1011
"os"
1112
"reflect"
@@ -16,6 +17,7 @@ import (
1617
"code.gitea.io/gitea/modules/setting"
1718

1819
"xorm.io/xorm"
20+
"xorm.io/xorm/schemas"
1921
)
2022

2123
const minDBVersion = 70 // Gitea 1.5.3
@@ -273,6 +275,8 @@ var migrations = []Migration{
273275
NewMigration("Convert topic name from 25 to 50", convertTopicNameFrom25To50),
274276
// v164 -> v165
275277
NewMigration("Add scope and nonce columns to oauth2_grant table", addScopeAndNonceColumnsToOAuth2Grant),
278+
// v165 -> v166
279+
NewMigration("Convert hook task type from char(16) to varchar(16) and trim the column", convertHookTaskTypeToVarcharAndTrim),
276280
}
277281

278282
// GetCurrentDBVersion returns the current db version
@@ -737,3 +741,39 @@ func dropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
737741

738742
return nil
739743
}
744+
745+
// modifyColumn will modify column's type or other propertity. SQLITE is not supported
746+
func modifyColumn(x *xorm.Engine, tableName string, col *schemas.Column) error {
747+
var indexes map[string]*schemas.Index
748+
var err error
749+
// MSSQL have to remove index at first, otherwise alter column will fail
750+
// ref. https://sqlzealots.com/2018/05/09/error-message-the-index-is-dependent-on-column-alter-table-alter-column-failed-because-one-or-more-objects-access-this-column/
751+
if x.Dialect().URI().DBType == schemas.MSSQL {
752+
indexes, err = x.Dialect().GetIndexes(x.DB(), context.Background(), tableName)
753+
if err != nil {
754+
return err
755+
}
756+
757+
for _, index := range indexes {
758+
_, err = x.Exec(x.Dialect().DropIndexSQL(tableName, index))
759+
if err != nil {
760+
return err
761+
}
762+
}
763+
}
764+
765+
defer func() {
766+
for _, index := range indexes {
767+
_, err = x.Exec(x.Dialect().CreateIndexSQL(tableName, index))
768+
if err != nil {
769+
log.Error("Create index %s on table %s failed: %v", index.Name, tableName, err)
770+
}
771+
}
772+
}()
773+
774+
alterSQL := x.Dialect().ModifyColumnSQL(tableName, col)
775+
if _, err := x.Exec(alterSQL); err != nil {
776+
return err
777+
}
778+
return nil
779+
}

‎models/migrations/v161.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func convertTaskTypeToString(x *xorm.Engine) error {
3434
}
3535

3636
type HookTask struct {
37-
Typ string `xorm:"char(16) index"`
37+
Typ string `xorm:"VARCHAR(16) index"`
3838
}
3939
if err := x.Sync2(new(HookTask)); err != nil {
4040
return err

‎models/migrations/v165.go

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"xorm.io/xorm"
9+
"xorm.io/xorm/schemas"
10+
)
11+
12+
func convertHookTaskTypeToVarcharAndTrim(x *xorm.Engine) error {
13+
dbType := x.Dialect().URI().DBType
14+
if dbType == schemas.SQLITE { // For SQLITE, varchar or char will always be represented as TEXT
15+
return nil
16+
}
17+
18+
type HookTask struct {
19+
Typ string `xorm:"VARCHAR(16) index"`
20+
}
21+
22+
if err := modifyColumn(x, "hook_task", &schemas.Column{
23+
Name: "typ",
24+
SQLType: schemas.SQLType{
25+
Name: "VARCHAR",
26+
},
27+
Length: 16,
28+
Nullable: true, // To keep compatible as nullable
29+
}); err != nil {
30+
return err
31+
}
32+
33+
var hookTaskTrimSQL string
34+
if dbType == schemas.MSSQL {
35+
hookTaskTrimSQL = "UPDATE hook_task SET typ = RTRIM(LTRIM(typ))"
36+
} else {
37+
hookTaskTrimSQL = "UPDATE hook_task SET typ = TRIM(typ)"
38+
}
39+
if _, err := x.Exec(hookTaskTrimSQL); err != nil {
40+
return err
41+
}
42+
43+
type Webhook struct {
44+
Type string `xorm:"VARCHAR(16) index"`
45+
}
46+
47+
if err := modifyColumn(x, "webhook", &schemas.Column{
48+
Name: "type",
49+
SQLType: schemas.SQLType{
50+
Name: "VARCHAR",
51+
},
52+
Length: 16,
53+
Nullable: true, // To keep compatible as nullable
54+
}); err != nil {
55+
return err
56+
}
57+
58+
var webhookTrimSQL string
59+
if dbType == schemas.MSSQL {
60+
webhookTrimSQL = "UPDATE webhook SET type = RTRIM(LTRIM(type))"
61+
} else {
62+
webhookTrimSQL = "UPDATE webhook SET type = TRIM(type)"
63+
}
64+
_, err := x.Exec(webhookTrimSQL)
65+
return err
66+
}

‎models/webhook.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ type Webhook struct {
113113
*HookEvent `xorm:"-"`
114114
IsSSL bool `xorm:"is_ssl"`
115115
IsActive bool `xorm:"INDEX"`
116-
Type HookTaskType `xorm:"char(16) 'type'"`
116+
Type HookTaskType `xorm:"VARCHAR(16) 'type'"`
117117
Meta string `xorm:"TEXT"` // store hook-specific attributes
118118
LastStatus HookStatus // Last delivery status
119119

@@ -641,9 +641,9 @@ type HookTask struct {
641641
RepoID int64 `xorm:"INDEX"`
642642
HookID int64
643643
UUID string
644-
Typ HookTaskType
645-
URL string `xorm:"TEXT"`
646-
Signature string `xorm:"TEXT"`
644+
Typ HookTaskType `xorm:"VARCHAR(16) index"`
645+
URL string `xorm:"TEXT"`
646+
Signature string `xorm:"TEXT"`
647647
api.Payloader `xorm:"-"`
648648
PayloadContent string `xorm:"TEXT"`
649649
HTTPMethod string `xorm:"http_method"`

‎options/locale/locale_zh-TW.ini

+6-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ report_message=如果你確定這是一個 Gitea 的 bug,請去 <a href="https
9797

9898
[startpage]
9999
install=安裝容易
100-
install_desc=簡單地用<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/install-from-binary/">執行檔</a>來架設平台,或是使用 <a target="_blank" rel="noopener noreferrer" href="https://github.com/go-gitea/gitea/tree/master/docker">Docker</a>,你也可以從<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/install-from-package/">套件管理員</a>安裝。
100+
install_desc=簡單地執行您平台的<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/install-from-binary/">二進位檔</a>,或是使用 <a target="_blank" rel="noopener noreferrer" href="https://github.com/go-gitea/gitea/tree/master/docker">Docker</a>,你也可以從<a target="_blank" rel="noopener noreferrer" href="https://docs.gitea.io/en-us/install-from-package/">套件管理員</a>安裝。
101101
platform=跨平台
102102
platform_desc=Gitea 可以在所有能編譯 <a target="_blank" rel="noopener noreferrer" href="http://golang.org/">Go 語言</a>的平台上執行: Windows, macOS, Linux, ARM 等等。挑一個您喜歡的吧!
103103
lightweight=輕量級
@@ -108,7 +108,7 @@ license_desc=取得 <a target="_blank" rel="noopener noreferrer" href="https://c
108108
[install]
109109
install=安裝頁面
110110
title=初始組態
111-
docker_helper=如果您正在使用 Docker 容器執行 Gitea,請務必先仔細閱讀 <a target="_blank" rel="noopener noreferrer" href="%s">官方文件</a>後再對本頁面進行填寫
111+
docker_helper=如果您在 Docker 中執行 Gitea,請先閱讀<a target="_blank" rel="noopener noreferrer" href="%s">安裝指南</a>再來調整設定
112112
requite_db_desc=Gitea 必須搭配 MySQL、PostgreSQL、MSSQL 或 SQLite3 資料庫使用。
113113
db_title=資料庫設定
114114
db_type=資料庫類型
@@ -145,7 +145,7 @@ domain_helper=用於 SSH Clone 的域名或主機位置。
145145
ssh_port=SSH 伺服器埠
146146
ssh_port_helper=SSH 伺服器使用的埠號,留空以停用此設定。
147147
http_port=Gitea HTTP 埠
148-
http_port_helper=Giteas web 伺服器將偵聽的埠號
148+
http_port_helper=Gitea 的網頁伺服器要接聽的埠號
149149
app_url=Gitea 基本 URL
150150
app_url_helper=用於 HTTP(S) Clone 和電子郵件通知的基本網址。
151151
log_root_path=日誌路徑
@@ -155,7 +155,7 @@ optional_title=可選設定
155155
email_title=電子郵件設定
156156
smtp_host=SMTP 主機
157157
smtp_from=電子郵件寄件者
158-
smtp_from_helper=Gitea 將會使用的電子信箱,輸入一個普通的電子信箱或使用 "名稱" <email@example.com> 格式
158+
smtp_from_helper=Gitea 將會使用的電子信箱,直接輸入電子信箱或使用「"名稱" <email@example.com>」的格式
159159
mailer_user=SMTP 帳號
160160
mailer_password=SMTP 密碼
161161
register_confirm=要求註冊時確認電子郵件
@@ -253,10 +253,10 @@ forgot_password_title=忘記密碼
253253
forgot_password=忘記密碼?
254254
sign_up_now=還沒有帳戶?馬上註冊。
255255
sign_up_successful=帳戶已成功建立。
256-
confirmation_mail_sent_prompt=一封新的確認郵件已發送至 <b>%s</b>。請檢查您的收件箱並在 %s 小時內完成確認註冊操作
256+
confirmation_mail_sent_prompt=一封新的確認信已發送至 <b>%s</b>。請檢查您的收件匣,並在 %s 內完成註冊作業
257257
must_change_password=更新您的密碼
258258
allow_password_change=要求使用者更改密碼 (推薦)
259-
reset_password_mail_sent_prompt=一封確認信已經被發送至 <b>%s</b>。請檢查您的收件匣,並在 %s 小時內完成帳戶救援作業
259+
reset_password_mail_sent_prompt=一封確認信已發送至 <b>%s</b>。請檢查您的收件匣,並在 %s 內完成帳戶救援作業
260260
active_your_account=啟用您的帳戶
261261
account_activated=帳戶已啟用
262262
prohibit_login=禁止登入

‎services/webhook/webhook.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ var (
6060

6161
// RegisterWebhook registers a webhook
6262
func RegisterWebhook(name string, webhook *webhook) {
63-
webhooks[models.HookTaskType(strings.TrimSpace(name))] = webhook
63+
webhooks[models.HookTaskType(name)] = webhook
6464
}
6565

6666
// IsValidHookTaskType returns true if a webhook registered
6767
func IsValidHookTaskType(name string) bool {
6868
if name == models.GITEA || name == models.GOGS {
6969
return true
7070
}
71-
_, ok := webhooks[models.HookTaskType(strings.TrimSpace(name))]
71+
_, ok := webhooks[models.HookTaskType(name)]
7272
return ok
7373
}
7474

@@ -147,7 +147,7 @@ func prepareWebhook(w *models.Webhook, repo *models.Repository, event models.Hoo
147147

148148
var payloader api.Payloader
149149
var err error
150-
webhook, ok := webhooks[strings.TrimSpace(w.Type)] // NOTICE: w.Type maynot be trimmed before store into database
150+
webhook, ok := webhooks[w.Type]
151151
if ok {
152152
payloader, err = webhook.payloadCreator(p, event, w.Meta)
153153
if err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.