Fix ref spec for default Git context

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2021-04-26 11:02:09 +02:00
parent c0c3e27be3
commit 19c07384dc
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
3 changed files with 28 additions and 15 deletions

View file

@ -38,9 +38,16 @@ export interface Inputs {
export function defaultContext(): string {
if (!_defaultContext) {
let ref = github.context.ref;
if (github.context.sha && ref && !ref.startsWith('refs/')) {
ref = `refs/heads/${github.context.ref}`;
}
if (github.context.sha && !ref.startsWith(`refs/pull/`)) {
ref = github.context.sha;
}
_defaultContext = `${process.env.GITHUB_SERVER_URL || 'https://github.com'}/${github.context.repo.owner}/${
github.context.repo.repo
}.git#${github.context?.ref?.replace(/^refs\//, '')}`;
}.git#${ref}`;
}
return _defaultContext;
}