mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
132 lines
4.9 KiB
Go
132 lines
4.9 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
asymkey_model "github.com/hanzoai/git/models/asymkey"
|
|
git_model "github.com/hanzoai/git/models/git"
|
|
"github.com/hanzoai/git/models/gituser"
|
|
issues_model "github.com/hanzoai/git/models/issues"
|
|
"github.com/hanzoai/git/modules/git"
|
|
"github.com/hanzoai/git/modules/setting"
|
|
git_service "github.com/hanzoai/git/services/git"
|
|
"github.com/hanzoai/git/services/gitdiff"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAttachCommentsToLines(t *testing.T) {
|
|
section := &gitdiff.DiffSection{
|
|
Lines: []*gitdiff.DiffLine{
|
|
{LeftIdx: 5, RightIdx: 10},
|
|
{LeftIdx: 6, RightIdx: 11},
|
|
},
|
|
}
|
|
|
|
lineComments := map[int64][]*issues_model.Comment{
|
|
-5: {{ID: 100, CreatedUnix: 1000}}, // left side comment
|
|
10: {{ID: 200, CreatedUnix: 2000}}, // right side comment
|
|
11: {{ID: 300, CreatedUnix: 1500}, {ID: 301, CreatedUnix: 2500}}, // multiple comments
|
|
}
|
|
|
|
attachCommentsToLines(section, lineComments)
|
|
|
|
// First line should have left and right comments
|
|
assert.Len(t, section.Lines[0].Comments, 2)
|
|
assert.Equal(t, int64(100), section.Lines[0].Comments[0].ID)
|
|
assert.Equal(t, int64(200), section.Lines[0].Comments[1].ID)
|
|
|
|
// Second line should have two comments, sorted by creation time
|
|
assert.Len(t, section.Lines[1].Comments, 2)
|
|
assert.Equal(t, int64(300), section.Lines[1].Comments[0].ID)
|
|
assert.Equal(t, int64(301), section.Lines[1].Comments[1].ID)
|
|
}
|
|
|
|
func TestNewPullRequestTitleContent(t *testing.T) {
|
|
ci := &git_service.CompareInfo{HeadRef: "refs/heads/head-branch"}
|
|
|
|
mockCommit := func(msg string) *git_model.SignCommitWithStatuses {
|
|
return &git_model.SignCommitWithStatuses{
|
|
SignCommit: &asymkey_model.SignCommit{
|
|
UserCommit: &gituser.UserCommit{
|
|
GitCommit: &git.Commit{
|
|
CommitMessage: git.CommitMessage{MessageRaw: msg},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
// no commit
|
|
title, content := prepareNewPullRequestTitleContent(ci, nil, setting.RepoPRTitleSourceAuto)
|
|
assert.Equal(t, "Head branch", title)
|
|
assert.Empty(t, content)
|
|
|
|
title, content = prepareNewPullRequestTitleContent(ci, nil, setting.RepoPRTitleSourceFirstCommit)
|
|
assert.Equal(t, "Head branch", title)
|
|
assert.Empty(t, content)
|
|
|
|
title, content = prepareNewPullRequestTitleContent(ci, nil, setting.RepoPRTitleSourceBranchName)
|
|
assert.Equal(t, "head-branch", title)
|
|
assert.Empty(t, content)
|
|
|
|
// single commit
|
|
title, content = prepareNewPullRequestTitleContent(ci, []*git_model.SignCommitWithStatuses{mockCommit("single-commit-title\nbody")}, setting.RepoPRTitleSourceAuto)
|
|
assert.Equal(t, "single-commit-title", title)
|
|
assert.Equal(t, "body", content)
|
|
|
|
title, content = prepareNewPullRequestTitleContent(ci, []*git_model.SignCommitWithStatuses{mockCommit("single-commit-title\nbody")}, setting.RepoPRTitleSourceFirstCommit)
|
|
assert.Equal(t, "single-commit-title", title)
|
|
assert.Equal(t, "body", content)
|
|
|
|
// multiple commits
|
|
commits := []*git_model.SignCommitWithStatuses{
|
|
// ordered from newest to oldest
|
|
mockCommit("title2\nbody2"),
|
|
mockCommit("title1\nbody1"),
|
|
}
|
|
title, content = prepareNewPullRequestTitleContent(ci, commits, setting.RepoPRTitleSourceAuto)
|
|
assert.Equal(t, "Head branch", title)
|
|
assert.Empty(t, content)
|
|
|
|
title, content = prepareNewPullRequestTitleContent(ci, commits, setting.RepoPRTitleSourceFirstCommit)
|
|
assert.Equal(t, "title1", title)
|
|
assert.Empty(t, content)
|
|
|
|
// title string handling
|
|
title, content = prepareNewPullRequestTitleContent(ci, []*git_model.SignCommitWithStatuses{mockCommit("title-" + strings.Repeat("a", 255))}, setting.RepoPRTitleSourceFirstCommit)
|
|
assert.Equal(t, "title-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa…", title)
|
|
assert.Equal(t, "…aaaaaaaaa\n", content)
|
|
|
|
title, content = prepareNewPullRequestTitleContent(ci, []*git_model.SignCommitWithStatuses{mockCommit("title \xf0\nbody \xf0")}, setting.RepoPRTitleSourceFirstCommit)
|
|
assert.Equal(t, "title ð", title)
|
|
assert.Equal(t, "body ð", content)
|
|
}
|
|
|
|
func TestAutoTitleFromBranchName(t *testing.T) {
|
|
cases := []struct {
|
|
branch string
|
|
want string
|
|
}{
|
|
{"fix/the-bug", "Fix/the bug"},
|
|
{"Already-Capitalized", "Already capitalized"},
|
|
{"ALL-CAPS-BRANCH", "All caps branch"},
|
|
{"FixHTMLBug", "Fix html bug"},
|
|
{"MixedCase-Name", "Mixed case name"},
|
|
{"fooBar-baz", "Foo bar baz"},
|
|
{"foo/BAR", "Foo/bar"},
|
|
{"_leading-underscore", "Leading underscore"},
|
|
{"CamelCase", "Camel case"},
|
|
{"foo--double-dash", "Foo double dash"},
|
|
{"123-fix", "123 fix"},
|
|
}
|
|
for _, c := range cases {
|
|
assert.Equal(t, c.want, autoTitleFromBranchName(c.branch), "branch: %q", c.branch)
|
|
}
|
|
}
|