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"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sethvargo/go-githubactions"
|
"github.com/sethvargo/go-githubactions"
|
||||||
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseActionConfig() (*CreatePrConfig, error) {
|
func ParseActionConfig(ctx githubactions.GitHubContext) (*CreatePrConfig, error) {
|
||||||
ctx, err := githubactions.Context()
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
base := githubactions.GetInput("base")
|
base := githubactions.GetInput("base")
|
||||||
if base == "" {
|
if base == "" {
|
||||||
return nil, errors.New("base branch name cannot be empty")
|
return nil, errors.New("base branch name cannot be empty")
|
||||||
|
@ -47,10 +44,10 @@ func ParseActionConfig() (*CreatePrConfig, error) {
|
||||||
var head string
|
var head string
|
||||||
headRaw := githubactions.GetInput("head")
|
headRaw := githubactions.GetInput("head")
|
||||||
if headRaw == "" {
|
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"))
|
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 {
|
} else {
|
||||||
head = headRaw
|
head = headRaw
|
||||||
}
|
}
|
||||||
|
@ -69,17 +66,20 @@ func ParseActionConfig() (*CreatePrConfig, error) {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Starting action CreatePullRequest, 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")
|
token := os.Getenv("GITHUB_TOKEN")
|
||||||
apiUrl := githubactions.GetInput("GITHUB_API_URL")
|
fmt.Printf("Api url is %v\n", ctx.ServerURL)
|
||||||
fmt.Printf("Api url is %v\n", apiUrl)
|
|
||||||
|
|
||||||
config, err := ParseActionConfig()
|
config, err := ParseActionConfig(*ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
githubactions.Fatalf("%v", err.Error())
|
githubactions.Fatalf("%v", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
pr, err := createPullRequest(apiUrl, token, *config)
|
pr, err := createPullRequest(ctx.ServerURL, token, *config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
githubactions.Fatalf("Error while creating pr: %v", err.Error())
|
githubactions.Fatalf("Error while creating pr: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue