-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from actions/willdasilva-fork
Support user-provided base/head refs & non-PR workflows
- Loading branch information
Showing
9 changed files
with
178 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {PullRequestSchema, ConfigurationOptions} from './schemas' | ||
|
||
export function getRefs( | ||
config: ConfigurationOptions, | ||
context: {payload: {pull_request?: unknown}; eventName: string} | ||
): {base: string; head: string} { | ||
let base_ref = config.base_ref | ||
let head_ref = config.head_ref | ||
|
||
// If possible, source default base & head refs from the GitHub event. | ||
// The base/head ref from the config take priority, if provided. | ||
if ( | ||
context.eventName === 'pull_request' || | ||
context.eventName === 'pull_request_target' | ||
) { | ||
const pull_request = PullRequestSchema.parse(context.payload.pull_request) | ||
base_ref = base_ref || pull_request.base.sha | ||
head_ref = head_ref || pull_request.head.sha | ||
} | ||
|
||
if (!base_ref && !head_ref) { | ||
throw new Error( | ||
'Both a base ref and head ref must be provided, either via the `base_ref`/`head_ref` ' + | ||
'config options, or by running a `pull_request`/`pull_request_target` workflow.' | ||
) | ||
} else if (!base_ref) { | ||
throw new Error( | ||
'A base ref must be provided, either via the `base_ref` config option, ' + | ||
'or by running a `pull_request`/`pull_request_target` workflow.' | ||
) | ||
} else if (!head_ref) { | ||
throw new Error( | ||
'A head ref must be provided, either via the `head_ref` config option, ' + | ||
'or by running a `pull_request`/`pull_request_target` workflow.' | ||
) | ||
} | ||
|
||
return { | ||
base: base_ref, | ||
head: head_ref | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters