Skip to content

Commit

Permalink
set associated head sha on pull request event
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Oct 7, 2022
1 parent 8671a4f commit 61ddee1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
52 changes: 26 additions & 26 deletions __tests__/meta.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,7 @@ describe('pr', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=pr-15",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
"org.opencontainers.image.licenses=MIT"
]
],
Expand All @@ -2117,7 +2117,7 @@ describe('pr', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=pr-15",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
"org.opencontainers.image.licenses=MIT"
]
],
Expand All @@ -2133,14 +2133,14 @@ describe('pr', () => {
} as Inputs,
{
main: 'pr-15',
partial: ['sha-a9c8c58'],
partial: ['sha-3370e22'],
latest: false
} as Version,
[
'org/app:pr-15',
'org/app:sha-a9c8c58',
'org/app:sha-3370e22',
'ghcr.io/user/app:pr-15',
'ghcr.io/user/app:sha-a9c8c58'
'ghcr.io/user/app:sha-3370e22'
],
[
"org.opencontainers.image.title=Hello-World",
Expand All @@ -2149,7 +2149,7 @@ describe('pr', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=pr-15",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
"org.opencontainers.image.licenses=MIT"
]
],
Expand All @@ -2164,24 +2164,24 @@ describe('pr', () => {
]
} as Inputs,
{
main: 'sha-a9c8c58',
main: 'sha-3370e22',
partial: ['pr-15'],
latest: false
} as Version,
[
'org/app:sha-a9c8c58',
'org/app:sha-3370e22',
'org/app:pr-15',
'ghcr.io/user/app:sha-a9c8c58',
'ghcr.io/user/app:sha-3370e22',
'ghcr.io/user/app:pr-15'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=sha-a9c8c58",
"org.opencontainers.image.version=sha-3370e22",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
"org.opencontainers.image.licenses=MIT"
]
],
Expand Down Expand Up @@ -2214,7 +2214,7 @@ describe('pr', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=pr-15-bal",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
"org.opencontainers.image.licenses=MIT"
]
],
Expand Down Expand Up @@ -2247,7 +2247,7 @@ describe('pr', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=15-bal",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
"org.opencontainers.image.licenses=MIT"
]
],
Expand All @@ -2262,24 +2262,24 @@ describe('pr', () => {
]
} as Inputs,
{
main: 'sha-2665741',
main: 'sha-3370e22',
partial: ['pr-15'],
latest: false
} as Version,
[
'org/app:sha-2665741',
'org/app:sha-3370e22',
'org/app:pr-15',
'ghcr.io/user/app:sha-2665741',
'ghcr.io/user/app:sha-3370e22',
'ghcr.io/user/app:pr-15'
],
[
"org.opencontainers.image.title=Hello-World",
"org.opencontainers.image.description=This your first repo!",
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=sha-2665741",
"org.opencontainers.image.version=sha-3370e22",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=266574110acf203503badf966df2ea24b5d732d7",
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
"org.opencontainers.image.licenses=MIT"
]
],
Expand Down Expand Up @@ -2312,7 +2312,7 @@ describe('pr', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=15-bal",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=266574110acf203503badf966df2ea24b5d732d7",
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
"org.opencontainers.image.licenses=MIT"
]
],
Expand All @@ -2332,15 +2332,15 @@ describe('pr', () => {
{
main: 'pr-15',
partial: [
'sha-2665741',
'sha-266574110acf203503badf966df2ea24b5d732d7'
'sha-3370e22',
'sha-3370e228f2209994d57af4427fe64e71bb79ac96'
],
latest: false
} as Version,
[
'org/app:pr-15',
'org/app:sha-2665741',
'org/app:sha-266574110acf203503badf966df2ea24b5d732d7'
'org/app:sha-3370e22',
'org/app:sha-3370e228f2209994d57af4427fe64e71bb79ac96'
],
[
"org.opencontainers.image.title=Hello-World",
Expand All @@ -2349,7 +2349,7 @@ describe('pr', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=pr-15",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=266574110acf203503badf966df2ea24b5d732d7",
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
"org.opencontainers.image.licenses=MIT"
]
],
Expand Down Expand Up @@ -2378,7 +2378,7 @@ describe('pr', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=mytag-master",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=266574110acf203503badf966df2ea24b5d732d7",
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
"org.opencontainers.image.licenses=MIT"
]
],
Expand Down Expand Up @@ -2407,7 +2407,7 @@ describe('pr', () => {
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
"org.opencontainers.image.version=mytag-master",
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
"org.opencontainers.image.licenses=MIT"
]
],
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.

8 changes: 6 additions & 2 deletions src/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export class Meta {
context.ref = `refs/pull/${context.payload.number}/merge`;
}

if ((/pull_request/.test(context.eventName) || /pull_request_target/.test(context.eventName)) && context.payload?.pull_request?.head?.sha != undefined) {
context.sha = context.payload.pull_request.head.sha;
}

this.inputs = inputs;
this.context = context;
this.repo = repo;
Expand Down Expand Up @@ -301,7 +305,7 @@ export class Meta {

let val = this.context.sha;
if (tag.attrs['format'] === tcl.ShaFormat.Short) {
val = this.context.sha.substr(0, 7);
val = this.context.sha.substring(0, 7);
}

const vraw = this.setValue(val, tag);
Expand Down Expand Up @@ -367,7 +371,7 @@ export class Meta {
return ctx.ref.replace(/^refs\/tags\//g, '');
},
sha: function () {
return ctx.sha.substr(0, 7);
return ctx.sha.substring(0, 7);
},
base_ref: function () {
if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {
Expand Down

0 comments on commit 61ddee1

Please sign in to comment.