summaryrefslogtreecommitdiffstats
path: root/tests/integration
diff options
context:
space:
mode:
authoroliverpool <3864879+oliverpool@users.noreply.github.com>2023-05-10 05:43:55 +0200
committerGitHub <noreply@github.com>2023-05-10 11:43:55 +0800
commit8030614386b5d3fa02dc294446a344d274b04a26 (patch)
tree33868012ca12609feafbb3e938e0fcb5efeb5130 /tests/integration
parent5930ab5fdf7a970fcca3cd50b44cf1cacb615a54 (diff)
downloadgitea-8030614386b5d3fa02dc294446a344d274b04a26.tar.gz
gitea-8030614386b5d3fa02dc294446a344d274b04a26.zip
fix: release page for empty or non-existing target (#24470)
Fixes #24145 To solve the bug, I added a "computed" `TargetBehind` field to the `Release` model, which indicates the target branch of a release. This is particularly useful if the target branch was deleted in the meantime (or is empty). I also did a micro-optimization in `calReleaseNumCommitsBehind`. Instead of checking that a branch exists and then call `GetBranchCommit`, I immediately call `GetBranchCommit` and handle the `git.ErrNotExist` error. This optimization is covered by the added unit test.
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/release_test.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/tests/integration/release_test.go b/tests/integration/release_test.go
index 8e3f96c93b..8de761ea6c 100644
--- a/tests/integration/release_test.go
+++ b/tests/integration/release_test.go
@@ -143,10 +143,10 @@ func TestViewReleaseListNoLogin(t *testing.T) {
htmlDoc := NewHTMLParser(t, rsp.Body)
releases := htmlDoc.Find("#release-list li.ui.grid")
- assert.Equal(t, 3, releases.Length())
+ assert.Equal(t, 5, releases.Length())
- links := make([]string, 0, 3)
- commitsToMain := make([]string, 0, 3)
+ 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 {
@@ -158,11 +158,15 @@ func TestViewReleaseListNoLogin(t *testing.T) {
})
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",