mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-11 17:50:58 +00:00
fix: align github.ref to GitHub Action (#1362)
* fix: align github.ref to GitHub Action The `github.ref` value should be `refs/heads/branch` in most cases. There are a few exceptions handled by the code. This change prefixes the default case with `refs/heads` and adds tests for this and the excpetional cases. * fix: correct existing assertions
This commit is contained in:
parent
b5fe49c062
commit
9e5ca4d0a6
4 changed files with 52 additions and 7 deletions
|
@ -95,7 +95,7 @@ func (ghc *GithubContext) SetRefAndSha(ctx context.Context, defaultBranch string
|
|||
// https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads
|
||||
switch ghc.EventName {
|
||||
case "pull_request_target":
|
||||
ghc.Ref = ghc.BaseRef
|
||||
ghc.Ref = fmt.Sprintf("refs/heads/%s", ghc.BaseRef)
|
||||
ghc.Sha = asString(nestedMapLookup(ghc.Event, "pull_request", "base", "sha"))
|
||||
case "pull_request", "pull_request_review", "pull_request_review_comment":
|
||||
ghc.Ref = fmt.Sprintf("refs/pull/%.0f/merge", ghc.Event["number"])
|
||||
|
@ -110,7 +110,10 @@ func (ghc *GithubContext) SetRefAndSha(ctx context.Context, defaultBranch string
|
|||
ghc.Sha = asString(ghc.Event["after"])
|
||||
}
|
||||
default:
|
||||
ghc.Ref = asString(nestedMapLookup(ghc.Event, "repository", "default_branch"))
|
||||
defaultBranch := asString(nestedMapLookup(ghc.Event, "repository", "default_branch"))
|
||||
if defaultBranch != "" {
|
||||
ghc.Ref = fmt.Sprintf("refs/heads/%s", defaultBranch)
|
||||
}
|
||||
}
|
||||
|
||||
if ghc.Ref == "" {
|
||||
|
@ -130,7 +133,7 @@ func (ghc *GithubContext) SetRefAndSha(ctx context.Context, defaultBranch string
|
|||
}
|
||||
|
||||
if ghc.Ref == "" {
|
||||
ghc.Ref = asString(nestedMapLookup(ghc.Event, "repository", "default_branch"))
|
||||
ghc.Ref = fmt.Sprintf("refs/heads/%s", asString(nestedMapLookup(ghc.Event, "repository", "default_branch")))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue