From 2795f5bc0e3465197f12dcf7d11ec4c7274fc9af Mon Sep 17 00:00:00 2001 From: Robert Wolff Date: Thu, 1 Aug 2024 17:26:52 +0200 Subject: [PATCH] feat(UI): fix links, add labels for releases on repo activity page --- options/locale/locale_en-US.ini | 4 +++- templates/repo/pulse.tmpl | 16 +++++++++---- tests/integration/repo_activity_test.go | 32 +++++++++++++++++++++---- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 3df2597886..915db6cc2e 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2119,7 +2119,9 @@ activity.unresolved_conv_label = Open activity.title.releases_1 = %d release activity.title.releases_n = %d releases activity.title.releases_published_by = %s published by %s -activity.published_release_label = Published +activity.published_release_label = Release +activity.published_prerelease_label = Pre-release +activity.published_tag_label = Tag activity.no_git_activity = There has not been any commit activity in this period. activity.git_stats_exclude_merges = Excluding merges, activity.git_stats_author_1 = %d author diff --git a/templates/repo/pulse.tmpl b/templates/repo/pulse.tmpl index 4790208541..0494883a85 100644 --- a/templates/repo/pulse.tmpl +++ b/templates/repo/pulse.tmpl @@ -122,10 +122,18 @@
{{range .Activity.PublishedReleases}}

- {{ctx.Locale.Tr "repo.activity.published_release_label"}} - {{.TagName}} - {{if not .IsTag}} - {{.Title | RenderEmoji $.Context | RenderCodeBlock}} + {{if .IsTag}} + {{ctx.Locale.Tr "repo.activity.published_tag_label"}} + {{else if .IsPrerelease}} + {{ctx.Locale.Tr "repo.activity.published_prerelease_label"}} + {{else}} + {{ctx.Locale.Tr "repo.activity.published_release_label"}} + {{end}} + {{if .IsTag}} + {{.TagName}} + {{else}} + {{.TagName}} + {{.Title | RenderEmoji $.Context | RenderCodeBlock}} {{end}} {{TimeSinceUnix .CreatedUnix ctx.Locale}}

diff --git a/tests/integration/repo_activity_test.go b/tests/integration/repo_activity_test.go index 824efddb52..dea7bcc415 100644 --- a/tests/integration/repo_activity_test.go +++ b/tests/integration/repo_activity_test.go @@ -7,9 +7,11 @@ import ( "fmt" "net/http" "net/url" + "sort" "strings" "testing" + auth_model "code.gitea.io/gitea/models/auth" "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" @@ -19,6 +21,7 @@ import ( repo_service "code.gitea.io/gitea/services/repository" "code.gitea.io/gitea/tests" + "github.com/PuerkitoBio/goquery" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -46,29 +49,50 @@ func TestRepoActivity(t *testing.T) { testNewIssue(t, session, "user2", "repo1", "Issue 2", "Description 2") testNewIssue(t, session, "user2", "repo1", "Issue 3", "Description 3") - // Create releases (1 new release) - createNewRelease(t, session, "/user2/repo1", "v1.0.0", "v1.0.0", false, false) + // Create releases (1 release, 1 pre-release, 1 release-draft, 1 tag) + createNewRelease(t, session, "/user2/repo1", "v1.0.0", "v1 Release", false, false) + createNewRelease(t, session, "/user2/repo1", "v0.1.0", "v0.1 Pre-release", true, false) + createNewRelease(t, session, "/user2/repo1", "v2.0.0", "v2 Release-Draft", false, true) + token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository) + createNewTagUsingAPI(t, token, "user2", "repo1", "v3.0.0", "master", "Tag message") // Open Activity page and check stats req := NewRequest(t, "GET", "/user2/repo1/activity") resp = session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - // Should be 1 published release + // Should be 3 published releases list := htmlDoc.doc.Find("#published-releases").Next().Find("p.desc") - assert.Len(t, list.Nodes, 1) + assert.Len(t, list.Nodes, 3) + var labels []string + var titles []string + list.Each(func(i int, s *goquery.Selection) { + labels = append(labels, s.Find(".label").Text()) + titles = append(titles, s.Find(".title").Text()) + }) + sort.Strings(labels) + sort.Strings(titles) + assert.Equal(t, []string{"Pre-release", "Release", "Tag"}, labels) + assert.Equal(t, []string{"", "v0.1 Pre-release", "v1 Release"}, titles) // Should be 1 merged pull request list = htmlDoc.doc.Find("#merged-pull-requests").Next().Find("p.desc") assert.Len(t, list.Nodes, 1) + assert.Equal(t, "Merged", list.Find(".label").Text()) // Should be 2 proposed pull requests list = htmlDoc.doc.Find("#proposed-pull-requests").Next().Find("p.desc") assert.Len(t, list.Nodes, 2) + assert.Equal(t, "Proposed", list.Find(".label").First().Text()) + + // Should be 0 closed issues + list = htmlDoc.doc.Find("#closed-issues").Next().Find("p.desc") + assert.Empty(t, list.Nodes) // Should be 3 new issues list = htmlDoc.doc.Find("#new-issues").Next().Find("p.desc") assert.Len(t, list.Nodes, 3) + assert.Equal(t, "Opened", list.Find(".label").First().Text()) }) }