I am very new to Go and am having issues printing out all releases for a given repo using the go-github
api.
I am adapting my code from the example in the project here.
This is the code I have so far.
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)
}
}
This works and runs okay (no errors at least), but when I run it, the code doesn't return anything. I have a feeling I am missing something simple but am stuck scratching my head.
From the GitHub documentation on the list releases API:
Since the repository you specified contains only tags and not releases, nothing is returned.
Changing
ListReleases
toListTags
yields output similar to the following: