-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Improvements of releases list and tags list #25859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
routers/web/repo/release_test.go
Outdated
| var err error | ||
| ctx.Data["NumReleases"], err = repo_model.GetReleaseCountByRepoID(ctx, ctx.Repo.Repository.ID, repo_model.FindReleasesOptions{ | ||
| IncludeDrafts: ctx.Repo.CanWrite(unit_model.TypeReleases), | ||
| }) | ||
| assert.NoError(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an assertion for ctx.Data["NumReleases"]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm .... I think the test code is not ideal. Calling Releases directly makes the middlewares never executed.
If it doesn't test NumReleases logic, it's better to remove this code block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for replying so late. I agree with your opinion that the test code is not ideal. Right now this unit test cannot work without the RepoAssignment middleware. I tried moving it to integration tests, then I found there was already a TestViewReleaseListNoLogin which tests the release list.
gitea/tests/integration/release_test.go
Lines 134 to 174 in 5600504
| func TestViewReleaseListNoLogin(t *testing.T) { | |
| defer tests.PrepareTestEnv(t)() | |
| repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 57, OwnerName: "user2", LowerName: "repo-release"}) | |
| link := repo.Link() + "/releases" | |
| req := NewRequest(t, "GET", link) | |
| rsp := MakeRequest(t, req, http.StatusOK) | |
| htmlDoc := NewHTMLParser(t, rsp.Body) | |
| releases := htmlDoc.Find("#release-list li.ui.grid") | |
| assert.Equal(t, 5, releases.Length()) | |
| links := make([]string, 0, 5) | |
| commitsToMain := make([]string, 0, 5) | |
| releases.Each(func(i int, s *goquery.Selection) { | |
| link, exist := s.Find(".release-list-title a").Attr("href") | |
| if !exist { | |
| return | |
| } | |
| links = append(links, link) | |
| commitsToMain = append(commitsToMain, s.Find(".ahead > a").Text()) | |
| }) | |
| assert.EqualValues(t, []string{ | |
| "/user2/repo-release/releases/tag/empty-target-branch", | |
| "/user2/repo-release/releases/tag/non-existing-target-branch", | |
| "/user2/repo-release/releases/tag/v2.0", | |
| "/user2/repo-release/releases/tag/v1.1", | |
| "/user2/repo-release/releases/tag/v1.0", | |
| }, links) | |
| assert.EqualValues(t, []string{ | |
| "1 commits", // like v1.1 | |
| "1 commits", // like v1.1 | |
| "0 commits", | |
| "1 commits", // should be 3 commits ahead and 2 commits behind, but not implemented yet | |
| "3 commits", | |
| }, commitsToMain) | |
| } |
Maybe we can remove TestNewReleasesList from unit tests?
wxiaoguang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why TestNewReleasesList is removed? Could it be kept?
Because In addition, as my previous comment said, I think the |
|
The test code and If I understand correctly, only the removed code tested the |
This fixes a regression from #25859 If a tag has no Release, Gitea will show a Link to create a Release for the Tag if the User has the Permission to do this, but the variable to indicate that is no longer set. Used here: https://github.com/go-gitea/gitea/blob/1bfcdeef4cca0f5509476358e5931c13d37ed1ca/templates/repo/tag/list.tmpl#L39-L41
Follow #23465 and #25624
This PR introduces the following improvements:
GetTagsto get tags because tags have been loaded byRepoAssignmentgitea/modules/context/repo.go
Lines 663 to 668 in ef90fdb
RepoAssignment, so the related code has been removed from the handlers. The query condition ofGetReleaseCountByRepoIDinRepoAssignmenthas been changed to include draft releases.gitea/modules/context/repo.go
Lines 538 to 551 in ef90fdb
releasesOrTagsfunction has been removed. The code for rendering releases list and tags list moved toReleasesandTagListrespectively.