You've already forked go-semantic-release
fix(internal/releaser): add helper method to lookup for provider accesToken in environment variabels
This commit is contained in:
@@ -29,16 +29,22 @@ type Client struct {
|
|||||||
|
|
||||||
// New initialize a new GitHubRelease
|
// New initialize a new GitHubRelease
|
||||||
func New(c *config.GitHubProvider) (*Client, error) {
|
func New(c *config.GitHubProvider) (*Client, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if c.AccessToken, err = util.GetAccessToken(GITHUB); err != nil {
|
||||||
|
return &Client{}, err
|
||||||
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
httpClient := util.CreateBearerHTTPClient(ctx, c.AccessToken)
|
httpClient := util.CreateBearerHTTPClient(ctx, c.AccessToken)
|
||||||
|
|
||||||
var client *github.Client
|
var client *github.Client
|
||||||
var err error
|
|
||||||
baseURL := "https://github.com"
|
baseURL := "https://github.com"
|
||||||
if c.CustomURL == "" {
|
if c.CustomURL == "" {
|
||||||
client = github.NewClient(httpClient)
|
client = github.NewClient(httpClient)
|
||||||
} else {
|
} else {
|
||||||
client, err = github.NewEnterpriseClient(c.CustomURL, c.CustomURL+"/api/v3/", httpClient)
|
if client, err = github.NewEnterpriseClient(c.CustomURL, c.CustomURL+"/api/v3/", httpClient); err != nil {
|
||||||
|
return &Client{}, err
|
||||||
|
}
|
||||||
baseURL = c.CustomURL
|
baseURL = c.CustomURL
|
||||||
}
|
}
|
||||||
return &Client{
|
return &Client{
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
@@ -17,3 +20,15 @@ func CreateBearerHTTPClient(ctx context.Context, token string) *http.Client {
|
|||||||
|
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAccessToken lookup for the providers accesstoken
|
||||||
|
func GetAccessToken(providerName string) (string, error) {
|
||||||
|
var token string
|
||||||
|
var exists bool
|
||||||
|
envName := fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(providerName))
|
||||||
|
|
||||||
|
if token, exists = os.LookupEnv(envName); !exists {
|
||||||
|
return "", fmt.Errorf("Could not find %s in the enviroment variables. Please check if it is set", envName)
|
||||||
|
}
|
||||||
|
return token, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user