From ecd89e9df9551a0801878925729f43afca06032a Mon Sep 17 00:00:00 2001 From: ianedwards Date: Wed, 27 Sep 2023 16:58:39 -0400 Subject: [PATCH] get correct branch name for deployment target (#3653) --- cli/cmd/v2/apply.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cli/cmd/v2/apply.go b/cli/cmd/v2/apply.go index f5835cf63f..26837a52d7 100644 --- a/cli/cmd/v2/apply.go +++ b/cli/cmd/v2/apply.go @@ -389,7 +389,12 @@ func deploymentTargetFromConfig(ctx context.Context, client api.Client, projectI if previewApply { var branchName string - if os.Getenv("GITHUB_REF_NAME") != "" { + + // branch name is set to different values in the GH env, depending on whether or not the workflow is triggered by a PR + // issue is being tracked here: https://github.com/github/docs/issues/15319 + if os.Getenv("GITHUB_HEAD_REF") != "" { + branchName = os.Getenv("GITHUB_HEAD_REF") + } else if os.Getenv("GITHUB_REF_NAME") != "" { branchName = os.Getenv("GITHUB_REF_NAME") } else if branch, err := git.CurrentBranch(); err == nil { branchName = branch