Skip to content

Commit a928739

Browse files
authored
Refactor sidebar assignee&milestone&project selectors (#32465)
Follow #32460 Now the code could be much clearer than before and easier to maintain. A lot of legacy code is removed. Manually tested. This PR is large enough, that fine tunes could be deferred to the future if there is no bug found or design problem. Screenshots: <details> ![image](https://github.com/user-attachments/assets/35f4ab7b-1bc0-4bad-a73c-a4569328303c) </details>
1 parent 58c634b commit a928739

23 files changed

+504
-829
lines changed

modules/base/tool.go

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ func StringsToInt64s(strs []string) ([]int64, error) {
147147
}
148148
ints := make([]int64, 0, len(strs))
149149
for _, s := range strs {
150+
if s == "" {
151+
continue
152+
}
150153
n, err := strconv.ParseInt(s, 10, 64)
151154
if err != nil {
152155
return nil, err

modules/base/tool_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func TestStringsToInt64s(t *testing.T) {
152152
}
153153
testSuccess(nil, nil)
154154
testSuccess([]string{}, []int64{})
155+
testSuccess([]string{""}, []int64{})
155156
testSuccess([]string{"-1234"}, []int64{-1234})
156157
testSuccess([]string{"1", "4", "16", "64", "256"}, []int64{1, 4, 16, 64, 256})
157158

modules/container/set.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ func (s Set[T]) AddMultiple(values ...T) {
3131
}
3232
}
3333

34-
// Contains determines whether a set contains the specified elements.
35-
// Returns true if the set contains the specified element; otherwise, false.
34+
// Contains determines whether a set contains all these elements.
35+
// Returns true if the set contains all these elements; otherwise, false.
3636
func (s Set[T]) Contains(values ...T) bool {
3737
ret := true
3838
for _, value := range values {

modules/container/set_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ func TestSet(t *testing.T) {
1818

1919
assert.True(t, s.Contains("key1"))
2020
assert.True(t, s.Contains("key2"))
21+
assert.True(t, s.Contains("key1", "key2"))
2122
assert.False(t, s.Contains("key3"))
23+
assert.False(t, s.Contains("key1", "key3"))
2224

2325
assert.True(t, s.Remove("key2"))
2426
assert.False(t, s.Contains("key2"))

modules/templates/helper.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func NewFuncMap() template.FuncMap {
3131
"ctx": func() any { return nil }, // template context function
3232

3333
"DumpVar": dumpVar,
34+
"NIL": func() any { return nil },
3435

3536
// -----------------------------------------------------------------
3637
// html/template related functions

routers/web/repo/compare.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -788,19 +788,11 @@ func CompareDiff(ctx *context.Context) {
788788

789789
if !nothingToCompare {
790790
// Setup information for new form.
791-
retrieveRepoMetasForIssueWriter(ctx, ctx.Repo.Repository, true)
791+
pageMetaData := retrieveRepoIssueMetaData(ctx, ctx.Repo.Repository, nil, true)
792792
if ctx.Written() {
793793
return
794794
}
795-
labelsData := retrieveRepoLabels(ctx, ctx.Repo.Repository, 0, true)
796-
if ctx.Written() {
797-
return
798-
}
799-
RetrieveRepoReviewers(ctx, ctx.Repo.Repository, nil, true)
800-
if ctx.Written() {
801-
return
802-
}
803-
_, templateErrs := setTemplateIfExists(ctx, pullRequestTemplateKey, pullRequestTemplateCandidates, labelsData)
795+
_, templateErrs := setTemplateIfExists(ctx, pullRequestTemplateKey, pullRequestTemplateCandidates, pageMetaData)
804796
if len(templateErrs) > 0 {
805797
ctx.Flash.Warning(renderErrorOfTemplates(ctx, templateErrs), true)
806798
}

0 commit comments

Comments
 (0)