Skip to content

Commit d8bf5b0

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Store webhook event in database (go-gitea#29145) Fix bug hidden on CI and make ci failed if tests failure (go-gitea#29254)
2 parents d057e11 + 26653b1 commit d8bf5b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1887
-1591
lines changed

.github/workflows/pull-db-tests.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ jobs:
4949
- run: make backend
5050
env:
5151
TAGS: bindata
52-
- run: make test-pgsql-migration test-pgsql
52+
- name: run migration tests
53+
run: make test-pgsql-migration
54+
- name: run tests
55+
run: make test-pgsql
5356
timeout-minutes: 50
5457
env:
5558
TAGS: bindata gogit
@@ -72,7 +75,10 @@ jobs:
7275
- run: make backend
7376
env:
7477
TAGS: bindata gogit sqlite sqlite_unlock_notify
75-
- run: make test-sqlite-migration test-sqlite
78+
- name: run migration tests
79+
run: make test-sqlite-migration
80+
- name: run tests
81+
run: make test-sqlite
7682
timeout-minutes: 50
7783
env:
7884
TAGS: bindata gogit sqlite sqlite_unlock_notify
@@ -175,8 +181,10 @@ jobs:
175181
- run: make backend
176182
env:
177183
TAGS: bindata
184+
- name: run migration tests
185+
run: make test-mysql-migration
178186
- name: run tests
179-
run: make test-mysql-migration integration-test-coverage
187+
run: make integration-test-coverage
180188
env:
181189
TAGS: bindata
182190
RACE_ENABLED: true
@@ -208,7 +216,9 @@ jobs:
208216
- run: make backend
209217
env:
210218
TAGS: bindata
211-
- run: make test-mssql-migration test-mssql
219+
- run: make test-mssql-migration
220+
- name: run tests
221+
run: make test-mssql
212222
timeout-minutes: 50
213223
env:
214224
TAGS: bindata

Makefile

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64
115115

116116
GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
117117
GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
118+
MIGRATE_TEST_PACKAGES ?= $(shell $(GO) list code.gitea.io/gitea/models/migrations/...)
118119

119120
FOMANTIC_WORK_DIR := web_src/fomantic
120121

@@ -710,40 +711,31 @@ migrations.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
710711

711712
.PHONY: migrations.individual.mysql.test
712713
migrations.individual.mysql.test: $(GO_SOURCES)
713-
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
714-
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
715-
done
714+
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
716715

717716
.PHONY: migrations.individual.sqlite.test\#%
718717
migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
719718
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
720719

721720
.PHONY: migrations.individual.pgsql.test
722721
migrations.individual.pgsql.test: $(GO_SOURCES)
723-
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
724-
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
725-
done
722+
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
726723

727724
.PHONY: migrations.individual.pgsql.test\#%
728725
migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql
729726
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
730727

731-
732728
.PHONY: migrations.individual.mssql.test
733729
migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql
734-
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
735-
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg -test.failfast; \
736-
done
730+
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
737731

738732
.PHONY: migrations.individual.mssql.test\#%
739733
migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql
740734
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
741735

742736
.PHONY: migrations.individual.sqlite.test
743737
migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
744-
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
745-
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
746-
done
738+
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
747739

748740
.PHONY: migrations.individual.sqlite.test\#%
749741
migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite

models/fixtures/hook_task.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,35 @@
33
hook_id: 1
44
uuid: uuid1
55
is_delivered: true
6+
is_succeed: false
7+
request_content: >
8+
{
9+
"url": "/matrix-delivered",
10+
"http_method":"PUT",
11+
"headers": {
12+
"X-Head": "42"
13+
},
14+
"body": "{}"
15+
}
16+
17+
-
18+
id: 2
19+
hook_id: 1
20+
uuid: uuid2
21+
is_delivered: false
22+
23+
-
24+
id: 3
25+
hook_id: 1
26+
uuid: uuid3
27+
is_delivered: true
28+
is_succeed: true
29+
payload_content: '{"key":"value"}' # legacy task, payload saved in payload_content (and not in request_content)
30+
request_content: >
31+
{
32+
"url": "/matrix-success",
33+
"http_method":"PUT",
34+
"headers": {
35+
"X-Head": "42"
36+
}
37+
}

models/migrations/base/db_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ func Test_DropTableColumns(t *testing.T) {
3636
"updated_unix",
3737
}
3838

39+
x.SetMapper(names.GonicMapper{})
40+
3941
for i := range columns {
40-
x.SetMapper(names.GonicMapper{})
4142
if err := x.Sync(new(DropTest)); err != nil {
4243
t.Errorf("unable to create DropTest table: %v", err)
4344
return
4445
}
46+
4547
sess := x.NewSession()
4648
if err := sess.Begin(); err != nil {
4749
sess.Close()
@@ -64,7 +66,6 @@ func Test_DropTableColumns(t *testing.T) {
6466
return
6567
}
6668
for j := range columns[i+1:] {
67-
x.SetMapper(names.GonicMapper{})
6869
if err := x.Sync(new(DropTest)); err != nil {
6970
t.Errorf("unable to create DropTest table: %v", err)
7071
return
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-
2+
id: 1
3+
repo_id: 1
4+
index: 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-
2+
id: 1
3+
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
4+
issue_id: 1
5+
release_id: 0
6+
7+
-
8+
id: 2
9+
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12
10+
issue_id: 0
11+
release_id: 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-
2+
id: 1
3+
repo_id: 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-
2+
id: 1
3+
repo_id: 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-
2+
id: 1
3+
commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-
2+
id: 1
3+
context_hash: 19fe5caf872476db265596eaac1dc35ad1c6422d
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-
2+
id: 1
3+
commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d
4+
merge_base: 19fe5caf872476db265596eaac1dc35ad1c6422d
5+
merged_commit_id: 19fe5caf872476db265596eaac1dc35ad1c6422d
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-
2+
id: 1
3+
sha1: 19fe5caf872476db265596eaac1dc35ad1c6422d
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-
2+
id: 1
3+
commit_id: 19fe5caf872476db265596eaac1dc35ad1c6422d
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-
2+
id: 1
3+
commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-
2+
id: 1
3+
commit_sha: 19fe5caf872476db265596eaac1dc35ad1c6422d
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-
2+
id: 1
3+
description: the badge
4+
image_url: https://gitea.com/myimage.png

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ var migrations = []Migration{
564564
NewMigration("Add user_blocking table", v1_22.AddUserBlockingTable),
565565
// v289 -> v290
566566
NewMigration("Add default_wiki_branch to repository table", v1_22.AddDefaultWikiBranch),
567+
// v290 -> v291
568+
NewMigration("Add PayloadVersion to HookTask", v1_22.AddPayloadVersionToHookTaskTable),
567569
}
568570

569571
// GetCurrentDBVersion returns the current db version

models/migrations/v1_16/v193_test.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
1515
type Attachment struct {
1616
ID int64 `xorm:"pk autoincr"`
1717
UUID string `xorm:"uuid UNIQUE"`
18-
RepoID int64 `xorm:"INDEX"` // this should not be zero
1918
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
2019
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
2120
UploaderID int64 `xorm:"INDEX DEFAULT 0"`
@@ -44,25 +43,34 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
4443
return
4544
}
4645

47-
var issueAttachments []*Attachment
48-
err := x.Where("issue_id > 0").Find(&issueAttachments)
46+
type NewAttachment struct {
47+
ID int64 `xorm:"pk autoincr"`
48+
UUID string `xorm:"uuid UNIQUE"`
49+
RepoID int64 `xorm:"INDEX"` // this should not be zero
50+
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
51+
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
52+
UploaderID int64 `xorm:"INDEX DEFAULT 0"`
53+
}
54+
55+
var issueAttachments []*NewAttachment
56+
err := x.Table("attachment").Where("issue_id > 0").Find(&issueAttachments)
4957
assert.NoError(t, err)
5058
for _, attach := range issueAttachments {
51-
assert.Greater(t, attach.RepoID, 0)
52-
assert.Greater(t, attach.IssueID, 0)
59+
assert.Greater(t, attach.RepoID, int64(0))
60+
assert.Greater(t, attach.IssueID, int64(0))
5361
var issue Issue
5462
has, err := x.ID(attach.IssueID).Get(&issue)
5563
assert.NoError(t, err)
5664
assert.True(t, has)
5765
assert.EqualValues(t, attach.RepoID, issue.RepoID)
5866
}
5967

60-
var releaseAttachments []*Attachment
61-
err = x.Where("release_id > 0").Find(&releaseAttachments)
68+
var releaseAttachments []*NewAttachment
69+
err = x.Table("attachment").Where("release_id > 0").Find(&releaseAttachments)
6270
assert.NoError(t, err)
6371
for _, attach := range releaseAttachments {
64-
assert.Greater(t, attach.RepoID, 0)
65-
assert.Greater(t, attach.IssueID, 0)
72+
assert.Greater(t, attach.RepoID, int64(0))
73+
assert.Greater(t, attach.ReleaseID, int64(0))
6674
var release Release
6775
has, err := x.ID(attach.ReleaseID).Get(&release)
6876
assert.NoError(t, err)

models/migrations/v1_22/v283.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
package v1_22 //nolint
55

66
import (
7+
"fmt"
8+
79
"xorm.io/xorm"
10+
"xorm.io/xorm/schemas"
811
)
912

1013
func AddCombinedIndexToIssueUser(x *xorm.Engine) error {
@@ -20,8 +23,18 @@ func AddCombinedIndexToIssueUser(x *xorm.Engine) error {
2023
return err
2124
}
2225
for _, issueUser := range duplicatedIssueUsers {
23-
if _, err := x.Exec("delete from issue_user where id in (SELECT id FROM issue_user WHERE issue_id = ? and uid = ? limit ?)", issueUser.IssueID, issueUser.UID, issueUser.Cnt-1); err != nil {
24-
return err
26+
if x.Dialect().URI().DBType == schemas.MSSQL {
27+
if _, err := x.Exec(fmt.Sprintf("delete from issue_user where id in (SELECT top %d id FROM issue_user WHERE issue_id = ? and uid = ?)", issueUser.Cnt-1), issueUser.IssueID, issueUser.UID); err != nil {
28+
return err
29+
}
30+
} else {
31+
var ids []int64
32+
if err := x.SQL("SELECT id FROM issue_user WHERE issue_id = ? and uid = ? limit ?", issueUser.IssueID, issueUser.UID, issueUser.Cnt-1).Find(&ids); err != nil {
33+
return err
34+
}
35+
if _, err := x.Table("issue_user").In("id", ids).Delete(); err != nil {
36+
return err
37+
}
2538
}
2639
}
2740

models/migrations/v1_22/v286.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ func expandHashReferencesToSha256(x *xorm.Engine) error {
3636
if setting.Database.Type.IsMSSQL() {
3737
// drop indexes that need to be re-created afterwards
3838
droppedIndexes := []string{
39-
"DROP INDEX commit_status.IDX_commit_status_context_hash",
40-
"DROP INDEX review_state.UQE_review_state_pull_commit_user",
41-
"DROP INDEX repo_archiver.UQE_repo_archiver_s",
39+
"DROP INDEX IF EXISTS [IDX_commit_status_context_hash] ON [commit_status]",
40+
"DROP INDEX IF EXISTS [UQE_review_state_pull_commit_user] ON [review_state]",
41+
"DROP INDEX IF EXISTS [UQE_repo_archiver_s] ON [repo_archiver]",
4242
}
4343
for _, s := range droppedIndexes {
4444
_, err := db.Exec(s)
@@ -53,7 +53,7 @@ func expandHashReferencesToSha256(x *xorm.Engine) error {
5353
if setting.Database.Type.IsMySQL() {
5454
_, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` MODIFY COLUMN `%s` VARCHAR(64)", alts[0], alts[1]))
5555
} else if setting.Database.Type.IsMSSQL() {
56-
_, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` ALTER COLUMN `%s` VARCHAR(64)", alts[0], alts[1]))
56+
_, err = db.Exec(fmt.Sprintf("ALTER TABLE [%s] ALTER COLUMN [%s] VARCHAR(64)", alts[0], alts[1]))
5757
} else {
5858
_, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` ALTER COLUMN `%s` TYPE VARCHAR(64)", alts[0], alts[1]))
5959
}

0 commit comments

Comments
 (0)