gpt4 book ai didi

go - 使用 go-github 打印存储库版本

转载 作者:数据小太阳 更新时间:2023-10-29 03:06:58 25 4
gpt4 key购买 nike

我是 Go 的新手,在使用 go-github api 打印给定存储库的所有版本时遇到问题。

我正在改编来自 example in the project 的代码在这里。

这是我目前的代码。

package main

import (
"fmt"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)

func main() {

// authentication
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: "XXX"})
tc := oauth2.NewClient(oauth2.NoContext, ts)

client := github.NewClient(tc)

// list all releases for single repo
fmt.Println("Releases for repo")
opt := &github.ListOptions{Page: 2, PerPage: 10}
releases, _, err := client.Repositories.ListReleases("hashicorp", "terraform", opt)

if err != nil {
fmt.Printf("error: %v\n", err)
} else {
for _, release := range releases {
fmt.Printf("%v\n", release)
}
}

这可以正常运行(至少没有错误),但是当我运行它时,代码没有返回任何内容。我有一种感觉,我错过了一些简单的东西,但我一直在摸不着头脑。

最佳答案

来自GitHub documentation on the list releases API :

This returns a list of releases, which does not include regular Git tags that have not been associated with a release. To get a list of Git tags, use the Repository Tags API.

由于您指定的存储库仅包含标签而不包含发布,因此不会返回任何内容。

改变 ListReleasesListTags产生类似于以下内容的输出:

Releases for repo
{0xc2081e1a10 github.Commit{SHA:"d8292227960eab405863ffbc5d13cc85839aa2db", URL:"https://api.github.com/repos/hashicorp/terraform/commits/d8292227960eab405863ffbc5d13cc85839aa2db"} 0xc2081e1a50 0xc2081e1a60}
{0xc2081e1c40 github.Commit{SHA:"4ed2c8d956d2eae83a2a3750290711ce7fa1ec76", URL:"https://api.github.com/repos/hashicorp/terraform/commits/4ed2c8d956d2eae83a2a3750290711ce7fa1ec76"} 0xc2081e1c60 0xc2081e1c70}
{0xc2081e1ca0 github.Commit{SHA:"33e11f0eba1b634849784151b29f69314bfae827", URL:"https://api.github.com/repos/hashicorp/terraform/commits/33e11f0eba1b634849784151b29f69314bfae827"} 0xc2081e1cb0 0xc2081e1cc0}
{0xc2081e1cf0 github.Commit{SHA:"8175d7f82134d378234a407e529853da681af07e", URL:"https://api.github.com/repos/hashicorp/terraform/commits/8175d7f82134d378234a407e529853da681af07e"} 0xc2081e1d10 0xc2081e1d20}
{0xc2081e1d50 github.Commit{SHA:"166efa1ba0c7aa2fb5a7230f787c8499c765786e", URL:"https://api.github.com/repos/hashicorp/terraform/commits/166efa1ba0c7aa2fb5a7230f787c8499c765786e"} 0xc2081e1d60 0xc2081e1d70}
{0xc2081e1da0 github.Commit{SHA:"1894e985557f010a4bca873c5b10bedb1cd7de5d", URL:"https://api.github.com/repos/hashicorp/terraform/commits/1894e985557f010a4bca873c5b10bedb1cd7de5d"} 0xc2081e1dc0 0xc2081e1dd0}
{0xc2081e1e00 github.Commit{SHA:"0bc0c03fece07c4f21ee5195743116a4d418f234", URL:"https://api.github.com/repos/hashicorp/terraform/commits/0bc0c03fece07c4f21ee5195743116a4d418f234"} 0xc2081e1e10 0xc2081e1e20}
{0xc2081e1e50 github.Commit{SHA:"4e11ed4327fa638a4c2587489a8660c69beb4047", URL:"https://api.github.com/repos/hashicorp/terraform/commits/4e11ed4327fa638a4c2587489a8660c69beb4047"} 0xc2081e1e70 0xc2081e1e80}
{0xc2081e1eb0 github.Commit{SHA:"a4cf3fec1c8341041f41897ea84781e6be9b1dad", URL:"https://api.github.com/repos/hashicorp/terraform/commits/a4cf3fec1c8341041f41897ea84781e6be9b1dad"} 0xc2081e1ec0 0xc2081e1ed0}
{0xc2081e1f00 github.Commit{SHA:"146d081b65aba3e0f183d6e4b26f3e794fabaebf", URL:"https://api.github.com/repos/hashicorp/terraform/commits/146d081b65aba3e0f183d6e4b26f3e794fabaebf"} 0xc2081e1f20 0xc2081e1f30}

关于go - 使用 go-github 打印存储库版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30766606/

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