Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set associated head sha on pull request event #234

Merged
merged 1 commit into from Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 26 additions & 26 deletions __tests__/meta.test.ts
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
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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to check that substring “pull_request” appears anywhere in the event name. Maybe the intention was to check if the name starts with a certain substring? Or matches exactly if that’s the entire event name?

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