Skip to content

Commit

Permalink
Merge pull request #198 from crazy-max/refactor-default-banch
Browse files Browse the repository at this point in the history
don't handle default branch global exp for pr events
  • Loading branch information
crazy-max authored Apr 26, 2022
2 parents 72fe50e + 0a72be4 commit be6d2cc
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 19 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,6 @@ workflow run. Will be empty for a branch reference:
Returns `true` if the branch that triggered the workflow run is the default
one, otherwise `false`.

Will compare against the branch name that triggered the workflow run or the
base ref for a pull request.

#### `{{date '<format>'}}`

Returns the current date rendered by its [moment format](https://momentjs.com/docs/#/displaying/format/).
Expand Down
14 changes: 4 additions & 10 deletions __tests__/meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2327,14 +2327,11 @@ describe('pr', () => {
} as Inputs,
{
main: 'mytag-master',
partial: [
'mytag-defbranch'
],
partial: [],
latest: false
} as Version,
[
'org/app:mytag-master',
'org/app:mytag-defbranch'
'org/app:mytag-master'
],
[
"org.opencontainers.image.title=Hello-World",
Expand All @@ -2359,14 +2356,11 @@ describe('pr', () => {
} as Inputs,
{
main: 'mytag-master',
partial: [
'mytag-defbranch'
],
partial: [],
latest: false
} as Version,
[
'org/app:mytag-master',
'org/app:mytag-defbranch'
'org/app:mytag-master'
],
[
"org.opencontainers.image.title=Hello-World",
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,17 +377,14 @@ export class Meta {
return '';
},
is_default_branch: function () {
let branch = ctx.ref.replace(/^refs\/heads\//g, '');
const branch = ctx.ref.replace(/^refs\/heads\//g, '');
// TODO: "base_ref" is available in the push payload but doesn't always seem to
// return the expected branch when the push tag event occurs. It's also not
// documented in GitHub docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push
// more context: https://github.com/docker/metadata-action/pull/192#discussion_r854673012
// if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {
// branch = ctx.payload.base_ref.replace(/^refs\/heads\//g, '');
// }
if (/^refs\/pull\//.test(ctx.ref) && ctx.payload?.pull_request?.base?.ref != undefined) {
branch = ctx.payload.pull_request.base.ref;
}
if (branch == undefined || branch.length == 0) {
return 'false';
}
Expand Down

0 comments on commit be6d2cc

Please sign in to comment.