Skip to content

Commit

Permalink
fetch GitHub API requests in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Oct 9, 2024
1 parent 50a59be commit 5e62f4d
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"net/url"
"os"
"regexp"
"sync"

"github.com/google/go-github/v65/github"
)

const version = "v3.7.2"
Expand Down Expand Up @@ -44,6 +47,31 @@ func remoteURL(config string) (*url.URL, error) {
return git.FirstRemoteURL()
}

func fetchInParallel(gh *GitHub) ([]*github.RepositoryRelease, []*github.Autolink, error) {
// Fetch the releases and autolinks in parallel. This is more efficient than fetching them in
// serial when we have the permission to fetch autolinks. Note that I'm not sure go-github's
// API client is thread-safe, but I checked that `-race` didn't report any error.
var wg sync.WaitGroup
wg.Add(2)

var rs []*github.RepositoryRelease
var err error
go func() {
rs, err = gh.Releases()
wg.Done()
}()

var ls []*github.Autolink
go func() {
// Ignore custom autolinks when we have no permission
ls, _ = gh.CustomAutolinks()
wg.Done()
}()

wg.Wait()
return rs, ls, err
}

func main() {
flag.Usage = usage
ver := flag.Bool("v", false, "Output version to stdout")
Expand Down Expand Up @@ -87,7 +115,7 @@ func main() {
fail(err)
}

rels, err := gh.Releases()
rels, ls, err := fetchInParallel(gh)
if err != nil {
fail(err)
}
Expand All @@ -99,7 +127,6 @@ func main() {
Extract: reExtract,
}
cl := NewChangeLog(os.Stdout, url, cfg)
ls, _ := gh.CustomAutolinks()
if err := cl.Generate(rels, ls); err != nil {
fail(err)
}
Expand Down

0 comments on commit 5e62f4d

Please sign in to comment.