如何使用go-github获取golang/go的发布版本。

huangapple go评论91阅读模式
英文:

How to get releases for golang/go with go-github

问题

学习Go并尝试使用go-github获取golang/go的发布列表。

以下是我的代码:

package main

import (
	"github.com/google/go-github/github"
	"fmt"
)


func main() {
	client := github.NewClient(nil)

	opt := &github.ListOptions{Page: 2, PerPage: 10}
	releases, rsp, err := client.Repositories.ListReleases("golang", "go", opt)

	if err != nil {
		fmt.Println(err)
	}
	
	fmt.Printf("\n%+v\n", releases)
	fmt.Printf("\n%+v\n", rsp)

}

当我运行它时,发布列表为空(如下所示):

[]
    
github.Rate{Limit:60, Remaining:59, Reset:github.Timestamp{2015-12-05 14:47:55 +1100 AEDT}}

我不知道我做错了什么。

英文:

Learning Go and try to get the release list of golang/go with go-github.

Here is my code:

package main

import (
	"github.com/google/go-github/github"
	"fmt"
)


func main() {
	client := github.NewClient(nil)

	opt := &github.ListOptions{Page: 2, PerPage: 10}
	releases, rsp, err := client.Repositories.ListReleases("golang", "go", opt)

	if err != nil {
		fmt.Println(err)
	}
	
	fmt.Printf("\n%+v\n", releases)
	fmt.Printf("\n%+v\n", rsp)

}

When I run it, the release list is empty (as below):

[]
    
github.Rate{Limit:60, Remaining:59, Reset:github.Timestamp{2015-12-05 14:47:55 +1100 AEDT}}

I don't know what I am doing wrong.

答案1

得分: 2

编辑:

仔细查看Go存储库,发现发布实际上只是标签,而不是Github发布,这就是为什么返回一个空数组的原因。尝试使用以下代码:

// https://api.github.com/repos/jp9000/obs-studio/releases
releases, rsp, err := client.Repositories.ListReleases("jp9000", "obs-studio", opt)

这应该正确返回jp9000的obs-studio存储库的所有发布。

原始答案:

根据文档,代码看起来没问题,但这可能是Github API的问题。例如,如果你访问https://api.github.com/repos/golang/go/releases,你会得到一个空数组,但如果你使用https://api.github.com/repos/golang/go/tags搜索标签,它会列出所有任务而没有任何问题。

如果你访问https://api.github.com/repos/golang/go/releases/1,你会得到一个404错误。我从Github开发者页面上获取了这些地址:https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository

英文:

Edit:

Taking a closer look at the Go repository, the releases are actually just tags and not Github releases, that's why it's returning an empty array. Try this:

// https://api.github.com/repos/jp9000/obs-studio/releases
releases, rsp, err := client.Repositories.ListReleases("jp9000", "obs-studio", opt)

This should correctly return all releases for jp9000's obs-studio repository.

Original Answer:

Looking at the docs, the code looks good but this might be an issue with Github's API though. For instance, if you go to https://api.github.com/repos/golang/go/releases you get an empty array, but if you search for the tags using https://api.github.com/repos/golang/go/tags it lists all tasks without any problem.

And if you go to https://api.github.com/repos/golang/go/releases/1 you get a 404. I took these addresses from the Github Developer's page: https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository

huangapple
  • 本文由 发表于 2015年12月5日 10:56:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/34100738.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定