mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 22:32:41 +01:00
55532061c8
This PR adds a new dropdown to select a commit or a commit range (shift-click like github) of a Pull Request. After selection of a commit only the changes of this commit will be shown. When selecting a range of commits the diff of this range is shown. This allows to review a PR commit by commit or by viewing only commit ranges. The "Show changes since your last review" mechanism github uses is implemented, too. When reviewing a single commit or a commit range the "Viewed" functionality is disabled. ## Screenshots ### The commit dropdown ![image](https://github.com/go-gitea/gitea/assets/51889757/0db3ae62-1272-436c-be64-4730c5d611e3) ### Selecting a commit range ![image](https://github.com/go-gitea/gitea/assets/51889757/ad81eedb-8437-42b0-8073-2d940c25fe8f) ### Show changes of a single commit only ![image](https://github.com/go-gitea/gitea/assets/51889757/6b1a113b-73ef-4ecc-adf6-bc2340bb8f97) ### Show changes of a commit range ![image](https://github.com/go-gitea/gitea/assets/51889757/6401b358-cd66-4c09-8baa-6cf6177f23a7) Fixes https://github.com/go-gitea/gitea/issues/20989 Fixes https://github.com/go-gitea/gitea/issues/19263 --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: delvh <dev.lh@web.de>
118 lines
3.7 KiB
Go
118 lines
3.7 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package user
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/modules/test"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestArchivedIssues(t *testing.T) {
|
|
// Arrange
|
|
setting.UI.IssuePagingNum = 1
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
ctx, _ := test.MockContext(t, "issues")
|
|
test.LoadUser(t, ctx, 30)
|
|
ctx.Req.Form.Set("state", "open")
|
|
|
|
// Assume: User 30 has access to two Repos with Issues, one of the Repos being archived.
|
|
repos, _, _ := repo_model.GetUserRepositories(&repo_model.SearchRepoOptions{Actor: ctx.Doer})
|
|
assert.Len(t, repos, 3)
|
|
IsArchived := make(map[int64]bool)
|
|
NumIssues := make(map[int64]int)
|
|
for _, repo := range repos {
|
|
IsArchived[repo.ID] = repo.IsArchived
|
|
NumIssues[repo.ID] = repo.NumIssues
|
|
}
|
|
assert.False(t, IsArchived[50])
|
|
assert.EqualValues(t, 1, NumIssues[50])
|
|
assert.True(t, IsArchived[51])
|
|
assert.EqualValues(t, 1, NumIssues[51])
|
|
|
|
// Act
|
|
Issues(ctx)
|
|
|
|
// Assert: One Issue (ID 30) from one Repo (ID 50) is retrieved, while nothing from archived Repo 51 is retrieved
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
assert.EqualValues(t, map[int64]int64{50: 1}, ctx.Data["Counts"])
|
|
assert.Len(t, ctx.Data["Issues"], 1)
|
|
assert.Len(t, ctx.Data["Repos"], 1)
|
|
}
|
|
|
|
func TestIssues(t *testing.T) {
|
|
setting.UI.IssuePagingNum = 1
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
ctx, _ := test.MockContext(t, "issues")
|
|
test.LoadUser(t, ctx, 2)
|
|
ctx.Req.Form.Set("state", "closed")
|
|
Issues(ctx)
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
assert.EqualValues(t, map[int64]int64{1: 1, 2: 1}, ctx.Data["Counts"])
|
|
assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
|
|
assert.Len(t, ctx.Data["Issues"], 1)
|
|
assert.Len(t, ctx.Data["Repos"], 2)
|
|
}
|
|
|
|
func TestPulls(t *testing.T) {
|
|
setting.UI.IssuePagingNum = 20
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
ctx, _ := test.MockContext(t, "pulls")
|
|
test.LoadUser(t, ctx, 2)
|
|
ctx.Req.Form.Set("state", "open")
|
|
Pulls(ctx)
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
assert.Len(t, ctx.Data["Issues"], 5)
|
|
}
|
|
|
|
func TestMilestones(t *testing.T) {
|
|
setting.UI.IssuePagingNum = 1
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
ctx, _ := test.MockContext(t, "milestones")
|
|
test.LoadUser(t, ctx, 2)
|
|
ctx.SetParams("sort", "issues")
|
|
ctx.Req.Form.Set("state", "closed")
|
|
ctx.Req.Form.Set("sort", "furthestduedate")
|
|
Milestones(ctx)
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
assert.EqualValues(t, map[int64]int64{1: 1}, ctx.Data["Counts"])
|
|
assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
|
|
assert.EqualValues(t, "furthestduedate", ctx.Data["SortType"])
|
|
assert.EqualValues(t, 1, ctx.Data["Total"])
|
|
assert.Len(t, ctx.Data["Milestones"], 1)
|
|
assert.Len(t, ctx.Data["Repos"], 2) // both repo 42 and 1 have milestones and both are owned by user 2
|
|
}
|
|
|
|
func TestMilestonesForSpecificRepo(t *testing.T) {
|
|
setting.UI.IssuePagingNum = 1
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
ctx, _ := test.MockContext(t, "milestones")
|
|
test.LoadUser(t, ctx, 2)
|
|
ctx.SetParams("sort", "issues")
|
|
ctx.SetParams("repo", "1")
|
|
ctx.Req.Form.Set("state", "closed")
|
|
ctx.Req.Form.Set("sort", "furthestduedate")
|
|
Milestones(ctx)
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
assert.EqualValues(t, map[int64]int64{1: 1}, ctx.Data["Counts"])
|
|
assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
|
|
assert.EqualValues(t, "furthestduedate", ctx.Data["SortType"])
|
|
assert.EqualValues(t, 1, ctx.Data["Total"])
|
|
assert.Len(t, ctx.Data["Milestones"], 1)
|
|
assert.Len(t, ctx.Data["Repos"], 2) // both repo 42 and 1 have milestones and both are owned by user 2
|
|
}
|