Skip to content

Commit

Permalink
🐛 Fix GitHub branch extraction for pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Jan 22, 2024
1 parent c6398e9 commit 1326824
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ func Test_ExtractEnvironmentVariables(t *testing.T) {
revisionExpected: revisionExpected,
branchExpected: branchExpected,
},
{
ci: "GitHub pull request",
variables: map[string]string{
"GITHUB_SERVER_URL": "https://github.jetbrains.com",
"GITHUB_REPOSITORY": "sa/entrypoint",
"GITHUB_RUN_ID": "123456789",
"GITHUB_SHA": revisionExpected,
"GITHUB_HEAD_REF": branchExpected,
"GITHUB_REF": "refs/pull/123/merge",
},
envExpected: fmt.Sprintf("github-actions:%s", Version),
jobUrlExpected: "https://github.jetbrains.com/sa/entrypoint/actions/runs/123456789",
remoteUrlExpected: "https://github.jetbrains.com/sa/entrypoint.git",
repoUrlExpected: "https://github.jetbrains.com/sa/entrypoint",
revisionExpected: revisionExpected,
branchExpected: branchExpected,
},
{
ci: "CircleCI",
variables: map[string]string{
Expand Down
3 changes: 3 additions & 0 deletions core/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ func validateBranch(branch string, env string) string {
if branch == "" {
if env == "github-actions" {
branch = os.Getenv("GITHUB_REF")
if strings.Contains(branch, "/pull/") {
branch = os.Getenv("GITHUB_HEAD_REF")
}
} else if env == "azure-pipelines" {
branch = os.Getenv("BUILD_SOURCEBRANCHNAME")
} else if env == "jenkins" {
Expand Down

0 comments on commit 1326824

Please sign in to comment.