mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-04 07:33:44 +09:00
@@ -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