Skip to content

Commit 98866a3

Browse files
committed
Merge remote-tracking branch 'giteaoffical/main'
* giteaoffical/main: [skip ci] Updated translations via Crowdin Move some functions to service layer (go-gitea#26969) Lock yamllint and update indirect python deps (go-gitea#26979) Chroma color tweaks (go-gitea#26978) Add a new column schedule_id for action_run to track (go-gitea#26975) Improve flex list UI (go-gitea#26970) Clarify the git command Stdin hanging problem (go-gitea#26967) Add v1.20.4 changelog (go-gitea#26974) Check newly added node type before "attachDirAuto" (go-gitea#26972) Expanding documentation in queue.go (go-gitea#26889) move repository deletion to service layer (go-gitea#26948)
2 parents d90d58c + 049b9f3 commit 98866a3

File tree

103 files changed

+1622
-1438
lines changed

Some content is hidden

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

103 files changed

+1622
-1438
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,34 @@ This changelog goes through all the changes that have been made in each release
44
without substantial changes to our git log; to see the highlights of what has
55
been added to each release, please refer to the [blog](https://blog.gitea.com).
66

7+
## [1.20.4](https://github.com/go-gitea/gitea/releases/tag/v1.20.4) - 2023-09-08
8+
9+
* SECURITY
10+
* Check blocklist for emails when adding them to account (#26812) (#26831)
11+
* ENHANCEMENTS
12+
* Add `branch_filter` to hooks API endpoints (#26599) (#26632)
13+
* Fix incorrect "tabindex" attributes (#26733) (#26734)
14+
* Use line-height: normal by default (#26635) (#26708)
15+
* Fix unable to display individual-level project (#26198) (#26636)
16+
* BUGFIXES
17+
* Fix wrong review requested number (#26784) (#26880)
18+
* Avoid double-unescaping of form value (#26853) (#26863)
19+
* Redirect from `{repo}/issues/new` to `{repo}/issues/new/choose` when blank issues are disabled (#26813) (#26847)
20+
* Sync tags when adopting repos (#26816) (#26834)
21+
* Fix verifyCommits error when push a new branch (#26664) (#26810)
22+
* Include the GITHUB_TOKEN/GITEA_TOKEN secret for fork pull requests (#26759) (#26806)
23+
* Fix some slice append usages (#26778) (#26798)
24+
* Add fix incorrect can_create_org_repo for org owner team (#26683) (#26791)
25+
* Fix bug for ctx usage (#26763)
26+
* Make issue template field template access correct template data (#26698) (#26709)
27+
* Use correct minio error (#26634) (#26639)
28+
* Ignore the trailing slashes when comparing oauth2 redirect_uri (#26597) (#26618)
29+
* Set errwriter for urfave/cli v1 (#26616)
30+
* Fix reopen logic for agit flow pull request (#26399) (#26613)
31+
* Fix context filter has no effect in dashboard (#26695) (#26811)
32+
* Fix being unable to use a repo that prohibits accepting PRs as a PR source. (#26785) (#26790)
33+
* Fix Page Not Found error (#26768)
34+
735
## [1.20.3](https://github.com/go-gitea/gitea/releases/tag/v1.20.3) - 2023-08-20
836

937
* BREAKING

models/actions/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ type ActionRun struct {
3535
Index int64 `xorm:"index unique(repo_index)"` // a unique number for each run of a repository
3636
TriggerUserID int64 `xorm:"index"`
3737
TriggerUser *user_model.User `xorm:"-"`
38-
Ref string `xorm:"index"` // the commit/tag/… that caused the run
38+
ScheduleID int64
39+
Ref string `xorm:"index"` // the commit/tag/… that caused the run
3940
CommitSHA string
4041
IsForkPullRequest bool // If this is triggered by a PR from a forked repository or an untrusted user, we need to check if it is approved and limit permissions when running the workflow.
4142
NeedApproval bool // may need approval if it's a fork pull request

models/activities/main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"code.gitea.io/gitea/models/unittest"
1111

1212
_ "code.gitea.io/gitea/models"
13+
_ "code.gitea.io/gitea/models/actions"
1314
)
1415

1516
func TestMain(m *testing.M) {

models/auth/main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"code.gitea.io/gitea/models/unittest"
1111

1212
_ "code.gitea.io/gitea/models"
13+
_ "code.gitea.io/gitea/models/actions"
1314
_ "code.gitea.io/gitea/models/activities"
1415
_ "code.gitea.io/gitea/models/auth"
1516
_ "code.gitea.io/gitea/models/perm/access"

models/git/main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"code.gitea.io/gitea/models/unittest"
1111

1212
_ "code.gitea.io/gitea/models"
13+
_ "code.gitea.io/gitea/models/actions"
14+
_ "code.gitea.io/gitea/models/activities"
1315
)
1416

1517
func TestMain(m *testing.M) {

models/issues/comment.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
project_model "code.gitea.io/gitea/models/project"
1818
repo_model "code.gitea.io/gitea/models/repo"
1919
user_model "code.gitea.io/gitea/models/user"
20+
"code.gitea.io/gitea/modules/container"
2021
"code.gitea.io/gitea/modules/git"
2122
"code.gitea.io/gitea/modules/json"
2223
"code.gitea.io/gitea/modules/log"
@@ -1247,3 +1248,44 @@ func FixCommentTypeLabelWithOutsideLabels(ctx context.Context) (int64, error) {
12471248
func (c *Comment) HasOriginalAuthor() bool {
12481249
return c.OriginalAuthor != "" && c.OriginalAuthorID != 0
12491250
}
1251+
1252+
// InsertIssueComments inserts many comments of issues.
1253+
func InsertIssueComments(comments []*Comment) error {
1254+
if len(comments) == 0 {
1255+
return nil
1256+
}
1257+
1258+
issueIDs := make(container.Set[int64])
1259+
for _, comment := range comments {
1260+
issueIDs.Add(comment.IssueID)
1261+
}
1262+
1263+
ctx, committer, err := db.TxContext(db.DefaultContext)
1264+
if err != nil {
1265+
return err
1266+
}
1267+
defer committer.Close()
1268+
for _, comment := range comments {
1269+
if _, err := db.GetEngine(ctx).NoAutoTime().Insert(comment); err != nil {
1270+
return err
1271+
}
1272+
1273+
for _, reaction := range comment.Reactions {
1274+
reaction.IssueID = comment.IssueID
1275+
reaction.CommentID = comment.ID
1276+
}
1277+
if len(comment.Reactions) > 0 {
1278+
if err := db.Insert(ctx, comment.Reactions); err != nil {
1279+
return err
1280+
}
1281+
}
1282+
}
1283+
1284+
for issueID := range issueIDs {
1285+
if _, err := db.Exec(ctx, "UPDATE issue set num_comments = (SELECT count(*) FROM comment WHERE issue_id = ? AND `type`=?) WHERE id = ?",
1286+
issueID, CommentTypeComment, issueID); err != nil {
1287+
return err
1288+
}
1289+
}
1290+
return committer.Commit()
1291+
}

models/issues/comment_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,30 @@ func TestAsCommentType(t *testing.T) {
7070
assert.Equal(t, issues_model.CommentTypeComment, issues_model.AsCommentType("comment"))
7171
assert.Equal(t, issues_model.CommentTypePRUnScheduledToAutoMerge, issues_model.AsCommentType("pull_cancel_scheduled_merge"))
7272
}
73+
74+
func TestMigrate_InsertIssueComments(t *testing.T) {
75+
assert.NoError(t, unittest.PrepareTestDatabase())
76+
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
77+
_ = issue.LoadRepo(db.DefaultContext)
78+
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: issue.Repo.OwnerID})
79+
reaction := &issues_model.Reaction{
80+
Type: "heart",
81+
UserID: owner.ID,
82+
}
83+
84+
comment := &issues_model.Comment{
85+
PosterID: owner.ID,
86+
Poster: owner,
87+
IssueID: issue.ID,
88+
Issue: issue,
89+
Reactions: []*issues_model.Reaction{reaction},
90+
}
91+
92+
err := issues_model.InsertIssueComments([]*issues_model.Comment{comment})
93+
assert.NoError(t, err)
94+
95+
issueModified := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
96+
assert.EqualValues(t, issue.NumComments+1, issueModified.NumComments)
97+
98+
unittest.CheckConsistencyFor(t, &issues_model.Issue{})
99+
}

models/issues/issue.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,3 +892,50 @@ func IsNewPinAllowed(ctx context.Context, repoID int64, isPull bool) (bool, erro
892892
func IsErrIssueMaxPinReached(err error) bool {
893893
return err == ErrIssueMaxPinReached
894894
}
895+
896+
// InsertIssues insert issues to database
897+
func InsertIssues(issues ...*Issue) error {
898+
ctx, committer, err := db.TxContext(db.DefaultContext)
899+
if err != nil {
900+
return err
901+
}
902+
defer committer.Close()
903+
904+
for _, issue := range issues {
905+
if err := insertIssue(ctx, issue); err != nil {
906+
return err
907+
}
908+
}
909+
return committer.Commit()
910+
}
911+
912+
func insertIssue(ctx context.Context, issue *Issue) error {
913+
sess := db.GetEngine(ctx)
914+
if _, err := sess.NoAutoTime().Insert(issue); err != nil {
915+
return err
916+
}
917+
issueLabels := make([]IssueLabel, 0, len(issue.Labels))
918+
for _, label := range issue.Labels {
919+
issueLabels = append(issueLabels, IssueLabel{
920+
IssueID: issue.ID,
921+
LabelID: label.ID,
922+
})
923+
}
924+
if len(issueLabels) > 0 {
925+
if _, err := sess.Insert(issueLabels); err != nil {
926+
return err
927+
}
928+
}
929+
930+
for _, reaction := range issue.Reactions {
931+
reaction.IssueID = issue.ID
932+
}
933+
934+
if len(issue.Reactions) > 0 {
935+
if _, err := sess.Insert(issue.Reactions); err != nil {
936+
return err
937+
}
938+
}
939+
940+
return nil
941+
}

models/issues/issue_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,45 @@ func TestIssueLoadAttributes(t *testing.T) {
573573
}
574574
}
575575
}
576+
577+
func assertCreateIssues(t *testing.T, isPull bool) {
578+
assert.NoError(t, unittest.PrepareTestDatabase())
579+
reponame := "repo1"
580+
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame})
581+
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
582+
label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1})
583+
milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1})
584+
assert.EqualValues(t, milestone.ID, 1)
585+
reaction := &issues_model.Reaction{
586+
Type: "heart",
587+
UserID: owner.ID,
588+
}
589+
590+
title := "issuetitle1"
591+
is := &issues_model.Issue{
592+
RepoID: repo.ID,
593+
MilestoneID: milestone.ID,
594+
Repo: repo,
595+
Title: title,
596+
Content: "issuecontent1",
597+
IsPull: isPull,
598+
PosterID: owner.ID,
599+
Poster: owner,
600+
IsClosed: true,
601+
Labels: []*issues_model.Label{label},
602+
Reactions: []*issues_model.Reaction{reaction},
603+
}
604+
err := issues_model.InsertIssues(is)
605+
assert.NoError(t, err)
606+
607+
i := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{Title: title})
608+
unittest.AssertExistsAndLoadBean(t, &issues_model.Reaction{Type: "heart", UserID: owner.ID, IssueID: i.ID})
609+
}
610+
611+
func TestMigrate_CreateIssuesIsPullFalse(t *testing.T) {
612+
assertCreateIssues(t, false)
613+
}
614+
615+
func TestMigrate_CreateIssuesIsPullTrue(t *testing.T) {
616+
assertCreateIssues(t, true)
617+
}

models/issues/main_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"code.gitea.io/gitea/models/unittest"
1212

1313
_ "code.gitea.io/gitea/models"
14+
_ "code.gitea.io/gitea/models/actions"
15+
_ "code.gitea.io/gitea/models/activities"
1416
_ "code.gitea.io/gitea/models/repo"
1517
_ "code.gitea.io/gitea/models/user"
1618

0 commit comments

Comments
 (0)