forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
* upstream/main: adapt README_{Country}.md stype name in localizedExtensions (go-gitea#21486) dump: Add option to skip index dirs (go-gitea#21501) Use recommended vscode configuration in gitpod environments (go-gitea#21537) Expand "Go to File" button again, fix 'Add File' margin (go-gitea#21543) Add yardenshoham to maintainers (go-gitea#21566) Refactor git command arguments and make all arguments to be safe to be used (go-gitea#21535) Update binding to fix bugs (go-gitea#21556) Link mentioned user in markdown only if they are visible to viewer (go-gitea#21554) Require authentication for OAuth token refresh (go-gitea#21421) CSS color enhancements (go-gitea#21534) Allow package version sorting (go-gitea#21453) Add link to user profile in markdown mention only if user exists (go-gitea#21533) Update milestone counters when issue is deleted (go-gitea#21459) Prevent Authorization header for presigned LFS urls (go-gitea#21531) Remove deleted repos from searchresult (go-gitea#21512) Remove unnecessary debug log (go-gitea#21536) Added check for disabled Packages (go-gitea#21540) Decouple HookTask from Repository (go-gitea#17940) Add color previews in markdown (go-gitea#21474) Fix generating compare link (go-gitea#21519)
- Loading branch information
Showing
128 changed files
with
1,306 additions
and
736 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
tasks: | ||
- name: Setup | ||
init: | | ||
cp -r contrib/ide/vscode .vscode | ||
make deps | ||
make build | ||
command: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
- | ||
id: 1 | ||
repo_id: 1 | ||
hook_id: 1 | ||
uuid: uuid1 | ||
is_delivered: true |
19 changes: 19 additions & 0 deletions
19
models/migrations/fixtures/Test_updateOpenMilestoneCounts/expected_milestone.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# type Milestone struct { | ||
# ID int64 `xorm:"pk autoincr"` | ||
# IsClosed bool | ||
# NumIssues int | ||
# NumClosedIssues int | ||
# Completeness int // Percentage(1-100). | ||
# } | ||
- | ||
id: 1 | ||
is_closed: false | ||
num_issues: 3 | ||
num_closed_issues: 1 | ||
completeness: 33 | ||
- | ||
id: 2 | ||
is_closed: true | ||
num_issues: 5 | ||
num_closed_issues: 5 | ||
completeness: 100 |
25 changes: 25 additions & 0 deletions
25
models/migrations/fixtures/Test_updateOpenMilestoneCounts/issue.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# type Issue struct { | ||
# ID int64 `xorm:"pk autoincr"` | ||
# RepoID int64 `xorm:"INDEX UNIQUE(repo_index)"` | ||
# Index int64 `xorm:"UNIQUE(repo_index)"` // Index in one repository. | ||
# MilestoneID int64 `xorm:"INDEX"` | ||
# IsClosed bool `xorm:"INDEX"` | ||
# } | ||
- | ||
id: 1 | ||
repo_id: 1 | ||
index: 1 | ||
milestone_id: 1 | ||
is_closed: false | ||
- | ||
id: 2 | ||
repo_id: 1 | ||
index: 2 | ||
milestone_id: 1 | ||
is_closed: true | ||
- | ||
id: 4 | ||
repo_id: 1 | ||
index: 3 | ||
milestone_id: 1 | ||
is_closed: false |
19 changes: 19 additions & 0 deletions
19
models/migrations/fixtures/Test_updateOpenMilestoneCounts/milestone.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# type Milestone struct { | ||
# ID int64 `xorm:"pk autoincr"` | ||
# IsClosed bool | ||
# NumIssues int | ||
# NumClosedIssues int | ||
# Completeness int // Percentage(1-100). | ||
# } | ||
- | ||
id: 1 | ||
is_closed: false | ||
num_issues: 4 | ||
num_closed_issues: 2 | ||
completeness: 50 | ||
- | ||
id: 2 | ||
is_closed: true | ||
num_issues: 5 | ||
num_closed_issues: 5 | ||
completeness: 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"fmt" | ||
|
||
"code.gitea.io/gitea/models/issues" | ||
|
||
"xorm.io/builder" | ||
"xorm.io/xorm" | ||
) | ||
|
||
func updateOpenMilestoneCounts(x *xorm.Engine) error { | ||
var openMilestoneIDs []int64 | ||
err := x.Table("milestone").Select("id").Where(builder.Neq{"is_closed": 1}).Find(&openMilestoneIDs) | ||
if err != nil { | ||
return fmt.Errorf("error selecting open milestone IDs: %w", err) | ||
} | ||
|
||
for _, id := range openMilestoneIDs { | ||
_, err := x.ID(id). | ||
SetExpr("num_issues", builder.Select("count(*)").From("issue").Where( | ||
builder.Eq{"milestone_id": id}, | ||
)). | ||
SetExpr("num_closed_issues", builder.Select("count(*)").From("issue").Where( | ||
builder.Eq{ | ||
"milestone_id": id, | ||
"is_closed": true, | ||
}, | ||
)). | ||
Update(&issues.Milestone{}) | ||
if err != nil { | ||
return fmt.Errorf("error updating issue counts in milestone %d: %w", id, err) | ||
} | ||
_, err = x.Exec("UPDATE `milestone` SET completeness=100*num_closed_issues/(CASE WHEN num_issues > 0 THEN num_issues ELSE 1 END) WHERE id=?", | ||
id, | ||
) | ||
if err != nil { | ||
return fmt.Errorf("error setting completeness on milestone %d: %w", id, err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/issues" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_updateOpenMilestoneCounts(t *testing.T) { | ||
type ExpectedMilestone issues.Milestone | ||
|
||
// Prepare and load the testing database | ||
x, deferable := prepareTestEnv(t, 0, new(issues.Milestone), new(ExpectedMilestone), new(issues.Issue)) | ||
defer deferable() | ||
if x == nil || t.Failed() { | ||
return | ||
} | ||
|
||
if err := updateOpenMilestoneCounts(x); err != nil { | ||
assert.NoError(t, err) | ||
return | ||
} | ||
|
||
expected := []ExpectedMilestone{} | ||
if err := x.Table("expected_milestone").Asc("id").Find(&expected); !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
got := []issues.Milestone{} | ||
if err := x.Table("milestone").Asc("id").Find(&got); !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
for i, e := range expected { | ||
got := got[i] | ||
assert.Equal(t, e.ID, got.ID) | ||
assert.Equal(t, e.NumIssues, got.NumIssues) | ||
assert.Equal(t, e.NumClosedIssues, got.NumClosedIssues) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.