Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions pkg/loader/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"

Expand All @@ -20,19 +21,35 @@ const (
githubCommitURL = "https://api.github.com/repos/%s/%s/commits/%s"
)

var (
githubAuthToken = os.Getenv("GITHUB_AUTH_TOKEN")
)

func init() {
loader.AddVSC(Load)
}

func getCommit(account, repo, ref string) (string, error) {
url := fmt.Sprintf(githubCommitURL, account, repo, ref)
resp, err := http.Get(url)
client := &http.Client{}

req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return "", fmt.Errorf("failed to create request of %s/%s at %s: %w", account, repo, url, err)
}

if githubAuthToken != "" {
req.Header.Add("Authorization", "Bearer "+githubAuthToken)
}

resp, err := client.Do(req)

if err != nil {
return "", err
} else if resp.StatusCode != http.StatusOK {
c, _ := io.ReadAll(resp.Body)
resp.Body.Close()
return "", fmt.Errorf("failed to GitHub commit of %s/%s at %s: %s %s",
return "", fmt.Errorf("failed to get GitHub commit of %s/%s at %s: %s %s",
account, repo, ref, resp.Status, c)
}
defer resp.Body.Close()
Expand Down