From 63def73bc307b4a7f4af40849c75145f2aa0ba1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Calasans?= Date: Wed, 9 Nov 2022 21:12:36 -0300 Subject: [PATCH 1/2] Add support for Github release webhook --- scm/const.go | 23 ++- .../testdata/webhooks/release_created.json | 164 ++++++++++++++++++ .../webhooks/release_created.json.golden | 34 ++++ .../testdata/webhooks/release_deleted.json | 164 ++++++++++++++++++ .../webhooks/release_deleted.json.golden | 34 ++++ .../testdata/webhooks/release_edited.json | 164 ++++++++++++++++++ .../webhooks/release_edited.json.golden | 34 ++++ .../webhooks/release_prereleased.json | 164 ++++++++++++++++++ .../webhooks/release_prereleased.json.golden | 34 ++++ .../testdata/webhooks/release_published.json | 164 ++++++++++++++++++ .../webhooks/release_published.json.golden | 34 ++++ .../testdata/webhooks/release_released.json | 164 ++++++++++++++++++ .../webhooks/release_released.json.golden | 34 ++++ .../webhooks/release_unpublished.json | 164 ++++++++++++++++++ .../webhooks/release_unpublished.json.golden | 34 ++++ scm/driver/github/webhook.go | 79 +++++++++ scm/driver/github/webhook_test.go | 45 +++++ scm/release.go | 2 +- scm/webhook.go | 10 ++ 19 files changed, 1542 insertions(+), 3 deletions(-) create mode 100644 scm/driver/github/testdata/webhooks/release_created.json create mode 100644 scm/driver/github/testdata/webhooks/release_created.json.golden create mode 100644 scm/driver/github/testdata/webhooks/release_deleted.json create mode 100644 scm/driver/github/testdata/webhooks/release_deleted.json.golden create mode 100644 scm/driver/github/testdata/webhooks/release_edited.json create mode 100644 scm/driver/github/testdata/webhooks/release_edited.json.golden create mode 100644 scm/driver/github/testdata/webhooks/release_prereleased.json create mode 100644 scm/driver/github/testdata/webhooks/release_prereleased.json.golden create mode 100644 scm/driver/github/testdata/webhooks/release_published.json create mode 100644 scm/driver/github/testdata/webhooks/release_published.json.golden create mode 100644 scm/driver/github/testdata/webhooks/release_released.json create mode 100644 scm/driver/github/testdata/webhooks/release_released.json.golden create mode 100644 scm/driver/github/testdata/webhooks/release_unpublished.json create mode 100644 scm/driver/github/testdata/webhooks/release_unpublished.json.golden diff --git a/scm/const.go b/scm/const.go index 690202cb5..148f73d74 100644 --- a/scm/const.go +++ b/scm/const.go @@ -42,6 +42,11 @@ const ( ActionMerge // issue comment ActionEdit + // release + ActionPublish + ActionUnpublish + ActionPrerelease + ActionRelease ) // String returns the string representation of Action. @@ -67,8 +72,14 @@ func (a Action) String() (s string) { return "synchronized" case ActionMerge: return "merged" - case ActionEdit: - return "edited" + case ActionPublish: + return "published" + case ActionUnpublish: + return "unpublished" + case ActionPrerelease: + return "prereleased" + case ActionRelease: + return "released" default: return } @@ -108,6 +119,14 @@ func (a *Action) UnmarshalJSON(data []byte) error { *a = ActionMerge case "edited": *a = ActionEdit + case "published": + *a = ActionPublish + case "unpublished": + *a = ActionUnpublish + case "prereleased": + *a = ActionPrerelease + case "released": + *a = ActionRelease } return nil } diff --git a/scm/driver/github/testdata/webhooks/release_created.json b/scm/driver/github/testdata/webhooks/release_created.json new file mode 100644 index 000000000..39a6d8d78 --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_created.json @@ -0,0 +1,164 @@ +{ + "action": "created", + "release": { + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309", + "assets_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets", + "upload_url": "https://uploads.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets{?name,label}", + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "id": 81372309, + "author": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "node_id": "RE_kwDOH5utuc4E2aSV", + "tag_name": "v1.0.0", + "target_commitish": "test-branch", + "name": "New release!", + "draft": false, + "prerelease": false, + "created_at": "2022-10-28T13:03:11Z", + "published_at": "2022-10-28T16:36:52Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tarball/v1.0.0", + "zipball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/zipball/v1.0.0", + "body": "New release!" + }, + "repository": { + "id": 530296249, + "node_id": "R_kgDOH5utuQ", + "name": "harness-ngtriggers-test", + "full_name": "vcalasansh/harness-ngtriggers-test", + "private": true, + "owner": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test", + "forks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/forks", + "keys_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/teams", + "hooks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/hooks", + "issue_events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/events{/number}", + "events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/events", + "assignees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/assignees{/user}", + "branches_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/branches{/branch}", + "tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tags", + "blobs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/statuses/{sha}", + "languages_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/languages", + "stargazers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/stargazers", + "contributors_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contributors", + "subscribers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscribers", + "subscription_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscription", + "commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contents/{+path}", + "compare_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/merges", + "archive_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/downloads", + "issues_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues{/number}", + "pulls_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/pulls{/number}", + "milestones_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/milestones{/number}", + "notifications_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/labels{/name}", + "releases_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases{/id}", + "deployments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/deployments", + "created_at": "2022-08-29T16:12:07Z", + "updated_at": "2022-08-29T16:12:07Z", + "pushed_at": "2022-10-28T16:36:27Z", + "git_url": "git://github.com/vcalasansh/harness-ngtriggers-test.git", + "ssh_url": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "clone_url": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "svn_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "homepage": null, + "size": 11, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + + ], + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "test-branch" + }, + "sender": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + } +} diff --git a/scm/driver/github/testdata/webhooks/release_created.json.golden b/scm/driver/github/testdata/webhooks/release_created.json.golden new file mode 100644 index 000000000..b7935c46d --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_created.json.golden @@ -0,0 +1,34 @@ +{ + "Action": "created", + "Release": { + "ID": 81372309, + "Title": "New release!", + "Description": "New release!", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "Tag": "v1.0.0", + "Commitish": "test-branch", + "Draft": false, + "Prerelease": false, + "Created": "2022-10-28T13:03:11Z", + "Published": "2022-10-28T16:36:52Z" + }, + "Repo": { + "ID": "530296249", + "Namespace": "vcalasansh", + "Name": "harness-ngtriggers-test", + "Perm": null, + "Branch": "test-branch", + "Private": true, + "Clone": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "CloneSSH": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Sender": { + "Login": "vcalasansh", + "Name": "", + "Email": "", + "Avatar": "https://avatars.githubusercontent.com/u/109106581?v=4" + } +} diff --git a/scm/driver/github/testdata/webhooks/release_deleted.json b/scm/driver/github/testdata/webhooks/release_deleted.json new file mode 100644 index 000000000..a5ba0fef2 --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_deleted.json @@ -0,0 +1,164 @@ +{ + "action": "deleted", + "release": { + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309", + "assets_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets", + "upload_url": "https://uploads.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets{?name,label}", + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "id": 81372309, + "author": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "node_id": "RE_kwDOH5utuc4E2aSV", + "tag_name": "v1.0.0", + "target_commitish": "test-branch", + "name": "New release!", + "draft": false, + "prerelease": false, + "created_at": "2022-10-28T13:03:11Z", + "published_at": "2022-10-28T16:36:52Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tarball/v1.0.0", + "zipball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/zipball/v1.0.0", + "body": "New release!" + }, + "repository": { + "id": 530296249, + "node_id": "R_kgDOH5utuQ", + "name": "harness-ngtriggers-test", + "full_name": "vcalasansh/harness-ngtriggers-test", + "private": true, + "owner": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test", + "forks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/forks", + "keys_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/teams", + "hooks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/hooks", + "issue_events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/events{/number}", + "events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/events", + "assignees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/assignees{/user}", + "branches_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/branches{/branch}", + "tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tags", + "blobs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/statuses/{sha}", + "languages_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/languages", + "stargazers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/stargazers", + "contributors_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contributors", + "subscribers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscribers", + "subscription_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscription", + "commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contents/{+path}", + "compare_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/merges", + "archive_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/downloads", + "issues_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues{/number}", + "pulls_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/pulls{/number}", + "milestones_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/milestones{/number}", + "notifications_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/labels{/name}", + "releases_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases{/id}", + "deployments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/deployments", + "created_at": "2022-08-29T16:12:07Z", + "updated_at": "2022-08-29T16:12:07Z", + "pushed_at": "2022-10-28T16:36:27Z", + "git_url": "git://github.com/vcalasansh/harness-ngtriggers-test.git", + "ssh_url": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "clone_url": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "svn_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "homepage": null, + "size": 11, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + + ], + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "test-branch" + }, + "sender": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + } +} diff --git a/scm/driver/github/testdata/webhooks/release_deleted.json.golden b/scm/driver/github/testdata/webhooks/release_deleted.json.golden new file mode 100644 index 000000000..30dee53c1 --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_deleted.json.golden @@ -0,0 +1,34 @@ +{ + "Action": "deleted", + "Release": { + "ID": 81372309, + "Title": "New release!", + "Description": "New release!", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "Tag": "v1.0.0", + "Commitish": "test-branch", + "Draft": false, + "Prerelease": false, + "Created": "2022-10-28T13:03:11Z", + "Published": "2022-10-28T16:36:52Z" + }, + "Repo": { + "ID": "530296249", + "Namespace": "vcalasansh", + "Name": "harness-ngtriggers-test", + "Perm": null, + "Branch": "test-branch", + "Private": true, + "Clone": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "CloneSSH": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Sender": { + "Login": "vcalasansh", + "Name": "", + "Email": "", + "Avatar": "https://avatars.githubusercontent.com/u/109106581?v=4" + } +} diff --git a/scm/driver/github/testdata/webhooks/release_edited.json b/scm/driver/github/testdata/webhooks/release_edited.json new file mode 100644 index 000000000..45f7511b4 --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_edited.json @@ -0,0 +1,164 @@ +{ + "action": "edited", + "release": { + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309", + "assets_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets", + "upload_url": "https://uploads.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets{?name,label}", + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "id": 81372309, + "author": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "node_id": "RE_kwDOH5utuc4E2aSV", + "tag_name": "v1.0.0", + "target_commitish": "test-branch", + "name": "New release!", + "draft": false, + "prerelease": false, + "created_at": "2022-10-28T13:03:11Z", + "published_at": "2022-10-28T16:36:52Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tarball/v1.0.0", + "zipball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/zipball/v1.0.0", + "body": "New release!" + }, + "repository": { + "id": 530296249, + "node_id": "R_kgDOH5utuQ", + "name": "harness-ngtriggers-test", + "full_name": "vcalasansh/harness-ngtriggers-test", + "private": true, + "owner": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test", + "forks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/forks", + "keys_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/teams", + "hooks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/hooks", + "issue_events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/events{/number}", + "events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/events", + "assignees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/assignees{/user}", + "branches_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/branches{/branch}", + "tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tags", + "blobs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/statuses/{sha}", + "languages_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/languages", + "stargazers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/stargazers", + "contributors_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contributors", + "subscribers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscribers", + "subscription_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscription", + "commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contents/{+path}", + "compare_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/merges", + "archive_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/downloads", + "issues_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues{/number}", + "pulls_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/pulls{/number}", + "milestones_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/milestones{/number}", + "notifications_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/labels{/name}", + "releases_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases{/id}", + "deployments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/deployments", + "created_at": "2022-08-29T16:12:07Z", + "updated_at": "2022-08-29T16:12:07Z", + "pushed_at": "2022-10-28T16:36:27Z", + "git_url": "git://github.com/vcalasansh/harness-ngtriggers-test.git", + "ssh_url": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "clone_url": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "svn_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "homepage": null, + "size": 11, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + + ], + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "test-branch" + }, + "sender": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + } +} diff --git a/scm/driver/github/testdata/webhooks/release_edited.json.golden b/scm/driver/github/testdata/webhooks/release_edited.json.golden new file mode 100644 index 000000000..0b1e387ad --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_edited.json.golden @@ -0,0 +1,34 @@ +{ + "Action": "edited", + "Release": { + "ID": 81372309, + "Title": "New release!", + "Description": "New release!", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "Tag": "v1.0.0", + "Commitish": "test-branch", + "Draft": false, + "Prerelease": false, + "Created": "2022-10-28T13:03:11Z", + "Published": "2022-10-28T16:36:52Z" + }, + "Repo": { + "ID": "530296249", + "Namespace": "vcalasansh", + "Name": "harness-ngtriggers-test", + "Perm": null, + "Branch": "test-branch", + "Private": true, + "Clone": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "CloneSSH": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Sender": { + "Login": "vcalasansh", + "Name": "", + "Email": "", + "Avatar": "https://avatars.githubusercontent.com/u/109106581?v=4" + } +} diff --git a/scm/driver/github/testdata/webhooks/release_prereleased.json b/scm/driver/github/testdata/webhooks/release_prereleased.json new file mode 100644 index 000000000..94ab938c8 --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_prereleased.json @@ -0,0 +1,164 @@ +{ + "action": "prereleased", + "release": { + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309", + "assets_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets", + "upload_url": "https://uploads.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets{?name,label}", + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "id": 81372309, + "author": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "node_id": "RE_kwDOH5utuc4E2aSV", + "tag_name": "v1.0.0", + "target_commitish": "test-branch", + "name": "New release!", + "draft": false, + "prerelease": false, + "created_at": "2022-10-28T13:03:11Z", + "published_at": "2022-10-28T16:36:52Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tarball/v1.0.0", + "zipball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/zipball/v1.0.0", + "body": "New release!" + }, + "repository": { + "id": 530296249, + "node_id": "R_kgDOH5utuQ", + "name": "harness-ngtriggers-test", + "full_name": "vcalasansh/harness-ngtriggers-test", + "private": true, + "owner": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test", + "forks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/forks", + "keys_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/teams", + "hooks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/hooks", + "issue_events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/events{/number}", + "events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/events", + "assignees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/assignees{/user}", + "branches_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/branches{/branch}", + "tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tags", + "blobs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/statuses/{sha}", + "languages_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/languages", + "stargazers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/stargazers", + "contributors_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contributors", + "subscribers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscribers", + "subscription_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscription", + "commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contents/{+path}", + "compare_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/merges", + "archive_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/downloads", + "issues_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues{/number}", + "pulls_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/pulls{/number}", + "milestones_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/milestones{/number}", + "notifications_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/labels{/name}", + "releases_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases{/id}", + "deployments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/deployments", + "created_at": "2022-08-29T16:12:07Z", + "updated_at": "2022-08-29T16:12:07Z", + "pushed_at": "2022-10-28T16:36:27Z", + "git_url": "git://github.com/vcalasansh/harness-ngtriggers-test.git", + "ssh_url": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "clone_url": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "svn_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "homepage": null, + "size": 11, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + + ], + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "test-branch" + }, + "sender": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + } +} diff --git a/scm/driver/github/testdata/webhooks/release_prereleased.json.golden b/scm/driver/github/testdata/webhooks/release_prereleased.json.golden new file mode 100644 index 000000000..996beb3a6 --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_prereleased.json.golden @@ -0,0 +1,34 @@ +{ + "Action": "prereleased", + "Release": { + "ID": 81372309, + "Title": "New release!", + "Description": "New release!", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "Tag": "v1.0.0", + "Commitish": "test-branch", + "Draft": false, + "Prerelease": false, + "Created": "2022-10-28T13:03:11Z", + "Published": "2022-10-28T16:36:52Z" + }, + "Repo": { + "ID": "530296249", + "Namespace": "vcalasansh", + "Name": "harness-ngtriggers-test", + "Perm": null, + "Branch": "test-branch", + "Private": true, + "Clone": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "CloneSSH": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Sender": { + "Login": "vcalasansh", + "Name": "", + "Email": "", + "Avatar": "https://avatars.githubusercontent.com/u/109106581?v=4" + } +} diff --git a/scm/driver/github/testdata/webhooks/release_published.json b/scm/driver/github/testdata/webhooks/release_published.json new file mode 100644 index 000000000..23b9bad66 --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_published.json @@ -0,0 +1,164 @@ +{ + "action": "published", + "release": { + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309", + "assets_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets", + "upload_url": "https://uploads.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets{?name,label}", + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "id": 81372309, + "author": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "node_id": "RE_kwDOH5utuc4E2aSV", + "tag_name": "v1.0.0", + "target_commitish": "test-branch", + "name": "New release!", + "draft": false, + "prerelease": false, + "created_at": "2022-10-28T13:03:11Z", + "published_at": "2022-10-28T16:36:52Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tarball/v1.0.0", + "zipball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/zipball/v1.0.0", + "body": "New release!" + }, + "repository": { + "id": 530296249, + "node_id": "R_kgDOH5utuQ", + "name": "harness-ngtriggers-test", + "full_name": "vcalasansh/harness-ngtriggers-test", + "private": true, + "owner": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test", + "forks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/forks", + "keys_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/teams", + "hooks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/hooks", + "issue_events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/events{/number}", + "events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/events", + "assignees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/assignees{/user}", + "branches_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/branches{/branch}", + "tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tags", + "blobs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/statuses/{sha}", + "languages_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/languages", + "stargazers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/stargazers", + "contributors_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contributors", + "subscribers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscribers", + "subscription_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscription", + "commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contents/{+path}", + "compare_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/merges", + "archive_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/downloads", + "issues_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues{/number}", + "pulls_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/pulls{/number}", + "milestones_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/milestones{/number}", + "notifications_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/labels{/name}", + "releases_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases{/id}", + "deployments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/deployments", + "created_at": "2022-08-29T16:12:07Z", + "updated_at": "2022-08-29T16:12:07Z", + "pushed_at": "2022-10-28T16:36:27Z", + "git_url": "git://github.com/vcalasansh/harness-ngtriggers-test.git", + "ssh_url": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "clone_url": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "svn_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "homepage": null, + "size": 11, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + + ], + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "test-branch" + }, + "sender": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + } +} diff --git a/scm/driver/github/testdata/webhooks/release_published.json.golden b/scm/driver/github/testdata/webhooks/release_published.json.golden new file mode 100644 index 000000000..a1f070b04 --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_published.json.golden @@ -0,0 +1,34 @@ +{ + "Action": "published", + "Release": { + "ID": 81372309, + "Title": "New release!", + "Description": "New release!", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "Tag": "v1.0.0", + "Commitish": "test-branch", + "Draft": false, + "Prerelease": false, + "Created": "2022-10-28T13:03:11Z", + "Published": "2022-10-28T16:36:52Z" + }, + "Repo": { + "ID": "530296249", + "Namespace": "vcalasansh", + "Name": "harness-ngtriggers-test", + "Perm": null, + "Branch": "test-branch", + "Private": true, + "Clone": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "CloneSSH": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Sender": { + "Login": "vcalasansh", + "Name": "", + "Email": "", + "Avatar": "https://avatars.githubusercontent.com/u/109106581?v=4" + } +} diff --git a/scm/driver/github/testdata/webhooks/release_released.json b/scm/driver/github/testdata/webhooks/release_released.json new file mode 100644 index 000000000..b4af3b457 --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_released.json @@ -0,0 +1,164 @@ +{ + "action": "released", + "release": { + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309", + "assets_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets", + "upload_url": "https://uploads.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets{?name,label}", + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "id": 81372309, + "author": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "node_id": "RE_kwDOH5utuc4E2aSV", + "tag_name": "v1.0.0", + "target_commitish": "test-branch", + "name": "New release!", + "draft": false, + "prerelease": false, + "created_at": "2022-10-28T13:03:11Z", + "published_at": "2022-10-28T16:36:52Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tarball/v1.0.0", + "zipball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/zipball/v1.0.0", + "body": "New release!" + }, + "repository": { + "id": 530296249, + "node_id": "R_kgDOH5utuQ", + "name": "harness-ngtriggers-test", + "full_name": "vcalasansh/harness-ngtriggers-test", + "private": true, + "owner": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test", + "forks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/forks", + "keys_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/teams", + "hooks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/hooks", + "issue_events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/events{/number}", + "events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/events", + "assignees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/assignees{/user}", + "branches_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/branches{/branch}", + "tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tags", + "blobs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/statuses/{sha}", + "languages_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/languages", + "stargazers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/stargazers", + "contributors_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contributors", + "subscribers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscribers", + "subscription_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscription", + "commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contents/{+path}", + "compare_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/merges", + "archive_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/downloads", + "issues_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues{/number}", + "pulls_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/pulls{/number}", + "milestones_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/milestones{/number}", + "notifications_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/labels{/name}", + "releases_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases{/id}", + "deployments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/deployments", + "created_at": "2022-08-29T16:12:07Z", + "updated_at": "2022-08-29T16:12:07Z", + "pushed_at": "2022-10-28T16:36:27Z", + "git_url": "git://github.com/vcalasansh/harness-ngtriggers-test.git", + "ssh_url": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "clone_url": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "svn_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "homepage": null, + "size": 11, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + + ], + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "test-branch" + }, + "sender": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + } +} diff --git a/scm/driver/github/testdata/webhooks/release_released.json.golden b/scm/driver/github/testdata/webhooks/release_released.json.golden new file mode 100644 index 000000000..3e93aa08e --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_released.json.golden @@ -0,0 +1,34 @@ +{ + "Action": "released", + "Release": { + "ID": 81372309, + "Title": "New release!", + "Description": "New release!", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "Tag": "v1.0.0", + "Commitish": "test-branch", + "Draft": false, + "Prerelease": false, + "Created": "2022-10-28T13:03:11Z", + "Published": "2022-10-28T16:36:52Z" + }, + "Repo": { + "ID": "530296249", + "Namespace": "vcalasansh", + "Name": "harness-ngtriggers-test", + "Perm": null, + "Branch": "test-branch", + "Private": true, + "Clone": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "CloneSSH": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Sender": { + "Login": "vcalasansh", + "Name": "", + "Email": "", + "Avatar": "https://avatars.githubusercontent.com/u/109106581?v=4" + } +} diff --git a/scm/driver/github/testdata/webhooks/release_unpublished.json b/scm/driver/github/testdata/webhooks/release_unpublished.json new file mode 100644 index 000000000..6ee38d4e2 --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_unpublished.json @@ -0,0 +1,164 @@ +{ + "action": "unpublished", + "release": { + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309", + "assets_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets", + "upload_url": "https://uploads.github.com/repos/vcalasansh/harness-ngtriggers-test/releases/81372309/assets{?name,label}", + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "id": 81372309, + "author": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "node_id": "RE_kwDOH5utuc4E2aSV", + "tag_name": "v1.0.0", + "target_commitish": "test-branch", + "name": "New release!", + "draft": false, + "prerelease": false, + "created_at": "2022-10-28T13:03:11Z", + "published_at": "2022-10-28T16:36:52Z", + "assets": [ + + ], + "tarball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tarball/v1.0.0", + "zipball_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/zipball/v1.0.0", + "body": "New release!" + }, + "repository": { + "id": 530296249, + "node_id": "R_kgDOH5utuQ", + "name": "harness-ngtriggers-test", + "full_name": "vcalasansh/harness-ngtriggers-test", + "private": true, + "owner": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test", + "forks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/forks", + "keys_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/teams", + "hooks_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/hooks", + "issue_events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/events{/number}", + "events_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/events", + "assignees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/assignees{/user}", + "branches_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/branches{/branch}", + "tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/tags", + "blobs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/statuses/{sha}", + "languages_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/languages", + "stargazers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/stargazers", + "contributors_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contributors", + "subscribers_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscribers", + "subscription_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/subscription", + "commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/contents/{+path}", + "compare_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/merges", + "archive_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/downloads", + "issues_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/issues{/number}", + "pulls_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/pulls{/number}", + "milestones_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/milestones{/number}", + "notifications_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/labels{/name}", + "releases_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/releases{/id}", + "deployments_url": "https://api.github.com/repos/vcalasansh/harness-ngtriggers-test/deployments", + "created_at": "2022-08-29T16:12:07Z", + "updated_at": "2022-08-29T16:12:07Z", + "pushed_at": "2022-10-28T16:36:27Z", + "git_url": "git://github.com/vcalasansh/harness-ngtriggers-test.git", + "ssh_url": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "clone_url": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "svn_url": "https://github.com/vcalasansh/harness-ngtriggers-test", + "homepage": null, + "size": 11, + "stargazers_count": 0, + "watchers_count": 0, + "language": null, + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": null, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [ + + ], + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "test-branch" + }, + "sender": { + "login": "vcalasansh", + "id": 109106581, + "node_id": "U_kgDOBoDVlQ", + "avatar_url": "https://avatars.githubusercontent.com/u/109106581?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/vcalasansh", + "html_url": "https://github.com/vcalasansh", + "followers_url": "https://api.github.com/users/vcalasansh/followers", + "following_url": "https://api.github.com/users/vcalasansh/following{/other_user}", + "gists_url": "https://api.github.com/users/vcalasansh/gists{/gist_id}", + "starred_url": "https://api.github.com/users/vcalasansh/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/vcalasansh/subscriptions", + "organizations_url": "https://api.github.com/users/vcalasansh/orgs", + "repos_url": "https://api.github.com/users/vcalasansh/repos", + "events_url": "https://api.github.com/users/vcalasansh/events{/privacy}", + "received_events_url": "https://api.github.com/users/vcalasansh/received_events", + "type": "User", + "site_admin": false + } +} diff --git a/scm/driver/github/testdata/webhooks/release_unpublished.json.golden b/scm/driver/github/testdata/webhooks/release_unpublished.json.golden new file mode 100644 index 000000000..21ea08eea --- /dev/null +++ b/scm/driver/github/testdata/webhooks/release_unpublished.json.golden @@ -0,0 +1,34 @@ +{ + "Action": "unpublished", + "Release": { + "ID": 81372309, + "Title": "New release!", + "Description": "New release!", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test/releases/tag/v1.0.0", + "Tag": "v1.0.0", + "Commitish": "test-branch", + "Draft": false, + "Prerelease": false, + "Created": "2022-10-28T13:03:11Z", + "Published": "2022-10-28T16:36:52Z" + }, + "Repo": { + "ID": "530296249", + "Namespace": "vcalasansh", + "Name": "harness-ngtriggers-test", + "Perm": null, + "Branch": "test-branch", + "Private": true, + "Clone": "https://github.com/vcalasansh/harness-ngtriggers-test.git", + "CloneSSH": "git@github.com:vcalasansh/harness-ngtriggers-test.git", + "Link": "https://github.com/vcalasansh/harness-ngtriggers-test", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Sender": { + "Login": "vcalasansh", + "Name": "", + "Email": "", + "Avatar": "https://avatars.githubusercontent.com/u/109106581?v=4" + } +} diff --git a/scm/driver/github/webhook.go b/scm/driver/github/webhook.go index e0f6ae77a..57d3ed9ed 100644 --- a/scm/driver/github/webhook.go +++ b/scm/driver/github/webhook.go @@ -46,6 +46,8 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo // case "issues": case "issue_comment": hook, err = s.parseIssueCommentHook(data) + case "release": + hook, err = s.parseReleaseHook(data) default: return nil, scm.ErrUnknownEvent } @@ -178,6 +180,34 @@ func (s *webhookService) parsePullRequestHook(data []byte) (scm.Webhook, error) return dst, nil } +func (s *webhookService) parseReleaseHook(data []byte) (scm.Webhook, error) { + src := new(releaseHook) + err := json.Unmarshal(data, src) + if err != nil { + return nil, err + } + dst := convertReleaseHook(src) + switch src.Action { + case "created": + dst.Action = scm.ActionCreate + case "edited": + dst.Action = scm.ActionEdit + case "deleted": + dst.Action = scm.ActionDelete + case "published": + dst.Action = scm.ActionPublish + case "unpublished": + dst.Action = scm.ActionUnpublish + case "prereleased": + dst.Action = scm.ActionPrerelease + case "released": + dst.Action = scm.ActionRelease + default: + dst.Action = scm.ActionUnknown + } + return dst, nil +} + // // native data structures // @@ -301,6 +331,25 @@ type ( Updated time.Time `json:"updated_at"` } `json:"comment"` } + + // github release webhook payload + releaseHook struct { + Action string `json:"action"` + Release struct { + ID int `json:"id"` + Title string `json:"name"` + Description string `json:"body"` + Link string `json:"html_url,omitempty"` + Tag string `json:"tag_name,omitempty"` + Commitish string `json:"target_commitish,omitempty"` + Draft bool `json:"draft"` + Prerelease bool `json:"prerelease"` + Created time.Time `json:"created_at"` + Published time.Time `json:"published_at"` + } `json:"release"` + Repository repository `json:"repository"` + Sender user `json:"sender"` + } ) // @@ -500,6 +549,36 @@ func convertIssueCommentHook(src *issueCommentHook) *scm.IssueCommentHook { return dst } +func convertReleaseHook(src *releaseHook) *scm.ReleaseHook { + dst := &scm.ReleaseHook{ + Release: scm.Release{ + ID: src.Release.ID, + Title: src.Release.Title, + Description: src.Release.Description, + Link: src.Release.Link, + Tag: src.Release.Tag, + Commitish: src.Release.Commitish, + Draft: src.Release.Draft, + Prerelease: src.Release.Prerelease, + Created: src.Release.Created, + Published: src.Release.Published, + }, + Repo: scm.Repository{ + ID: fmt.Sprint(src.Repository.ID), + Namespace: src.Repository.Owner.Login, + Name: src.Repository.Name, + Branch: src.Repository.DefaultBranch, + Private: src.Repository.Private, + Visibility: convertVisibility(src.Repository.Visibility), + Clone: src.Repository.CloneURL, + CloneSSH: src.Repository.SSHURL, + Link: src.Repository.HTMLURL, + }, + Sender: *convertUser(&src.Sender), + } + return dst +} + // regexp help determine if the named git object is a tag. // this is not meant to be 100% accurate. var tagRE = regexp.MustCompile("^v?(\\d+).(.+)") diff --git a/scm/driver/github/webhook_test.go b/scm/driver/github/webhook_test.go index e54970f0d..7d3621c94 100644 --- a/scm/driver/github/webhook_test.go +++ b/scm/driver/github/webhook_test.go @@ -185,6 +185,51 @@ func TestWebhooks(t *testing.T) { after: "testdata/webhooks/deployment_commit.json.golden", obj: new(scm.DeployHook), }, + // + // release + // + { + event: "release", + before: "testdata/webhooks/release_published.json", + after: "testdata/webhooks/release_published.json.golden", + obj: new(scm.ReleaseHook), + }, + { + event: "release", + before: "testdata/webhooks/release_unpublished.json", + after: "testdata/webhooks/release_unpublished.json.golden", + obj: new(scm.ReleaseHook), + }, + { + event: "release", + before: "testdata/webhooks/release_created.json", + after: "testdata/webhooks/release_created.json.golden", + obj: new(scm.ReleaseHook), + }, + { + event: "release", + before: "testdata/webhooks/release_edited.json", + after: "testdata/webhooks/release_edited.json.golden", + obj: new(scm.ReleaseHook), + }, + { + event: "release", + before: "testdata/webhooks/release_deleted.json", + after: "testdata/webhooks/release_deleted.json.golden", + obj: new(scm.ReleaseHook), + }, + { + event: "release", + before: "testdata/webhooks/release_prereleased.json", + after: "testdata/webhooks/release_prereleased.json.golden", + obj: new(scm.ReleaseHook), + }, + { + event: "release", + before: "testdata/webhooks/release_released.json", + after: "testdata/webhooks/release_released.json.golden", + obj: new(scm.ReleaseHook), + }, } for _, test := range tests { diff --git a/scm/release.go b/scm/release.go index 68d6a058d..baef995ba 100644 --- a/scm/release.go +++ b/scm/release.go @@ -9,7 +9,7 @@ type ( // Release the release Release struct { ID int - Title string + Title string Description string Link string Tag string diff --git a/scm/webhook.go b/scm/webhook.go index b36c25feb..65af29a49 100644 --- a/scm/webhook.go +++ b/scm/webhook.go @@ -115,6 +115,15 @@ type ( Task string } + // ReleaseHook represents a release event. This is + // currently a GitHub-specific event type. + ReleaseHook struct { + Action Action + Release Release + Repo Repository + Sender User + } + // SecretFunc provides the Webhook parser with the // secret key used to validate webhook authenticity. SecretFunc func(webhook Webhook) (string, error) @@ -140,3 +149,4 @@ func (h *IssueCommentHook) Repository() Repository { return h.Repo } func (h *PullRequestHook) Repository() Repository { return h.Repo } func (h *PullRequestCommentHook) Repository() Repository { return h.Repo } func (h *ReviewCommentHook) Repository() Repository { return h.Repo } +func (h *ReleaseHook) Repository() Repository { return h.Repo } From 046c931f3ee547c9e3c334ac78e58023674542e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Calasans?= Date: Wed, 9 Nov 2022 22:04:53 -0300 Subject: [PATCH 2/2] Fix code format --- scm/const.go | 12 ++++++------ scm/release.go | 2 +- scm/webhook.go | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scm/const.go b/scm/const.go index 148f73d74..84fb47151 100644 --- a/scm/const.go +++ b/scm/const.go @@ -42,11 +42,11 @@ const ( ActionMerge // issue comment ActionEdit - // release - ActionPublish - ActionUnpublish - ActionPrerelease - ActionRelease + // release + ActionPublish + ActionUnpublish + ActionPrerelease + ActionRelease ) // String returns the string representation of Action. @@ -74,7 +74,7 @@ func (a Action) String() (s string) { return "merged" case ActionPublish: return "published" - case ActionUnpublish: + case ActionUnpublish: return "unpublished" case ActionPrerelease: return "prereleased" diff --git a/scm/release.go b/scm/release.go index baef995ba..68d6a058d 100644 --- a/scm/release.go +++ b/scm/release.go @@ -9,7 +9,7 @@ type ( // Release the release Release struct { ID int - Title string + Title string Description string Link string Tag string diff --git a/scm/webhook.go b/scm/webhook.go index 65af29a49..f6875f6f2 100644 --- a/scm/webhook.go +++ b/scm/webhook.go @@ -119,9 +119,9 @@ type ( // currently a GitHub-specific event type. ReleaseHook struct { Action Action - Release Release - Repo Repository - Sender User + Release Release + Repo Repository + Sender User } // SecretFunc provides the Webhook parser with the