GitHub Event Path #542 (#605)

Co-authored-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
Josh Soref 2021-05-03 11:02:26 -04:00 committed by GitHub
parent 806bc4d999
commit cc3e7aeaf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 11 deletions

View File

@ -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" {