Fix the way the environment variables are retrieved
This commit is contained in:
parent
f802f2b6eb
commit
deb1ba6843
24
main.go
24
main.go
|
@ -5,16 +5,13 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"github.com/sethvargo/go-githubactions"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ParseActionConfig() (*CreatePrConfig, error) {
|
||||
ctx, err := githubactions.Context()
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
func ParseActionConfig(ctx githubactions.GitHubContext) (*CreatePrConfig, error) {
|
||||
base := githubactions.GetInput("base")
|
||||
if base == "" {
|
||||
return nil, errors.New("base branch name cannot be empty")
|
||||
|
@ -47,10 +44,10 @@ func ParseActionConfig() (*CreatePrConfig, error) {
|
|||
var head string
|
||||
headRaw := githubactions.GetInput("head")
|
||||
if headRaw == "" {
|
||||
if githubactions.GetInput("GITHUB_REF_TYPE") != "branch" {
|
||||
if os.Getenv("GITHUB_REF_TYPE") != "branch" {
|
||||
return nil, fmt.Errorf("set the \"head\" parameter or work from a branch: only branch can create a pull request: %v given as parameter GITHUB_REF_TYPE", githubactions.GetInput("GITHUB_REF_TYPE"))
|
||||
}
|
||||
head = githubactions.GetInput("GITHUB_REF_NAME")
|
||||
head = os.Getenv("GITHUB_REF_NAME")
|
||||
} else {
|
||||
head = headRaw
|
||||
}
|
||||
|
@ -69,17 +66,20 @@ func ParseActionConfig() (*CreatePrConfig, error) {
|
|||
|
||||
func main() {
|
||||
fmt.Println("Starting action CreatePullRequest, main")
|
||||
ctx, err := githubactions.Context()
|
||||
if err != nil {
|
||||
githubactions.Fatalf("could not get context: %v", err.Error())
|
||||
}
|
||||
|
||||
token := githubactions.GetInput("GITHUB_TOKEN")
|
||||
apiUrl := githubactions.GetInput("GITHUB_API_URL")
|
||||
fmt.Printf("Api url is %v\n", apiUrl)
|
||||
token := os.Getenv("GITHUB_TOKEN")
|
||||
fmt.Printf("Api url is %v\n", ctx.ServerURL)
|
||||
|
||||
config, err := ParseActionConfig()
|
||||
config, err := ParseActionConfig(*ctx)
|
||||
if err != nil {
|
||||
githubactions.Fatalf("%v", err.Error())
|
||||
}
|
||||
|
||||
pr, err := createPullRequest(apiUrl, token, *config)
|
||||
pr, err := createPullRequest(ctx.ServerURL, token, *config)
|
||||
if err != nil {
|
||||
githubactions.Fatalf("Error while creating pr: %v", err.Error())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue