From 100ddf45a74e079f51f43f17b98f3904d4d8d04a Mon Sep 17 00:00:00 2001 From: zokki Date: Sun, 17 Aug 2025 12:18:09 +0200 Subject: [PATCH] [v12.0/forgejo] fix: redirect from /{username}/{reponame}/pulls/{index} to issue if index is a issue (#8876) **Backport:** !8874 conflict resolved by accepting the incomming hunk and removing TestIssueTimelineLabels-func Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8876 Reviewed-by: Earl Warren Reviewed-by: floss4good Co-authored-by: zokki Co-committed-by: zokki --- routers/web/repo/pull.go | 2 +- tests/integration/issue_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 1e3eda9b61..87a7d2d5cd 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -360,7 +360,7 @@ func getPullInfo(ctx *context.Context) (issue *issues_model.Issue, ok bool) { ctx.Data["Issue"] = issue if !issue.IsPull { - ctx.NotFound("ViewPullCommits", nil) + ctx.Redirect(issue.Link()) return nil, false } diff --git a/tests/integration/issue_test.go b/tests/integration/issue_test.go index 2b50be48a4..368897f461 100644 --- a/tests/integration/issue_test.go +++ b/tests/integration/issue_test.go @@ -1526,3 +1526,35 @@ func TestIssuePostersSearch(t *testing.T) { assert.EqualValues(t, 1, data.Results[0].UserID) }) } + +func TestIssueAndPullRedirect(t *testing.T) { + defer tests.PrepareTestEnv(t)() + + req := NewRequest(t, "GET", "/user2/repo1/issues/1") + MakeRequest(t, req, http.StatusOK) + + req = NewRequest(t, "GET", "/user2/repo1/pulls/2") + MakeRequest(t, req, http.StatusOK) + + req = NewRequest(t, "GET", "/user2/repo1/pulls/1") + resp := MakeRequest(t, req, http.StatusSeeOther) + assert.Equal(t, "/user2/repo1/issues/1", resp.Header().Get("Location")) + + req = NewRequest(t, "GET", "/user2/repo1/pulls/1/commits") + resp = MakeRequest(t, req, http.StatusSeeOther) + assert.Equal(t, "/user2/repo1/issues/1", resp.Header().Get("Location")) + + req = NewRequest(t, "GET", "/user2/repo1/pulls/1/files") + resp = MakeRequest(t, req, http.StatusSeeOther) + assert.Equal(t, "/user2/repo1/issues/1", resp.Header().Get("Location")) + + req = NewRequest(t, "GET", "/user2/repo1/issues/2") + resp = MakeRequest(t, req, http.StatusSeeOther) + assert.Equal(t, "/user2/repo1/pulls/2", resp.Header().Get("Location")) + + req = NewRequest(t, "GET", "/user2/repo1/issues/9999999") + MakeRequest(t, req, http.StatusNotFound) + + req = NewRequest(t, "GET", "/user2/repo1/pulls/9999999") + MakeRequest(t, req, http.StatusNotFound) +}