gitea/modules/templates/util_slice.go
Admin 6795122e00
Some checks failed
Build and Release / Create Release (push) Has been skipped
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 1m32s
Build and Release / Lint (push) Failing after 1m54s
Build and Release / Build Binaries (arm64, linux) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux) (push) Has been skipped
Build and Release / Build Binaries (amd64, windows) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 1m59s
feat: group release downloads by OS, load primary language for pinned repos
- Add ToLower to StringUtils template helper
- Add slice and Append template functions for grouping
- Group release attachments by OS (Windows, macOS, Linux, Other)
- Load primary language for org pinned repos to show in cards

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-11 04:27:55 +00:00

50 lines
1.0 KiB
Go

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package templates
import (
"fmt"
"reflect"
)
type SliceUtils struct{}
func NewSliceUtils() *SliceUtils {
return &SliceUtils{}
}
func (su *SliceUtils) Contains(s, v any) bool {
if s == nil {
return false
}
sv := reflect.ValueOf(s)
if sv.Kind() != reflect.Slice && sv.Kind() != reflect.Array {
panic(fmt.Sprintf("invalid type, expected slice or array, but got: %T", s))
}
for i := 0; i < sv.Len(); i++ {
it := sv.Index(i)
if !it.CanInterface() {
continue
}
if it.Interface() == v {
return true
}
}
return false
}
// Append appends an element to a slice and returns the new slice
func (su *SliceUtils) Append(s any, v any) any {
if s == nil {
return []any{v}
}
sv := reflect.ValueOf(s)
if sv.Kind() != reflect.Slice {
panic(fmt.Sprintf("invalid type, expected slice, but got: %T", s))
}
// Create a new slice with the appended element
newSlice := reflect.Append(sv, reflect.ValueOf(v))
return newSlice.Interface()
}