Skip to content

Commit

Permalink
Add support for Github release webhook (#229)
Browse files Browse the repository at this point in the history
* Add support for Github release webhook
  • Loading branch information
vcalasansh authored Nov 16, 2022
1 parent b29a0d2 commit 1949a8e
Show file tree
Hide file tree
Showing 18 changed files with 1,541 additions and 2 deletions.
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://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
}
}
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": "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"
}
}
Loading

0 comments on commit 1949a8e

Please sign in to comment.