mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-01 09:01:22 +00:00
@@ -66,6 +66,7 @@ func convertPGPSignature(c *object.Commit) *CommitSignature {
|
||||
func convertCommit(c *object.Commit) *Commit {
|
||||
return &Commit{
|
||||
ID: ParseGogitHash(c.Hash),
|
||||
TreeID: ParseGogitHash(c.TreeHash),
|
||||
CommitMessage: CommitMessage{MessageRaw: c.Message},
|
||||
Committer: &c.Committer,
|
||||
Author: &c.Author,
|
||||
|
||||
@@ -37,6 +37,7 @@ func TestGetNoteNestedWithCache(t *testing.T) {
|
||||
assert.Equal(t, "Note 1", note.BlobMessage.MessageUTF8())
|
||||
assert.Equal(t, "ba0a96fa63532d6c5087ecef070b0250ed72fa47", note.TreePath)
|
||||
assert.Equal(t, "Filip Navara", lastCommit.Author.Name)
|
||||
assert.Equal(t, "fec9fe57e9864fe537f02f825e377c4a8a65ad2e", lastCommit.TreeID.String())
|
||||
|
||||
note, lastCommit, err = GetNoteWithLastCommit(t.Context(), repo, "3e668dbfac39cbc80a9ff9c61eb565d944453ba4")
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -172,8 +172,8 @@ func ToCommit(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Rep
|
||||
},
|
||||
Message: commit.MessageUTF8(),
|
||||
Tree: &api.CommitMeta{
|
||||
URL: repo.APIURL() + "/git/trees/" + url.PathEscape(commit.ID.String()),
|
||||
SHA: commit.ID.String(),
|
||||
URL: repo.APIURL() + "/git/trees/" + url.PathEscape(commit.TreeID.String()),
|
||||
SHA: commit.TreeID.String(),
|
||||
Created: commit.Committer.When,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
api "gitea.dev/modules/structs"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestToCommitMeta(t *testing.T) {
|
||||
@@ -38,3 +39,21 @@ func TestToCommitMeta(t *testing.T) {
|
||||
Created: time.Unix(0, 0),
|
||||
}, commitMeta)
|
||||
}
|
||||
|
||||
func TestToCommitTree(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
signature := &git.Signature{Name: "Test Signature", Email: "test@email.com", When: time.Unix(0, 0)}
|
||||
commit := &git.Commit{
|
||||
ID: git.MustIDFromString("65f1bf27bc3bf70f64657658635e66094edbcb4d"),
|
||||
TreeID: git.MustIDFromString("2a2f1d4670728a2e10049e345bd7a276468beab6"),
|
||||
Author: signature,
|
||||
Committer: signature,
|
||||
}
|
||||
|
||||
apiCommit, err := ToCommit(t.Context(), repo, nil, commit, nil, ToCommitOptions{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "2a2f1d4670728a2e10049e345bd7a276468beab6", apiCommit.RepoCommit.Tree.SHA)
|
||||
assert.Equal(t, repo.APIURL()+"/git/trees/2a2f1d4670728a2e10049e345bd7a276468beab6", apiCommit.RepoCommit.Tree.URL)
|
||||
assert.Equal(t, "65f1bf27bc3bf70f64657658635e66094edbcb4d", apiCommit.SHA)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user