feat: show timestamp on release attachments (#8757)

- Show the `created_unix` timestamp as relative time for each non-external release attachment.
- The details section of the release attachment can become quite long in width, for smaller screens it's now shown as columns.
- Integration test added.

Close #7600

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8757
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Squel <squeljur+git@gmail.com>
Co-committed-by: Squel <squeljur+git@gmail.com>
This commit is contained in:
Squel 2025-08-08 03:19:28 +02:00 committed by Gusted
commit dd653c4784
2 changed files with 21 additions and 2 deletions

View file

@ -103,12 +103,12 @@
</a>
</li>
{{else}}
<li>
<li class="max-sm:tw-flex-col max-sm:tw-gap-2">
<a class="tw-flex-1 flex-text-inline tw-font-bold" target="_blank" rel="nofollow" href="{{.DownloadURL}}" download>
{{svg "octicon-package" 16 "tw-mr-1"}}{{.Name}}
</a>
<div>
<span class="text grey">{{ctx.Locale.TrN .DownloadCount "repo.release.download_count_one" "repo.release.download_count_few" (ctx.Locale.PrettyNumber .DownloadCount)}} · {{.Size | ctx.Locale.TrSize}}</span>
<span class="text grey">{{ctx.Locale.TrN .DownloadCount "repo.release.download_count_one" "repo.release.download_count_few" (ctx.Locale.PrettyNumber .DownloadCount)}} · {{DateUtils.TimeSince .CreatedUnix}} · {{.Size | ctx.Locale.TrSize}}</span>
</div>
</li>
{{end}}

View file

@ -9,6 +9,7 @@ import (
"net/http"
"strconv"
"testing"
"time"
auth_model "forgejo.org/models/auth"
"forgejo.org/models/db"
@ -17,6 +18,7 @@ import (
"forgejo.org/modules/setting"
api "forgejo.org/modules/structs"
"forgejo.org/modules/test"
"forgejo.org/modules/timeutil"
"forgejo.org/modules/translation"
"forgejo.org/tests"
@ -329,6 +331,23 @@ func TestViewTagsList(t *testing.T) {
assert.Equal(t, []string{"v1.0", "delete-tag", "v1.1"}, tagNames)
}
func TestAttachmentTimestamp(t *testing.T) {
defer tests.PrepareTestEnv(t)()
req := NewRequest(t, "GET", "user2/repo1/releases")
resp := MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
var timeStamp int64 = 946684800
unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{
UUID: "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a20",
CreatedUnix: timeutil.TimeStamp(timeStamp),
})
formattedTime := time.Unix(timeStamp, 0).Format(time.RFC3339)
htmlDoc.AssertElement(t, fmt.Sprintf("details.download relative-time[datetime='%s']", formattedTime), true)
}
func TestDownloadReleaseAttachment(t *testing.T) {
defer tests.PrepareTestEnv(t)()