1
0
Fork 0
forked from forgejo/forgejo

fix: release page for empty or non-existing target (#24659)

Backport #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.

_contributed in the context of @forgejo_

(cherry picked from commit cb7ba8969d)
This commit is contained in:
oliverpool 2023-05-12 20:14:41 +02:00 committed by Earl Warren
parent 3e8f99287a
commit 937b8e8184
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
6 changed files with 107 additions and 17 deletions

View file

@ -71,6 +71,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