feat: group release downloads by OS, load primary language for pinned repos
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
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
- 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>
This commit is contained in:
parent
2fc3e5a1c7
commit
6795122e00
@ -48,6 +48,8 @@ func NewFuncMap() template.FuncMap {
|
||||
// utils
|
||||
"StringUtils": NewStringUtils,
|
||||
"SliceUtils": NewSliceUtils,
|
||||
"slice": func() []any { return []any{} },
|
||||
"Append": func(s []any, v any) []any { return append(s, v) },
|
||||
"JsonUtils": NewJsonUtils,
|
||||
"DateUtils": NewDateUtils,
|
||||
|
||||
|
||||
@ -33,3 +33,17 @@ func (su *SliceUtils) Contains(s, v any) bool {
|
||||
}
|
||||
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()
|
||||
}
|
||||
|
||||
@ -61,6 +61,10 @@ func (su *StringUtils) ToUpper(s string) string {
|
||||
return strings.ToUpper(s)
|
||||
}
|
||||
|
||||
func (su *StringUtils) ToLower(s string) string {
|
||||
return strings.ToLower(s)
|
||||
}
|
||||
|
||||
func (su *StringUtils) TrimPrefix(s, prefix string) string {
|
||||
return strings.TrimPrefix(s, prefix)
|
||||
}
|
||||
|
||||
@ -37,9 +37,13 @@ func GetOrgPinnedReposWithDetails(ctx context.Context, orgID int64) ([]*organiza
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Attach repos
|
||||
// Attach repos and load attributes (including primary language)
|
||||
for _, p := range pinnedRepos {
|
||||
p.Repo = repos[p.RepoID]
|
||||
repo := repos[p.RepoID]
|
||||
if repo != nil {
|
||||
_ = repo.LoadAttributes(ctx)
|
||||
}
|
||||
p.Repo = repo
|
||||
}
|
||||
|
||||
return pinnedRepos, nil
|
||||
|
||||
@ -92,23 +92,137 @@
|
||||
<summary>
|
||||
{{ctx.Locale.Tr "repo.release.downloads"}}
|
||||
</summary>
|
||||
<ul class="ui divided list attachment-list">
|
||||
{{range $att := $release.Attachments}}
|
||||
<li class="item">
|
||||
<a target="_blank" class="tw-flex-1 gt-ellipsis" rel="nofollow" download href="{{$att.DownloadURL}}">
|
||||
<strong class="flex-text-inline">{{svg "octicon-package" 16 "download-icon"}}<span class="gt-ellipsis">{{$att.Name}}</span></strong>
|
||||
</a>
|
||||
<div class="attachment-right-info flex-text-inline">
|
||||
<span class="tw-pl-5">{{$att.Size | FileSize}}</span>
|
||||
<span class="flex-text-inline" data-tooltip-content="{{ctx.Locale.Tr "repo.release.download_count" (ctx.Locale.PrettyNumber $att.DownloadCount)}}">
|
||||
{{svg "octicon-info"}}
|
||||
</span>
|
||||
<div class="tw-flex-1"></div>
|
||||
{{DateUtils.TimeSince $att.CreatedUnix}}
|
||||
</div>
|
||||
</li>
|
||||
|
||||
{{/* Group attachments by OS */}}
|
||||
{{$windowsFiles := slice}}
|
||||
{{$macosFiles := slice}}
|
||||
{{$linuxFiles := slice}}
|
||||
{{$otherFiles := slice}}
|
||||
|
||||
{{range $att := $release.Attachments}}
|
||||
{{$name := StringUtils.ToLower $att.Name}}
|
||||
{{if or (StringUtils.Contains $name "windows") (StringUtils.Contains $name "win64") (StringUtils.Contains $name "win32") (StringUtils.Contains $name ".exe") (StringUtils.Contains $name ".msi")}}
|
||||
{{$windowsFiles = Append $windowsFiles $att}}
|
||||
{{else if or (StringUtils.Contains $name "darwin") (StringUtils.Contains $name "macos") (StringUtils.Contains $name "osx") (StringUtils.Contains $name ".dmg") (StringUtils.Contains $name ".pkg")}}
|
||||
{{$macosFiles = Append $macosFiles $att}}
|
||||
{{else if or (StringUtils.Contains $name "linux") (StringUtils.Contains $name ".deb") (StringUtils.Contains $name ".rpm") (StringUtils.Contains $name ".appimage")}}
|
||||
{{$linuxFiles = Append $linuxFiles $att}}
|
||||
{{else}}
|
||||
{{$otherFiles = Append $otherFiles $att}}
|
||||
{{end}}
|
||||
{{if and (not $.DisableDownloadSourceArchives) (not $release.IsDraft) ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode)}}
|
||||
{{end}}
|
||||
|
||||
{{/* Windows Downloads */}}
|
||||
{{if $windowsFiles}}
|
||||
<div class="tw-mb-3">
|
||||
<h5 class="tw-flex tw-items-center tw-gap-2 tw-mb-2 tw-font-medium">
|
||||
{{svg "octicon-device-desktop" 16}} Windows
|
||||
</h5>
|
||||
<ul class="ui divided list attachment-list tw-ml-4">
|
||||
{{range $att := $windowsFiles}}
|
||||
<li class="item">
|
||||
<a target="_blank" class="tw-flex-1 gt-ellipsis" rel="nofollow" download href="{{$att.DownloadURL}}">
|
||||
<strong class="flex-text-inline">{{svg "octicon-package" 16 "download-icon"}}<span class="gt-ellipsis">{{$att.Name}}</span></strong>
|
||||
</a>
|
||||
<div class="attachment-right-info flex-text-inline">
|
||||
<span class="tw-pl-5">{{$att.Size | FileSize}}</span>
|
||||
<span class="flex-text-inline" data-tooltip-content="{{ctx.Locale.Tr "repo.release.download_count" (ctx.Locale.PrettyNumber $att.DownloadCount)}}">
|
||||
{{svg "octicon-info"}}
|
||||
</span>
|
||||
<div class="tw-flex-1"></div>
|
||||
{{DateUtils.TimeSince $att.CreatedUnix}}
|
||||
</div>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{/* macOS Downloads */}}
|
||||
{{if $macosFiles}}
|
||||
<div class="tw-mb-3">
|
||||
<h5 class="tw-flex tw-items-center tw-gap-2 tw-mb-2 tw-font-medium">
|
||||
{{svg "octicon-device-desktop" 16}} macOS
|
||||
</h5>
|
||||
<ul class="ui divided list attachment-list tw-ml-4">
|
||||
{{range $att := $macosFiles}}
|
||||
<li class="item">
|
||||
<a target="_blank" class="tw-flex-1 gt-ellipsis" rel="nofollow" download href="{{$att.DownloadURL}}">
|
||||
<strong class="flex-text-inline">{{svg "octicon-package" 16 "download-icon"}}<span class="gt-ellipsis">{{$att.Name}}</span></strong>
|
||||
</a>
|
||||
<div class="attachment-right-info flex-text-inline">
|
||||
<span class="tw-pl-5">{{$att.Size | FileSize}}</span>
|
||||
<span class="flex-text-inline" data-tooltip-content="{{ctx.Locale.Tr "repo.release.download_count" (ctx.Locale.PrettyNumber $att.DownloadCount)}}">
|
||||
{{svg "octicon-info"}}
|
||||
</span>
|
||||
<div class="tw-flex-1"></div>
|
||||
{{DateUtils.TimeSince $att.CreatedUnix}}
|
||||
</div>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{/* Linux Downloads */}}
|
||||
{{if $linuxFiles}}
|
||||
<div class="tw-mb-3">
|
||||
<h5 class="tw-flex tw-items-center tw-gap-2 tw-mb-2 tw-font-medium">
|
||||
{{svg "octicon-terminal" 16}} Linux
|
||||
</h5>
|
||||
<ul class="ui divided list attachment-list tw-ml-4">
|
||||
{{range $att := $linuxFiles}}
|
||||
<li class="item">
|
||||
<a target="_blank" class="tw-flex-1 gt-ellipsis" rel="nofollow" download href="{{$att.DownloadURL}}">
|
||||
<strong class="flex-text-inline">{{svg "octicon-package" 16 "download-icon"}}<span class="gt-ellipsis">{{$att.Name}}</span></strong>
|
||||
</a>
|
||||
<div class="attachment-right-info flex-text-inline">
|
||||
<span class="tw-pl-5">{{$att.Size | FileSize}}</span>
|
||||
<span class="flex-text-inline" data-tooltip-content="{{ctx.Locale.Tr "repo.release.download_count" (ctx.Locale.PrettyNumber $att.DownloadCount)}}">
|
||||
{{svg "octicon-info"}}
|
||||
</span>
|
||||
<div class="tw-flex-1"></div>
|
||||
{{DateUtils.TimeSince $att.CreatedUnix}}
|
||||
</div>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{/* Other Downloads */}}
|
||||
{{if $otherFiles}}
|
||||
<div class="tw-mb-3">
|
||||
<h5 class="tw-flex tw-items-center tw-gap-2 tw-mb-2 tw-font-medium">
|
||||
{{svg "octicon-file" 16}} Other
|
||||
</h5>
|
||||
<ul class="ui divided list attachment-list tw-ml-4">
|
||||
{{range $att := $otherFiles}}
|
||||
<li class="item">
|
||||
<a target="_blank" class="tw-flex-1 gt-ellipsis" rel="nofollow" download href="{{$att.DownloadURL}}">
|
||||
<strong class="flex-text-inline">{{svg "octicon-package" 16 "download-icon"}}<span class="gt-ellipsis">{{$att.Name}}</span></strong>
|
||||
</a>
|
||||
<div class="attachment-right-info flex-text-inline">
|
||||
<span class="tw-pl-5">{{$att.Size | FileSize}}</span>
|
||||
<span class="flex-text-inline" data-tooltip-content="{{ctx.Locale.Tr "repo.release.download_count" (ctx.Locale.PrettyNumber $att.DownloadCount)}}">
|
||||
{{svg "octicon-info"}}
|
||||
</span>
|
||||
<div class="tw-flex-1"></div>
|
||||
{{DateUtils.TimeSince $att.CreatedUnix}}
|
||||
</div>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{/* Source Code Archives */}}
|
||||
{{if and (not $.DisableDownloadSourceArchives) (not $release.IsDraft) ($.Permission.CanRead ctx.Consts.RepoUnitTypeCode)}}
|
||||
<div class="tw-mb-3">
|
||||
<h5 class="tw-flex tw-items-center tw-gap-2 tw-mb-2 tw-font-medium">
|
||||
{{svg "octicon-code" 16}} Source Code
|
||||
</h5>
|
||||
<ul class="ui divided list attachment-list tw-ml-4">
|
||||
<li class="item">
|
||||
<a class="archive-link" download href="{{$.RepoLink}}/archive/{{$release.TagName | PathEscapeSegments}}.zip" rel="nofollow">
|
||||
<strong class="flex-text-inline">{{svg "octicon-file-zip" 16 "download-icon"}}{{ctx.Locale.Tr "repo.release.source_code"}} (ZIP)</strong>
|
||||
@ -119,8 +233,9 @@
|
||||
<strong class="flex-text-inline">{{svg "octicon-file-zip" 16 "download-icon"}}{{ctx.Locale.Tr "repo.release.source_code"}} (TAR.GZ)</strong>
|
||||
</a>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
{{end}}
|
||||
</details>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user