From 8d4f8d9a8600eb62891767293580b2b4f5275013 Mon Sep 17 00:00:00 2001 From: unilock Date: Thu, 1 Jun 2023 12:54:32 -0400 Subject: [PATCH] github: Accept GitHub API token via OS environment variable "GH_API_TOKEN" Signed-off-by: unilock --- github/request.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/github/request.go b/github/request.go index f3fb5f6..28b2119 100644 --- a/github/request.go +++ b/github/request.go @@ -3,6 +3,7 @@ package github import ( "fmt" "net/http" + "os" "github.com/packwiz/packwiz/core" ) @@ -17,6 +18,8 @@ type ghApiClient struct { var ghDefaultClient = ghApiClient{&http.Client{}} func (c *ghApiClient) makeGet(url string) (*http.Response, error) { + ghApiToken := os.Getenv("GH_API_TOKEN") + req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, err @@ -24,6 +27,9 @@ func (c *ghApiClient) makeGet(url string) (*http.Response, error) { req.Header.Set("User-Agent", core.UserAgent) req.Header.Set("Accept", "application/vnd.github+json") + if ghApiToken != "" { + req.Header.Set("Authorization", "Bearer " + ghApiToken) + } resp, err := c.httpClient.Do(req) if err != nil {