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) +}