From cc3e7aeaf21823f602901cc40836477977bdb3bc Mon Sep 17 00:00:00 2001 From: Josh Soref Date: Mon, 3 May 2021 11:02:26 -0400 Subject: [PATCH] GitHub Event Path #542 (#605) Co-authored-by: Casey Lee --- pkg/runner/run_context.go | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 96335fb..94af75f 100755 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -495,13 +495,6 @@ func (rc *RunContext) getGithubContext() *githubContext { ghc.Sha = sha } - ref, err := common.FindGitRef(repoPath) - if err != nil { - log.Warningf("unable to get git ref: %v", err) - } else { - log.Debugf("using github ref: %s", ref) - ghc.Ref = ref - } if rc.EventJSON != "" { err = json.Unmarshal([]byte(rc.EventJSON), &ghc.Event) if err != nil { @@ -509,11 +502,25 @@ func (rc *RunContext) getGithubContext() *githubContext { } } - // set the branch in the event data - if rc.Config.DefaultBranch != "" { - ghc.Event = withDefaultBranch(rc.Config.DefaultBranch, ghc.Event) + maybeRef := nestedMapLookup(ghc.Event, ghc.EventName, "ref") + if maybeRef != nil { + log.Debugf("using github ref from event: %s", maybeRef) + ghc.Ref = maybeRef.(string) } else { - ghc.Event = withDefaultBranch("master", ghc.Event) + ref, err := common.FindGitRef(repoPath) + if err != nil { + log.Warningf("unable to get git ref: %v", err) + } else { + log.Debugf("using github ref: %s", ref) + ghc.Ref = ref + } + + // set the branch in the event data + if rc.Config.DefaultBranch != "" { + ghc.Event = withDefaultBranch(rc.Config.DefaultBranch, ghc.Event) + } else { + ghc.Event = withDefaultBranch("master", ghc.Event) + } } if ghc.EventName == "pull_request" {