繁体   English   中英

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

[英]Print out repository releases with go-github

我对Go很陌生,在使用go-github api打印给定回购的所有发行版时遇到问题。

我正在从这里的项目示例中修改我的代码。

这是我到目前为止的代码。

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文档中发布API

这将返回发行版列表,其中不包括尚未与发行版关联的常规Git标签。 要获取Git标签列表,请使用Repository Tags API

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

ListReleases更改为ListTags产生类似于以下内容的输出:

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}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM