在 groovy GitBlit 挂钩中获取内容版本化文件
Get content versionned file in groovy GitBlit hook
我有一个在 Groovy 中制作的自定义预接收挂钩 GitBlit。我想读取当前存储库中的版本化文件并将其内容提取到字符串中。
我已经看到 {repository}
和 {user}
变量来获取存储库的绝对路径,但没有找到。
您知道获取此文件路径(或内容)的任何参数或工具函数吗?
谢谢
我找到了参考此 page 的解决方案。 com.gitblit.utils.JGitUtils
和 com.gitblit.GitBlit
中有工具函数允许将文件内容作为字符串获取。
文档可用here
import com.gitblit.GitBlit
import com.gitblit.Keys
import com.gitblit.models.RepositoryModel
import com.gitblit.models.UserModel
import com.gitblit.utils.JGitUtils
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.revwalk.RevCommit
import org.eclipse.jgit.transport.ReceiveCommand
import org.eclipse.jgit.transport.ReceiveCommand.Result
import org.slf4j.Logger
// Get repository
def repo = gitblit.getRepository(repository.name)
//logger.info(repo.dump()) // See a dump of the var in the logs
// Get string file content
def str = JGitUtils.getStringContent(repo, null, "myFile.txt", null)
NB : repository
var is naturally injected by GitBlit at the
execution of the groovy hook script.
我有一个在 Groovy 中制作的自定义预接收挂钩 GitBlit。我想读取当前存储库中的版本化文件并将其内容提取到字符串中。
我已经看到 {repository}
和 {user}
变量来获取存储库的绝对路径,但没有找到。
您知道获取此文件路径(或内容)的任何参数或工具函数吗? 谢谢
我找到了参考此 page 的解决方案。 com.gitblit.utils.JGitUtils
和 com.gitblit.GitBlit
中有工具函数允许将文件内容作为字符串获取。
文档可用here
import com.gitblit.GitBlit
import com.gitblit.Keys
import com.gitblit.models.RepositoryModel
import com.gitblit.models.UserModel
import com.gitblit.utils.JGitUtils
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.revwalk.RevCommit
import org.eclipse.jgit.transport.ReceiveCommand
import org.eclipse.jgit.transport.ReceiveCommand.Result
import org.slf4j.Logger
// Get repository
def repo = gitblit.getRepository(repository.name)
//logger.info(repo.dump()) // See a dump of the var in the logs
// Get string file content
def str = JGitUtils.getStringContent(repo, null, "myFile.txt", null)
NB :
repository
var is naturally injected by GitBlit at the execution of the groovy hook script.