[英]How to use JFrog Artifactory to proxy GitHub as Go Repository?
[英]How to use Go to get the Github commit history of a given file of a repository
正如标题所说,我的问题是如何使用 Go 以编程方式获取给定存储库中给定文件的 Github 提交历史
看来你需要从golang访问GitHub
api。 有很多库,但我建议使用go-github 。
这是您可以尝试这样做的方法
package main
import (
"context"
"github.com/google/go-github/github"
)
func main() {
var username string = "MayukhSobo"
client := github.NewClient(nil)
commits, response, err := client.Repositories.ListCommits(context.Background(), username, "Awesome-Snippets", nil)
if err != nil && response.StatusCode != 200 {
panic(err)
}
for _, commit := range commits {
// commit.SHA
// commit.Files
// You can use the commit
}
}
如果您尝试访问其他一些公共仓库,则需要在username
名中传递所有者名称并更改仓库名称。
如果您遇到访问问题,可能是私人仓库。 您还可以使用密钥对来设置访问权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.