summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-12-31 12:19:53 +0100
committerEarl Warren <contact@earl-warren.org>2025-01-05 14:46:19 +0100
commit81f30218cf20e95c605513af3a6730dcf095e4a6 (patch)
tree9437655787fb63c95a19fe21fffd55e6f7f75efe /models
parentFix issue comment number (#30556) (diff)
downloadforgejo-81f30218cf20e95c605513af3a6730dcf095e4a6.tar.xz
forgejo-81f30218cf20e95c605513af3a6730dcf095e4a6.zip
Use project's redirect url instead of composing url (#33058)
Fix #32992 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> (cherry picked from commit 20c7fba60157067252af49da41b6f8929a5ae31a) Conflicts: routers/web/repo/issue_new.go the function is at routers/web/repo/issue.go in Forgejo
Diffstat (limited to 'models')
-rw-r--r--models/project/project.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/models/project/project.go b/models/project/project.go
index 245838abb5..beffffcdfc 100644
--- a/models/project/project.go
+++ b/models/project/project.go
@@ -126,6 +126,14 @@ func (p *Project) LoadRepo(ctx context.Context) (err error) {
return err
}
+func ProjectLinkForOrg(org *user_model.User, projectID int64) string { //nolint
+ return fmt.Sprintf("%s/-/projects/%d", org.HomeLink(), projectID)
+}
+
+func ProjectLinkForRepo(repo *repo_model.Repository, projectID int64) string { //nolint
+ return fmt.Sprintf("%s/projects/%d", repo.Link(), projectID)
+}
+
// Link returns the project's relative URL.
func (p *Project) Link(ctx context.Context) string {
if p.OwnerID > 0 {
@@ -134,7 +142,7 @@ func (p *Project) Link(ctx context.Context) string {
log.Error("LoadOwner: %v", err)
return ""
}
- return fmt.Sprintf("%s/-/projects/%d", p.Owner.HomeLink(), p.ID)
+ return ProjectLinkForOrg(p.Owner, p.ID)
}
if p.RepoID > 0 {
err := p.LoadRepo(ctx)
@@ -142,7 +150,7 @@ func (p *Project) Link(ctx context.Context) string {
log.Error("LoadRepo: %v", err)
return ""
}
- return fmt.Sprintf("%s/projects/%d", p.Repo.Link(), p.ID)
+ return ProjectLinkForRepo(p.Repo, p.ID)
}
return ""
}