package convert

import (
	repo_model "code.gitea.io/gitea/models/repo"
	user_model "code.gitea.io/gitea/models/user"
	gitea_convert "code.gitea.io/gitea/modules/convert"
	"code.gitea.io/gitea/modules/git"
	hat_api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs"
)

func ToCommit(repo *repo_model.Repository, gitRepo *git.Repository, commit *git.Commit, userCache map[string]*user_model.User, stat bool) (*hat_api.Commit, error) {
	giteaApiCommit, err := gitea_convert.ToCommit(repo, gitRepo, commit, userCache, stat)
	if err != nil {
		return nil, err
	}

	err = commit.LoadBranchName()
	if err != nil {
		return nil, err
	}

	return &hat_api.Commit{
		Commit: giteaApiCommit,
		Branch: commit.Branch,
	}, nil
}
