From 4d088f5efc4c6775c5ea1847086502b0925c6da0 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Sun, 23 May 2021 03:54:23 +0200 Subject: [PATCH] Handle `pull_request_target` event Signed-off-by: CrazyMax --- .../fixtures/event_pull_request_target.env | 25 + .../fixtures/event_pull_request_target.json | 476 ++++++++++++++++++ __tests__/meta.test.ts | 65 +++ dist/index.js | 8 +- src/meta.ts | 9 +- 5 files changed, 579 insertions(+), 4 deletions(-) create mode 100644 __tests__/fixtures/event_pull_request_target.env create mode 100644 __tests__/fixtures/event_pull_request_target.json diff --git a/__tests__/fixtures/event_pull_request_target.env b/__tests__/fixtures/event_pull_request_target.env new file mode 100644 index 0000000..b13a20b --- /dev/null +++ b/__tests__/fixtures/event_pull_request_target.env @@ -0,0 +1,25 @@ +GITHUB_ACTION=crazy-maxghaction-dump-context +GITHUB_ACTIONS=true +GITHUB_ACTION_PATH=/home/runner/work/_actions/crazy-max/ghaction-dump-context/v1 +GITHUB_ACTION_REF= +GITHUB_ACTION_REPOSITORY= +GITHUB_ACTOR=crazy-max +GITHUB_API_URL=https://api.github.com +GITHUB_BASE_REF=master +GITHUB_ENV=/home/runner/work/_temp/_runner_file_commands/set_env_cc4da131-0660-4771-8663-0f96c0fc944f +GITHUB_EVENT_NAME=pull_request_target +GITHUB_EVENT_PATH=./__tests__/fixtures/event_pull_request_target.json +GITHUB_GRAPHQL_URL=https://api.github.com/graphql +GITHUB_HEAD_REF=test-pr-target +GITHUB_JOB=build +GITHUB_PATH=/home/runner/work/_temp/_runner_file_commands/add_path_cc4da131-0660-4771-8663-0f96c0fc944f +GITHUB_REF=refs/heads/master +GITHUB_REPOSITORY=crazy-max/test-docker-action +GITHUB_REPOSITORY_OWNER=crazy-max +GITHUB_RETENTION_DAYS=90 +GITHUB_RUN_ID=867725119 +GITHUB_RUN_NUMBER=12 +GITHUB_SERVER_URL=https://github.com +GITHUB_SHA=f24900bfcfee76d8055c8421a164c7e57ad20e68 +GITHUB_WORKFLOW=push-ghcr +GITHUB_WORKSPACE=/home/runner/work/test-docker-action/test-docker-action diff --git a/__tests__/fixtures/event_pull_request_target.json b/__tests__/fixtures/event_pull_request_target.json new file mode 100644 index 0000000..0ca97c9 --- /dev/null +++ b/__tests__/fixtures/event_pull_request_target.json @@ -0,0 +1,476 @@ +{ + "action": "synchronize", + "after": "57a8fb29acfb3c1e27c66226a8993fb4ef722e26", + "before": "18c4c149d695bdeba42643ef8343a6b8e466970c", + "number": 8, + "pull_request": { + "_links": { + "comments": { + "href": "https://api.github.com/repos/crazy-max/test-docker-action/issues/8/comments" + }, + "commits": { + "href": "https://api.github.com/repos/crazy-max/test-docker-action/pulls/8/commits" + }, + "html": { + "href": "https://github.com/crazy-max/test-docker-action/pull/8" + }, + "issue": { + "href": "https://api.github.com/repos/crazy-max/test-docker-action/issues/8" + }, + "review_comment": { + "href": "https://api.github.com/repos/crazy-max/test-docker-action/pulls/comments{/number}" + }, + "review_comments": { + "href": "https://api.github.com/repos/crazy-max/test-docker-action/pulls/8/comments" + }, + "self": { + "href": "https://api.github.com/repos/crazy-max/test-docker-action/pulls/8" + }, + "statuses": { + "href": "https://api.github.com/repos/crazy-max/test-docker-action/statuses/57a8fb29acfb3c1e27c66226a8993fb4ef722e26" + } + }, + "active_lock_reason": null, + "additions": 1, + "assignee": null, + "assignees": [], + "author_association": "OWNER", + "auto_merge": null, + "base": { + "label": "crazy-max:master", + "ref": "master", + "repo": { + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_squash_merge": true, + "archive_url": "https://api.github.com/repos/crazy-max/test-docker-action/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/crazy-max/test-docker-action/assignees{/user}", + "blobs_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/crazy-max/test-docker-action/branches{/branch}", + "clone_url": "https://github.com/crazy-max/test-docker-action.git", + "collaborators_url": "https://api.github.com/repos/crazy-max/test-docker-action/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/crazy-max/test-docker-action/comments{/number}", + "commits_url": "https://api.github.com/repos/crazy-max/test-docker-action/commits{/sha}", + "compare_url": "https://api.github.com/repos/crazy-max/test-docker-action/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/crazy-max/test-docker-action/contents/{+path}", + "contributors_url": "https://api.github.com/repos/crazy-max/test-docker-action/contributors", + "created_at": "2020-08-07T09:23:00Z", + "default_branch": "master", + "delete_branch_on_merge": false, + "deployments_url": "https://api.github.com/repos/crazy-max/test-docker-action/deployments", + "description": "Test \"Docker\" Actions", + "disabled": false, + "downloads_url": "https://api.github.com/repos/crazy-max/test-docker-action/downloads", + "events_url": "https://api.github.com/repos/crazy-max/test-docker-action/events", + "fork": false, + "forks": 4, + "forks_count": 4, + "forks_url": "https://api.github.com/repos/crazy-max/test-docker-action/forks", + "full_name": "crazy-max/test-docker-action", + "git_commits_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/tags{/sha}", + "git_url": "git://github.com/crazy-max/test-docker-action.git", + "has_downloads": true, + "has_issues": false, + "has_pages": false, + "has_projects": false, + "has_wiki": false, + "homepage": "", + "hooks_url": "https://api.github.com/repos/crazy-max/test-docker-action/hooks", + "html_url": "https://github.com/crazy-max/test-docker-action", + "id": 285789493, + "issue_comment_url": "https://api.github.com/repos/crazy-max/test-docker-action/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/crazy-max/test-docker-action/issues/events{/number}", + "issues_url": "https://api.github.com/repos/crazy-max/test-docker-action/issues{/number}", + "keys_url": "https://api.github.com/repos/crazy-max/test-docker-action/keys{/key_id}", + "labels_url": "https://api.github.com/repos/crazy-max/test-docker-action/labels{/name}", + "language": "Dockerfile", + "languages_url": "https://api.github.com/repos/crazy-max/test-docker-action/languages", + "license": { + "key": "mit", + "name": "MIT License", + "node_id": "MDc6TGljZW5zZTEz", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit" + }, + "merges_url": "https://api.github.com/repos/crazy-max/test-docker-action/merges", + "milestones_url": "https://api.github.com/repos/crazy-max/test-docker-action/milestones{/number}", + "mirror_url": null, + "name": "test-docker-action", + "node_id": "MDEwOlJlcG9zaXRvcnkyODU3ODk0OTM=", + "notifications_url": "https://api.github.com/repos/crazy-max/test-docker-action/notifications{?since,all,participating}", + "open_issues": 4, + "open_issues_count": 4, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/1951866?v=4", + "events_url": "https://api.github.com/users/crazy-max/events{/privacy}", + "followers_url": "https://api.github.com/users/crazy-max/followers", + "following_url": "https://api.github.com/users/crazy-max/following{/other_user}", + "gists_url": "https://api.github.com/users/crazy-max/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/crazy-max", + "id": 1951866, + "login": "crazy-max", + "node_id": "MDQ6VXNlcjE5NTE4NjY=", + "organizations_url": "https://api.github.com/users/crazy-max/orgs", + "received_events_url": "https://api.github.com/users/crazy-max/received_events", + "repos_url": "https://api.github.com/users/crazy-max/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/crazy-max/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/crazy-max/subscriptions", + "type": "User", + "url": "https://api.github.com/users/crazy-max" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/crazy-max/test-docker-action/pulls{/number}", + "pushed_at": "2021-05-23T01:38:41Z", + "releases_url": "https://api.github.com/repos/crazy-max/test-docker-action/releases{/id}", + "size": 137, + "ssh_url": "git@github.com:crazy-max/test-docker-action.git", + "stargazers_count": 3, + "stargazers_url": "https://api.github.com/repos/crazy-max/test-docker-action/stargazers", + "statuses_url": "https://api.github.com/repos/crazy-max/test-docker-action/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/crazy-max/test-docker-action/subscribers", + "subscription_url": "https://api.github.com/repos/crazy-max/test-docker-action/subscription", + "svn_url": "https://github.com/crazy-max/test-docker-action", + "tags_url": "https://api.github.com/repos/crazy-max/test-docker-action/tags", + "teams_url": "https://api.github.com/repos/crazy-max/test-docker-action/teams", + "trees_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/trees{/sha}", + "updated_at": "2021-05-23T01:37:33Z", + "url": "https://api.github.com/repos/crazy-max/test-docker-action", + "watchers": 3, + "watchers_count": 3 + }, + "sha": "2b13c4617af78dc00a6304390682f234a53f3665", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/1951866?v=4", + "events_url": "https://api.github.com/users/crazy-max/events{/privacy}", + "followers_url": "https://api.github.com/users/crazy-max/followers", + "following_url": "https://api.github.com/users/crazy-max/following{/other_user}", + "gists_url": "https://api.github.com/users/crazy-max/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/crazy-max", + "id": 1951866, + "login": "crazy-max", + "node_id": "MDQ6VXNlcjE5NTE4NjY=", + "organizations_url": "https://api.github.com/users/crazy-max/orgs", + "received_events_url": "https://api.github.com/users/crazy-max/received_events", + "repos_url": "https://api.github.com/users/crazy-max/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/crazy-max/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/crazy-max/subscriptions", + "type": "User", + "url": "https://api.github.com/users/crazy-max" + } + }, + "body": "", + "changed_files": 1, + "closed_at": null, + "comments": 0, + "comments_url": "https://api.github.com/repos/crazy-max/test-docker-action/issues/8/comments", + "commits": 2, + "commits_url": "https://api.github.com/repos/crazy-max/test-docker-action/pulls/8/commits", + "created_at": "2021-05-23T01:24:57Z", + "deletions": 1, + "diff_url": "https://github.com/crazy-max/test-docker-action/pull/8.diff", + "draft": false, + "head": { + "label": "crazy-max:test-pr-target", + "ref": "test-pr-target", + "repo": { + "allow_merge_commit": true, + "allow_rebase_merge": true, + "allow_squash_merge": true, + "archive_url": "https://api.github.com/repos/crazy-max/test-docker-action/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/crazy-max/test-docker-action/assignees{/user}", + "blobs_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/crazy-max/test-docker-action/branches{/branch}", + "clone_url": "https://github.com/crazy-max/test-docker-action.git", + "collaborators_url": "https://api.github.com/repos/crazy-max/test-docker-action/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/crazy-max/test-docker-action/comments{/number}", + "commits_url": "https://api.github.com/repos/crazy-max/test-docker-action/commits{/sha}", + "compare_url": "https://api.github.com/repos/crazy-max/test-docker-action/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/crazy-max/test-docker-action/contents/{+path}", + "contributors_url": "https://api.github.com/repos/crazy-max/test-docker-action/contributors", + "created_at": "2020-08-07T09:23:00Z", + "default_branch": "master", + "delete_branch_on_merge": false, + "deployments_url": "https://api.github.com/repos/crazy-max/test-docker-action/deployments", + "description": "Test \"Docker\" Actions", + "disabled": false, + "downloads_url": "https://api.github.com/repos/crazy-max/test-docker-action/downloads", + "events_url": "https://api.github.com/repos/crazy-max/test-docker-action/events", + "fork": false, + "forks": 4, + "forks_count": 4, + "forks_url": "https://api.github.com/repos/crazy-max/test-docker-action/forks", + "full_name": "crazy-max/test-docker-action", + "git_commits_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/tags{/sha}", + "git_url": "git://github.com/crazy-max/test-docker-action.git", + "has_downloads": true, + "has_issues": false, + "has_pages": false, + "has_projects": false, + "has_wiki": false, + "homepage": "", + "hooks_url": "https://api.github.com/repos/crazy-max/test-docker-action/hooks", + "html_url": "https://github.com/crazy-max/test-docker-action", + "id": 285789493, + "issue_comment_url": "https://api.github.com/repos/crazy-max/test-docker-action/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/crazy-max/test-docker-action/issues/events{/number}", + "issues_url": "https://api.github.com/repos/crazy-max/test-docker-action/issues{/number}", + "keys_url": "https://api.github.com/repos/crazy-max/test-docker-action/keys{/key_id}", + "labels_url": "https://api.github.com/repos/crazy-max/test-docker-action/labels{/name}", + "language": "Dockerfile", + "languages_url": "https://api.github.com/repos/crazy-max/test-docker-action/languages", + "license": { + "key": "mit", + "name": "MIT License", + "node_id": "MDc6TGljZW5zZTEz", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit" + }, + "merges_url": "https://api.github.com/repos/crazy-max/test-docker-action/merges", + "milestones_url": "https://api.github.com/repos/crazy-max/test-docker-action/milestones{/number}", + "mirror_url": null, + "name": "test-docker-action", + "node_id": "MDEwOlJlcG9zaXRvcnkyODU3ODk0OTM=", + "notifications_url": "https://api.github.com/repos/crazy-max/test-docker-action/notifications{?since,all,participating}", + "open_issues": 4, + "open_issues_count": 4, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/1951866?v=4", + "events_url": "https://api.github.com/users/crazy-max/events{/privacy}", + "followers_url": "https://api.github.com/users/crazy-max/followers", + "following_url": "https://api.github.com/users/crazy-max/following{/other_user}", + "gists_url": "https://api.github.com/users/crazy-max/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/crazy-max", + "id": 1951866, + "login": "crazy-max", + "node_id": "MDQ6VXNlcjE5NTE4NjY=", + "organizations_url": "https://api.github.com/users/crazy-max/orgs", + "received_events_url": "https://api.github.com/users/crazy-max/received_events", + "repos_url": "https://api.github.com/users/crazy-max/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/crazy-max/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/crazy-max/subscriptions", + "type": "User", + "url": "https://api.github.com/users/crazy-max" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/crazy-max/test-docker-action/pulls{/number}", + "pushed_at": "2021-05-23T01:38:41Z", + "releases_url": "https://api.github.com/repos/crazy-max/test-docker-action/releases{/id}", + "size": 137, + "ssh_url": "git@github.com:crazy-max/test-docker-action.git", + "stargazers_count": 3, + "stargazers_url": "https://api.github.com/repos/crazy-max/test-docker-action/stargazers", + "statuses_url": "https://api.github.com/repos/crazy-max/test-docker-action/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/crazy-max/test-docker-action/subscribers", + "subscription_url": "https://api.github.com/repos/crazy-max/test-docker-action/subscription", + "svn_url": "https://github.com/crazy-max/test-docker-action", + "tags_url": "https://api.github.com/repos/crazy-max/test-docker-action/tags", + "teams_url": "https://api.github.com/repos/crazy-max/test-docker-action/teams", + "trees_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/trees{/sha}", + "updated_at": "2021-05-23T01:37:33Z", + "url": "https://api.github.com/repos/crazy-max/test-docker-action", + "watchers": 3, + "watchers_count": 3 + }, + "sha": "57a8fb29acfb3c1e27c66226a8993fb4ef722e26", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/1951866?v=4", + "events_url": "https://api.github.com/users/crazy-max/events{/privacy}", + "followers_url": "https://api.github.com/users/crazy-max/followers", + "following_url": "https://api.github.com/users/crazy-max/following{/other_user}", + "gists_url": "https://api.github.com/users/crazy-max/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/crazy-max", + "id": 1951866, + "login": "crazy-max", + "node_id": "MDQ6VXNlcjE5NTE4NjY=", + "organizations_url": "https://api.github.com/users/crazy-max/orgs", + "received_events_url": "https://api.github.com/users/crazy-max/received_events", + "repos_url": "https://api.github.com/users/crazy-max/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/crazy-max/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/crazy-max/subscriptions", + "type": "User", + "url": "https://api.github.com/users/crazy-max" + } + }, + "html_url": "https://github.com/crazy-max/test-docker-action/pull/8", + "id": 650710002, + "issue_url": "https://api.github.com/repos/crazy-max/test-docker-action/issues/8", + "labels": [], + "locked": false, + "maintainer_can_modify": false, + "merge_commit_sha": "823b99c3c3cf5421e6ff0514b13a44bf21c7a4f0", + "mergeable": null, + "mergeable_state": "unknown", + "merged": false, + "merged_at": null, + "merged_by": null, + "milestone": null, + "node_id": "MDExOlB1bGxSZXF1ZXN0NjUwNzEwMDAy", + "number": 8, + "patch_url": "https://github.com/crazy-max/test-docker-action/pull/8.patch", + "rebaseable": null, + "requested_reviewers": [], + "requested_teams": [], + "review_comment_url": "https://api.github.com/repos/crazy-max/test-docker-action/pulls/comments{/number}", + "review_comments": 0, + "review_comments_url": "https://api.github.com/repos/crazy-max/test-docker-action/pulls/8/comments", + "state": "open", + "statuses_url": "https://api.github.com/repos/crazy-max/test-docker-action/statuses/57a8fb29acfb3c1e27c66226a8993fb4ef722e26", + "title": "Test PR target", + "updated_at": "2021-05-23T01:38:42Z", + "url": "https://api.github.com/repos/crazy-max/test-docker-action/pulls/8", + "user": { + "avatar_url": "https://avatars.githubusercontent.com/u/1951866?v=4", + "events_url": "https://api.github.com/users/crazy-max/events{/privacy}", + "followers_url": "https://api.github.com/users/crazy-max/followers", + "following_url": "https://api.github.com/users/crazy-max/following{/other_user}", + "gists_url": "https://api.github.com/users/crazy-max/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/crazy-max", + "id": 1951866, + "login": "crazy-max", + "node_id": "MDQ6VXNlcjE5NTE4NjY=", + "organizations_url": "https://api.github.com/users/crazy-max/orgs", + "received_events_url": "https://api.github.com/users/crazy-max/received_events", + "repos_url": "https://api.github.com/users/crazy-max/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/crazy-max/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/crazy-max/subscriptions", + "type": "User", + "url": "https://api.github.com/users/crazy-max" + } + }, + "repository": { + "archive_url": "https://api.github.com/repos/crazy-max/test-docker-action/{archive_format}{/ref}", + "archived": false, + "assignees_url": "https://api.github.com/repos/crazy-max/test-docker-action/assignees{/user}", + "blobs_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/blobs{/sha}", + "branches_url": "https://api.github.com/repos/crazy-max/test-docker-action/branches{/branch}", + "clone_url": "https://github.com/crazy-max/test-docker-action.git", + "collaborators_url": "https://api.github.com/repos/crazy-max/test-docker-action/collaborators{/collaborator}", + "comments_url": "https://api.github.com/repos/crazy-max/test-docker-action/comments{/number}", + "commits_url": "https://api.github.com/repos/crazy-max/test-docker-action/commits{/sha}", + "compare_url": "https://api.github.com/repos/crazy-max/test-docker-action/compare/{base}...{head}", + "contents_url": "https://api.github.com/repos/crazy-max/test-docker-action/contents/{+path}", + "contributors_url": "https://api.github.com/repos/crazy-max/test-docker-action/contributors", + "created_at": "2020-08-07T09:23:00Z", + "default_branch": "master", + "deployments_url": "https://api.github.com/repos/crazy-max/test-docker-action/deployments", + "description": "Test \"Docker\" Actions", + "disabled": false, + "downloads_url": "https://api.github.com/repos/crazy-max/test-docker-action/downloads", + "events_url": "https://api.github.com/repos/crazy-max/test-docker-action/events", + "fork": false, + "forks": 4, + "forks_count": 4, + "forks_url": "https://api.github.com/repos/crazy-max/test-docker-action/forks", + "full_name": "crazy-max/test-docker-action", + "git_commits_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/commits{/sha}", + "git_refs_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/refs{/sha}", + "git_tags_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/tags{/sha}", + "git_url": "git://github.com/crazy-max/test-docker-action.git", + "has_downloads": true, + "has_issues": false, + "has_pages": false, + "has_projects": false, + "has_wiki": false, + "homepage": "", + "hooks_url": "https://api.github.com/repos/crazy-max/test-docker-action/hooks", + "html_url": "https://github.com/crazy-max/test-docker-action", + "id": 285789493, + "issue_comment_url": "https://api.github.com/repos/crazy-max/test-docker-action/issues/comments{/number}", + "issue_events_url": "https://api.github.com/repos/crazy-max/test-docker-action/issues/events{/number}", + "issues_url": "https://api.github.com/repos/crazy-max/test-docker-action/issues{/number}", + "keys_url": "https://api.github.com/repos/crazy-max/test-docker-action/keys{/key_id}", + "labels_url": "https://api.github.com/repos/crazy-max/test-docker-action/labels{/name}", + "language": "Dockerfile", + "languages_url": "https://api.github.com/repos/crazy-max/test-docker-action/languages", + "license": { + "key": "mit", + "name": "MIT License", + "node_id": "MDc6TGljZW5zZTEz", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit" + }, + "merges_url": "https://api.github.com/repos/crazy-max/test-docker-action/merges", + "milestones_url": "https://api.github.com/repos/crazy-max/test-docker-action/milestones{/number}", + "mirror_url": null, + "name": "test-docker-action", + "node_id": "MDEwOlJlcG9zaXRvcnkyODU3ODk0OTM=", + "notifications_url": "https://api.github.com/repos/crazy-max/test-docker-action/notifications{?since,all,participating}", + "open_issues": 4, + "open_issues_count": 4, + "owner": { + "avatar_url": "https://avatars.githubusercontent.com/u/1951866?v=4", + "events_url": "https://api.github.com/users/crazy-max/events{/privacy}", + "followers_url": "https://api.github.com/users/crazy-max/followers", + "following_url": "https://api.github.com/users/crazy-max/following{/other_user}", + "gists_url": "https://api.github.com/users/crazy-max/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/crazy-max", + "id": 1951866, + "login": "crazy-max", + "node_id": "MDQ6VXNlcjE5NTE4NjY=", + "organizations_url": "https://api.github.com/users/crazy-max/orgs", + "received_events_url": "https://api.github.com/users/crazy-max/received_events", + "repos_url": "https://api.github.com/users/crazy-max/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/crazy-max/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/crazy-max/subscriptions", + "type": "User", + "url": "https://api.github.com/users/crazy-max" + }, + "private": false, + "pulls_url": "https://api.github.com/repos/crazy-max/test-docker-action/pulls{/number}", + "pushed_at": "2021-05-23T01:38:41Z", + "releases_url": "https://api.github.com/repos/crazy-max/test-docker-action/releases{/id}", + "size": 137, + "ssh_url": "git@github.com:crazy-max/test-docker-action.git", + "stargazers_count": 3, + "stargazers_url": "https://api.github.com/repos/crazy-max/test-docker-action/stargazers", + "statuses_url": "https://api.github.com/repos/crazy-max/test-docker-action/statuses/{sha}", + "subscribers_url": "https://api.github.com/repos/crazy-max/test-docker-action/subscribers", + "subscription_url": "https://api.github.com/repos/crazy-max/test-docker-action/subscription", + "svn_url": "https://github.com/crazy-max/test-docker-action", + "tags_url": "https://api.github.com/repos/crazy-max/test-docker-action/tags", + "teams_url": "https://api.github.com/repos/crazy-max/test-docker-action/teams", + "trees_url": "https://api.github.com/repos/crazy-max/test-docker-action/git/trees{/sha}", + "updated_at": "2021-05-23T01:37:33Z", + "url": "https://api.github.com/repos/crazy-max/test-docker-action", + "watchers": 3, + "watchers_count": 3 + }, + "sender": { + "avatar_url": "https://avatars.githubusercontent.com/u/1951866?v=4", + "events_url": "https://api.github.com/users/crazy-max/events{/privacy}", + "followers_url": "https://api.github.com/users/crazy-max/followers", + "following_url": "https://api.github.com/users/crazy-max/following{/other_user}", + "gists_url": "https://api.github.com/users/crazy-max/gists{/gist_id}", + "gravatar_id": "", + "html_url": "https://github.com/crazy-max", + "id": 1951866, + "login": "crazy-max", + "node_id": "MDQ6VXNlcjE5NTE4NjY=", + "organizations_url": "https://api.github.com/users/crazy-max/orgs", + "received_events_url": "https://api.github.com/users/crazy-max/received_events", + "repos_url": "https://api.github.com/users/crazy-max/repos", + "site_admin": false, + "starred_url": "https://api.github.com/users/crazy-max/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/crazy-max/subscriptions", + "type": "User", + "url": "https://api.github.com/users/crazy-max" + } +} diff --git a/__tests__/meta.test.ts b/__tests__/meta.test.ts index fb4bc1d..c770f74 100644 --- a/__tests__/meta.test.ts +++ b/__tests__/meta.test.ts @@ -1776,6 +1776,71 @@ describe('pr', () => { "org.opencontainers.image.revision=1e9249f05bfc090e0688b8fb9c1b347586add504", "org.opencontainers.image.licenses=MIT" ] + ], + [ + 'pr07', + 'event_pull_request_target.env', + { + images: ['org/app', 'ghcr.io/user/app'], + tags: [ + `type=sha,priority=2000`, + `type=ref,event=pr` + ] + } as Inputs, + { + main: 'sha-f24900b', + partial: ['pr-8'], + latest: false + } as Version, + [ + 'org/app:sha-f24900b', + 'org/app:pr-8', + 'ghcr.io/user/app:sha-f24900b', + 'ghcr.io/user/app:pr-8' + ], + [ + "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-f24900b", + "org.opencontainers.image.created=2020-01-10T00:30:00.000Z", + "org.opencontainers.image.revision=f24900bfcfee76d8055c8421a164c7e57ad20e68", + "org.opencontainers.image.licenses=MIT" + ] + ], + [ + 'pr08', + 'event_pull_request_target.env', + { + images: ['org/app', 'ghcr.io/user/app'], + tags: [ + `type=ref,event=pr,prefix=` + ], + flavor: [ + `prefix=glo-`, + `suffix=-bal` + ] + } as Inputs, + { + main: '8-bal', + partial: [], + latest: false + } as Version, + [ + 'org/app:8-bal', + 'ghcr.io/user/app:8-bal' + ], + [ + "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=8-bal", + "org.opencontainers.image.created=2020-01-10T00:30:00.000Z", + "org.opencontainers.image.revision=f24900bfcfee76d8055c8421a164c7e57ad20e68", + "org.opencontainers.image.licenses=MIT" + ] ] ])('given %p with %p event', tagsLabelsTest); }); diff --git a/dist/index.js b/dist/index.js index 3887e51..72c97bd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -533,10 +533,14 @@ class Meta { return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? true : this.flavor.latest == 'true'); } procRefPr(version, tag) { - if (!/^refs\/pull\//.test(this.context.ref)) { + let ref = this.context.ref; + if (/pull_request_target/.test(this.context.eventName)) { + ref = `refs/pull/${this.context.payload.number}/merge`; + } + if (!/^refs\/pull\//.test(ref)) { return version; } - const vraw = this.setValue(this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag); + const vraw = this.setValue(ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag); return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true'); } procEdge(version, tag) { diff --git a/src/meta.ts b/src/meta.ts index b608f6e..d0e9201 100644 --- a/src/meta.ts +++ b/src/meta.ts @@ -191,10 +191,15 @@ export class Meta { } private procRefPr(version: Version, tag: tcl.Tag): Version { - if (!/^refs\/pull\//.test(this.context.ref)) { + let ref = this.context.ref; + if (/pull_request_target/.test(this.context.eventName)) { + ref = `refs/pull/${this.context.payload.number}/merge`; + } + if (!/^refs\/pull\//.test(ref)) { return version; } - const vraw = this.setValue(this.context.ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag); + + const vraw = this.setValue(ref.replace(/^refs\/pull\//g, '').replace(/\/merge$/g, ''), tag); return Meta.setVersion(version, vraw, this.flavor.latest == 'auto' ? false : this.flavor.latest == 'true'); }