gpt4 book ai didi

git - 如何在Golang中使用git2go在github中获取最新标签?

转载 作者:行者123 更新时间:2023-12-01 22:29:48 25 4
gpt4 key购买 nike

我正在尝试从golang的本地存储库中获取最新的github标记。
现在,我得到了所有标签,代码如下:

repo, err := git.OpenRepository("/home/defiant/Temp/repo")
checkErr(err)
re, err := repo.Tags.List()
checkErr(err)
fmt.Println(re)

返回的结果格式为:
[0.1 1.3 1.4]

这里是最新的标记1.3。那么有人可以帮我获取最新标签吗?

最佳答案

您正在寻找的位是signature对象(它具有when字段)。在提交时,您可能对authorcommitter感兴趣。如果您自己使用annotated标记-它们具有tagger字段,即标记提交的时间。

如果您只有带注释的标签(即没有轻量级标签),则应该为标签获取时间戳:

repo, err := git.OpenRepository("/home/defiant/Temp/repo")
if err != nil {
panic(err)
}
err = repo.Tags.Foreach(func(name string, id *git.Oid) error {
tag, err := repo.LookupTag(id)
if err != nil {
return err
}
log.Info(tag.Tagger().When)
return nil
})

使用轻量级标签,您将需要直接解决提交-您应该能够使用 LookupCommit做到这一点,并明确选择 committerauthor

关于git - 如何在Golang中使用git2go在github中获取最新标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40155665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com