Skip to content

Commit ae6b8ee

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Refactor some tests (go-gitea#34580) Do not mutate incoming options to SearchRepositoryByName (go-gitea#34553) Fix/improve avatar sync from LDAP (go-gitea#34573) Fix some trivial problems (go-gitea#34579) Retain issue sort type when a keyword search is introduced (go-gitea#34559) Always use an empty line to separate the commit message and trailer (go-gitea#34512) Fix line-button issue after file selection in file tree (go-gitea#34574) [skip ci] Updated translations via Crowdin Fix doctor deleting orphaned issues attachments (go-gitea#34142) [skip ci] Updated translations via Crowdin Fix actions skipped commit status indicator (go-gitea#34507) Clean up "file-view" related styles (go-gitea#34558) Add "View workflow file" to Actions list page (go-gitea#34538) Do not mutate incoming options to RenderUserSearch and SearchUsers (go-gitea#34544) Add webhook assigning test and fix possible bug (go-gitea#34420) Fix possible nil description of pull request when migrating from CodeCommit (go-gitea#34541) Refactor commit reader (go-gitea#34542)
2 parents 1794de8 + 2a1585b commit ae6b8ee

File tree

111 files changed

+968
-1077
lines changed

Some content is hidden

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

111 files changed

+968
-1077
lines changed

cmd/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func runRepoSyncReleases(_ *cli.Context) error {
107107

108108
log.Trace("Synchronizing repository releases (this may take a while)")
109109
for page := 1; ; page++ {
110-
repos, count, err := repo_model.SearchRepositoryByName(ctx, &repo_model.SearchRepoOptions{
110+
repos, count, err := repo_model.SearchRepositoryByName(ctx, repo_model.SearchRepoOptions{
111111
ListOptions: db.ListOptions{
112112
PageSize: repo_model.RepositoryListDefaultPageSize,
113113
Page: page,

cmd/admin_auth_ldap_test.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"code.gitea.io/gitea/models/auth"
11+
"code.gitea.io/gitea/modules/test"
1112
"code.gitea.io/gitea/services/auth/source/ldap"
1213

1314
"github.com/stretchr/testify/assert"
@@ -16,9 +17,7 @@ import (
1617

1718
func TestAddLdapBindDn(t *testing.T) {
1819
// Mock cli functions to do not exit on error
19-
osExiter := cli.OsExiter
20-
defer func() { cli.OsExiter = osExiter }()
21-
cli.OsExiter = func(code int) {}
20+
defer test.MockVariableValue(&cli.OsExiter, func(code int) {})()
2221

2322
// Test cases
2423
cases := []struct {
@@ -256,9 +255,7 @@ func TestAddLdapBindDn(t *testing.T) {
256255

257256
func TestAddLdapSimpleAuth(t *testing.T) {
258257
// Mock cli functions to do not exit on error
259-
osExiter := cli.OsExiter
260-
defer func() { cli.OsExiter = osExiter }()
261-
cli.OsExiter = func(code int) {}
258+
defer test.MockVariableValue(&cli.OsExiter, func(code int) {})()
262259

263260
// Test cases
264261
cases := []struct {
@@ -487,9 +484,7 @@ func TestAddLdapSimpleAuth(t *testing.T) {
487484

488485
func TestUpdateLdapBindDn(t *testing.T) {
489486
// Mock cli functions to do not exit on error
490-
osExiter := cli.OsExiter
491-
defer func() { cli.OsExiter = osExiter }()
492-
cli.OsExiter = func(code int) {}
487+
defer test.MockVariableValue(&cli.OsExiter, func(code int) {})()
493488

494489
// Test cases
495490
cases := []struct {
@@ -964,9 +959,7 @@ func TestUpdateLdapBindDn(t *testing.T) {
964959

965960
func TestUpdateLdapSimpleAuth(t *testing.T) {
966961
// Mock cli functions to do not exit on error
967-
osExiter := cli.OsExiter
968-
defer func() { cli.OsExiter = osExiter }()
969-
cli.OsExiter = func(code int) {}
962+
defer test.MockVariableValue(&cli.OsExiter, func(code int) {})()
970963

971964
// Test cases
972965
cases := []struct {

cmd/web_graceful.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ func NoHTTPRedirector() {
2323
graceful.GetManager().InformCleanup()
2424
}
2525

26-
// NoMainListener tells our cleanup routine that we will not be using a possibly provided listener
27-
// for our main HTTP/HTTPS service
28-
func NoMainListener() {
29-
graceful.GetManager().InformCleanup()
30-
}
31-
3226
// NoInstallListener tells our cleanup routine that we will not be using a possibly provided listener
3327
// for our install HTTP/HTTPS service
3428
func NoInstallListener() {

models/activities/user_heatmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func getUserHeatmapData(ctx context.Context, user *user_model.User, team *organi
6666
Select(groupBy+" AS timestamp, count(user_id) as contributions").
6767
Table("action").
6868
Where(cond).
69-
And("created_unix > ?", timeutil.TimeStampNow()-31536000).
69+
And("created_unix > ?", timeutil.TimeStampNow()-(366+7)*86400). // (366+7) days to include the first week for the heatmap
7070
GroupBy(groupByName).
7171
OrderBy("timestamp").
7272
Find(&hdata)

models/fixtures/hook_task.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
id: 2
1919
hook_id: 1
2020
uuid: uuid2
21-
is_delivered: false
21+
is_delivered: true
2222

2323
-
2424
id: 3

models/git/branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o
487487
ForkFrom: opts.BaseRepo.ID,
488488
Archived: optional.Some(false),
489489
}
490-
repoCond := repo_model.SearchRepositoryCondition(&repoOpts).And(repo_model.AccessibleRepositoryCondition(doer, unit.TypeCode))
490+
repoCond := repo_model.SearchRepositoryCondition(repoOpts).And(repo_model.AccessibleRepositoryCondition(doer, unit.TypeCode))
491491
if opts.Repo.ID == opts.BaseRepo.ID {
492492
// should also include the base repo's branches
493493
repoCond = repoCond.Or(builder.Eq{"id": opts.BaseRepo.ID})

models/git/commit_status.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,24 @@ func (status *CommitStatus) HideActionsURL(ctx context.Context) {
230230

231231
// CalcCommitStatus returns commit status state via some status, the commit statues should order by id desc
232232
func CalcCommitStatus(statuses []*CommitStatus) *CommitStatus {
233+
// This function is widely used, but it is not quite right.
234+
// Ideally it should return something like "CommitStatusSummary" with properly aggregated state.
235+
// GitHub's behavior: if all statuses are "skipped", GitHub will return "success" as the combined status.
233236
var lastStatus *CommitStatus
234237
state := api.CommitStatusSuccess
235238
for _, status := range statuses {
236-
if status.State.NoBetterThan(state) {
239+
if state == status.State || status.State.HasHigherPriorityThan(state) {
237240
state = status.State
238241
lastStatus = status
239242
}
240243
}
241244
if lastStatus == nil {
242245
if len(statuses) > 0 {
246+
// FIXME: a bad case: Gitea just returns the first commit status, its status is "skipped" in this case.
243247
lastStatus = statuses[0]
244248
} else {
249+
// FIXME: another bad case: if the "statuses" slice is empty, the returned value is an invalid CommitStatus, all its fields are empty.
250+
// Frontend code (tmpl&vue) sometimes depend on the empty fields to skip rendering commit status elements (need to double check in the future)
245251
lastStatus = &CommitStatus{}
246252
}
247253
}

models/git/commit_status_summary.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) er
5959
if err != nil {
6060
return err
6161
}
62-
state := CalcCommitStatus(commitStatuses)
62+
// it guarantees that commitStatuses is not empty because this function is always called after a commit status is created
63+
if len(commitStatuses) == 0 {
64+
setting.PanicInDevOrTesting("no commit statuses found for repo %d and sha %s", repoID, sha)
65+
}
66+
state := CalcCommitStatus(commitStatuses) // non-empty commitStatuses is guaranteed
6367
// mysql will return 0 when update a record which state hasn't been changed which behaviour is different from other database,
6468
// so we need to use insert in on duplicate
6569
if setting.Database.Type.IsMySQL() {

models/issues/issue_update.go

Lines changed: 8 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import (
1212
"code.gitea.io/gitea/models/db"
1313
"code.gitea.io/gitea/models/organization"
1414
access_model "code.gitea.io/gitea/models/perm/access"
15-
project_model "code.gitea.io/gitea/models/project"
1615
repo_model "code.gitea.io/gitea/models/repo"
17-
system_model "code.gitea.io/gitea/models/system"
1816
"code.gitea.io/gitea/models/unit"
1917
user_model "code.gitea.io/gitea/models/user"
2018
"code.gitea.io/gitea/modules/git"
@@ -715,138 +713,13 @@ func UpdateReactionsMigrationsByType(ctx context.Context, gitServiceType api.Git
715713
return err
716714
}
717715

718-
// DeleteIssuesByRepoID deletes issues by repositories id
719-
func DeleteIssuesByRepoID(ctx context.Context, repoID int64) (attachmentPaths []string, err error) {
720-
// MariaDB has a performance bug: https://jira.mariadb.org/browse/MDEV-16289
721-
// so here it uses "DELETE ... WHERE IN" with pre-queried IDs.
722-
sess := db.GetEngine(ctx)
723-
724-
for {
725-
issueIDs := make([]int64, 0, db.DefaultMaxInSize)
726-
727-
err := sess.Table(&Issue{}).Where("repo_id = ?", repoID).OrderBy("id").Limit(db.DefaultMaxInSize).Cols("id").Find(&issueIDs)
728-
if err != nil {
729-
return nil, err
730-
}
731-
732-
if len(issueIDs) == 0 {
733-
break
734-
}
735-
736-
// Delete content histories
737-
_, err = sess.In("issue_id", issueIDs).Delete(&ContentHistory{})
738-
if err != nil {
739-
return nil, err
740-
}
741-
742-
// Delete comments and attachments
743-
_, err = sess.In("issue_id", issueIDs).Delete(&Comment{})
744-
if err != nil {
745-
return nil, err
746-
}
747-
748-
// Dependencies for issues in this repository
749-
_, err = sess.In("issue_id", issueIDs).Delete(&IssueDependency{})
750-
if err != nil {
751-
return nil, err
752-
}
753-
754-
// Delete dependencies for issues in other repositories
755-
_, err = sess.In("dependency_id", issueIDs).Delete(&IssueDependency{})
756-
if err != nil {
757-
return nil, err
758-
}
759-
760-
_, err = sess.In("issue_id", issueIDs).Delete(&IssueUser{})
761-
if err != nil {
762-
return nil, err
763-
}
764-
765-
_, err = sess.In("issue_id", issueIDs).Delete(&Reaction{})
766-
if err != nil {
767-
return nil, err
768-
}
769-
770-
_, err = sess.In("issue_id", issueIDs).Delete(&IssueWatch{})
771-
if err != nil {
772-
return nil, err
773-
}
774-
775-
_, err = sess.In("issue_id", issueIDs).Delete(&Stopwatch{})
776-
if err != nil {
777-
return nil, err
778-
}
779-
780-
_, err = sess.In("issue_id", issueIDs).Delete(&TrackedTime{})
781-
if err != nil {
782-
return nil, err
783-
}
784-
785-
_, err = sess.In("issue_id", issueIDs).Delete(&project_model.ProjectIssue{})
786-
if err != nil {
787-
return nil, err
788-
}
789-
790-
_, err = sess.In("dependent_issue_id", issueIDs).Delete(&Comment{})
791-
if err != nil {
792-
return nil, err
793-
}
794-
795-
var attachments []*repo_model.Attachment
796-
err = sess.In("issue_id", issueIDs).Find(&attachments)
797-
if err != nil {
798-
return nil, err
799-
}
800-
801-
for j := range attachments {
802-
attachmentPaths = append(attachmentPaths, attachments[j].RelativePath())
803-
}
804-
805-
_, err = sess.In("issue_id", issueIDs).Delete(&repo_model.Attachment{})
806-
if err != nil {
807-
return nil, err
808-
}
809-
810-
_, err = sess.In("id", issueIDs).Delete(&Issue{})
811-
if err != nil {
812-
return nil, err
813-
}
814-
}
815-
816-
return attachmentPaths, err
817-
}
818-
819-
// DeleteOrphanedIssues delete issues without a repo
820-
func DeleteOrphanedIssues(ctx context.Context) error {
821-
var attachmentPaths []string
822-
err := db.WithTx(ctx, func(ctx context.Context) error {
823-
var ids []int64
824-
825-
if err := db.GetEngine(ctx).Table("issue").Distinct("issue.repo_id").
826-
Join("LEFT", "repository", "issue.repo_id=repository.id").
827-
Where(builder.IsNull{"repository.id"}).GroupBy("issue.repo_id").
828-
Find(&ids); err != nil {
829-
return err
830-
}
831-
832-
for i := range ids {
833-
paths, err := DeleteIssuesByRepoID(ctx, ids[i])
834-
if err != nil {
835-
return err
836-
}
837-
attachmentPaths = append(attachmentPaths, paths...)
838-
}
839-
840-
return nil
841-
})
842-
if err != nil {
843-
return err
844-
}
845-
846-
// Remove issue attachment files.
847-
for i := range attachmentPaths {
848-
// FIXME: it's not right, because the attachment might not be on local filesystem
849-
system_model.RemoveAllWithNotice(ctx, "Delete issue attachment", attachmentPaths[i])
716+
func GetOrphanedIssueRepoIDs(ctx context.Context) ([]int64, error) {
717+
var repoIDs []int64
718+
if err := db.GetEngine(ctx).Table("issue").Distinct("issue.repo_id").
719+
Join("LEFT", "repository", "issue.repo_id=repository.id").
720+
Where(builder.IsNull{"repository.id"}).
721+
Find(&repoIDs); err != nil {
722+
return nil, err
850723
}
851-
return nil
724+
return repoIDs, nil
852725
}

models/repo/pushmirror_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ func TestPushMirrorsIterate(t *testing.T) {
3939
Interval: 0,
4040
})
4141

42-
time.Sleep(1 * time.Millisecond)
43-
4442
repo_model.PushMirrorsIterate(db.DefaultContext, 1, func(idx int, bean any) error {
4543
m, ok := bean.(*repo_model.PushMirror)
4644
assert.True(t, ok)

0 commit comments

Comments
 (0)