diff options
author | oliverpool <3864879+oliverpool@users.noreply.github.com> | 2023-05-10 05:43:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-10 11:43:55 +0800 |
commit | 8030614386b5d3fa02dc294446a344d274b04a26 (patch) | |
tree | 33868012ca12609feafbb3e938e0fcb5efeb5130 /models | |
parent | 5930ab5fdf7a970fcca3cd50b44cf1cacb615a54 (diff) | |
download | gitea-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 'models')
-rw-r--r-- | models/fixtures/release.yml | 28 | ||||
-rw-r--r-- | models/repo/release.go | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/models/fixtures/release.yml b/models/fixtures/release.yml index 6d09401ebc..4ed7df440d 100644 --- a/models/fixtures/release.yml +++ b/models/fixtures/release.yml @@ -108,3 +108,31 @@ is_prerelease: false is_tag: false created_unix: 946684803 + +- id: 9 + repo_id: 57 + publisher_id: 2 + tag_name: "non-existing-target-branch" + lower_tag_name: "non-existing-target-branch" + target: "non-existing" + title: "non-existing-target-branch" + sha1: "cef06e48f2642cd0dc9597b4bea09f4b3f74aad6" + num_commits: 5 + is_draft: false + is_prerelease: false + is_tag: false + created_unix: 946684803 + +- id: 10 + repo_id: 57 + publisher_id: 2 + tag_name: "empty-target-branch" + lower_tag_name: "empty-target-branch" + target: "" + title: "empty-target-branch" + sha1: "cef06e48f2642cd0dc9597b4bea09f4b3f74aad6" + num_commits: 5 + is_draft: false + is_prerelease: false + is_tag: false + created_unix: 946684803 diff --git a/models/repo/release.go b/models/repo/release.go index 75eb27f074..b77490584f 100644 --- a/models/repo/release.go +++ b/models/repo/release.go @@ -72,6 +72,7 @@ type Release struct { OriginalAuthorID int64 `xorm:"index"` LowerTagName string Target string + TargetBehind string `xorm:"-"` // to handle non-existing or empty target Title string Sha1 string `xorm:"VARCHAR(40)"` NumCommits int64 |