Skip to content

Add support for Github release webhook #229

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions scm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const (
ActionMerge
// issue comment
ActionEdit
// release
ActionPublish
ActionUnpublish
ActionPrerelease
ActionRelease
)

// String returns the string representation of Action.
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
164 changes: 164 additions & 0 deletions scm/driver/github/testdata/webhooks/release_created.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
{
"action": "created",
"release": {
"url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/releases/81372309",
"assets_url": "https://github.com/api/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://github.com/api/users/vcalasansh",
"html_url": "https://github.com/vcalasansh",
"followers_url": "https://github.com/api/users/vcalasansh/followers",
"following_url": "https://github.com/api/users/vcalasansh/following{/other_user}",
"gists_url": "https://github.com/api/users/vcalasansh/gists{/gist_id}",
"starred_url": "https://github.com/api/users/vcalasansh/starred{/owner}{/repo}",
"subscriptions_url": "https://github.com/api/users/vcalasansh/subscriptions",
"organizations_url": "https://github.com/api/users/vcalasansh/orgs",
"repos_url": "https://github.com/api/users/vcalasansh/repos",
"events_url": "https://github.com/api/users/vcalasansh/events{/privacy}",
"received_events_url": "https://github.com/api/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://github.com/api/repos/vcalasansh/harness-ngtriggers-test/tarball/v1.0.0",
"zipball_url": "https://github.com/api/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://github.com/api/users/vcalasansh",
"html_url": "https://github.com/vcalasansh",
"followers_url": "https://github.com/api/users/vcalasansh/followers",
"following_url": "https://github.com/api/users/vcalasansh/following{/other_user}",
"gists_url": "https://github.com/api/users/vcalasansh/gists{/gist_id}",
"starred_url": "https://github.com/api/users/vcalasansh/starred{/owner}{/repo}",
"subscriptions_url": "https://github.com/api/users/vcalasansh/subscriptions",
"organizations_url": "https://github.com/api/users/vcalasansh/orgs",
"repos_url": "https://github.com/api/users/vcalasansh/repos",
"events_url": "https://github.com/api/users/vcalasansh/events{/privacy}",
"received_events_url": "https://github.com/api/users/vcalasansh/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/vcalasansh/harness-ngtriggers-test",
"description": null,
"fork": false,
"url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test",
"forks_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/forks",
"keys_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/keys{/key_id}",
"collaborators_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/collaborators{/collaborator}",
"teams_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/teams",
"hooks_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/hooks",
"issue_events_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/issues/events{/number}",
"events_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/events",
"assignees_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/assignees{/user}",
"branches_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/branches{/branch}",
"tags_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/tags",
"blobs_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/git/blobs{/sha}",
"git_tags_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/git/tags{/sha}",
"git_refs_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/git/refs{/sha}",
"trees_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/git/trees{/sha}",
"statuses_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/statuses/{sha}",
"languages_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/languages",
"stargazers_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/stargazers",
"contributors_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/contributors",
"subscribers_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/subscribers",
"subscription_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/subscription",
"commits_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/commits{/sha}",
"git_commits_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/git/commits{/sha}",
"comments_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/comments{/number}",
"issue_comment_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/issues/comments{/number}",
"contents_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/contents/{+path}",
"compare_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/compare/{base}...{head}",
"merges_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/merges",
"archive_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/{archive_format}{/ref}",
"downloads_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/downloads",
"issues_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/issues{/number}",
"pulls_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/pulls{/number}",
"milestones_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/milestones{/number}",
"notifications_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/notifications{?since,all,participating}",
"labels_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/labels{/name}",
"releases_url": "https://github.com/api/repos/vcalasansh/harness-ngtriggers-test/releases{/id}",
"deployments_url": "https://github.com/api/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": "[email protected]: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://github.com/api/users/vcalasansh",
"html_url": "https://github.com/vcalasansh",
"followers_url": "https://github.com/api/users/vcalasansh/followers",
"following_url": "https://github.com/api/users/vcalasansh/following{/other_user}",
"gists_url": "https://github.com/api/users/vcalasansh/gists{/gist_id}",
"starred_url": "https://github.com/api/users/vcalasansh/starred{/owner}{/repo}",
"subscriptions_url": "https://github.com/api/users/vcalasansh/subscriptions",
"organizations_url": "https://github.com/api/users/vcalasansh/orgs",
"repos_url": "https://github.com/api/users/vcalasansh/repos",
"events_url": "https://github.com/api/users/vcalasansh/events{/privacy}",
"received_events_url": "https://github.com/api/users/vcalasansh/received_events",
"type": "User",
"site_admin": false
}
}
34 changes: 34 additions & 0 deletions scm/driver/github/testdata/webhooks/release_created.json.golden
Original file line number Diff line number Diff line change
@@ -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": "[email protected]: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"
}
}
Loading