package convert

import (
	"context"

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

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

	branchName, err := commit.GetBranchName()
	if err != nil {
		return nil, err
	}

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