Created
December 1, 2015 21:51
-
-
Save ianbattersby/340e343ed65f84f7067b to your computer and use it in GitHub Desktop.
Example of a more complicated EventStore projection using GitHub API data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Push an IssuesEvent into ES (with known issue number) | |
curl -i -L -d @example-issues-event.json http://127.0.0.1:2113/streams/github-IssuesEvent -H "Content-Type:application/json" -H "ES-EventType:IssuesEvent" -u "admin:changeit" | |
# Push a PushEvent into ES (has a commit description with required match) | |
curl -i -L -d @example-push-event.json http://127.0.0.1:2113/streams/github-PushEvent -H "Content-Type:application/json" -H "ES-EventType:PushEvent" -u "admin:changeit" | |
# Push a DeploymentEvent into ES (has a description with required match) | |
curl -i -L -d @example-DeploymentEvent-desc.json http://127.0.0.1:2113/streams/github-DeploymentEvent -H "Content-Type:application/json" -H "ES-EventType:DeploymentEvent" -u "admin:changeit" | |
# Push a DeploymentEvent into eS (does not have description with match, relies on date precedence) | |
curl -i -L -d @example-DeploymentEvent-nodesc.json http://127.0.0.1:2113/streams/github-DeploymentEvent -H "Content-Type:application/json" -H "ES-EventType:DeploymentEvent" -u "admin:changeit" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"deployment": { | |
"url": "https://api.github.com/repos/ianbattersby/public-repo/deployments/710692", | |
"id": 9910692, | |
"sha": "9049f1265b7d61be4a8904a9a27120d2064dab3b", | |
"ref": "master", | |
"task": "deploy", | |
"payload": { | |
}, | |
"environment": "production", | |
"description": "This deployment fixes #223.", | |
"creator": { | |
"login": "ianbattersby", | |
"id": 6752317, | |
"avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", | |
"gravatar_id": "", | |
"url": "https://api.github.com/users/ianbattersby", | |
"html_url": "https://github.com/ianbattersby", | |
"followers_url": "https://api.github.com/users/ianbattersby/followers", | |
"following_url": "https://api.github.com/users/ianbattersby/following{/other_user}", | |
"gists_url": "https://api.github.com/users/ianbattersby/gists{/gist_id}", | |
"starred_url": "https://api.github.com/users/ianbattersby/starred{/owner}{/repo}", | |
"subscriptions_url": "https://api.github.com/users/ianbattersby/subscriptions", | |
"organizations_url": "https://api.github.com/users/ianbattersby/orgs", | |
"repos_url": "https://api.github.com/users/ianbattersby/repos", | |
"events_url": "https://api.github.com/users/ianbattersby/events{/privacy}", | |
"received_events_url": "https://api.github.com/users/ianbattersby/received_events", | |
"type": "User", | |
"site_admin": false | |
}, | |
"created_at": "2015-11-28T23:40:38Z", | |
"updated_at": "2015-11-28T23:40:38Z", | |
"statuses_url": "https://api.github.com/repos/ianbattersby/public-repo/deployments/710692/statuses", | |
"repository_url": "https://api.github.com/repos/ianbattersby/public-repo" | |
}, | |
"repository": { | |
"id": 47172074, | |
"name": "public-repo", | |
"full_name": "ianbattersby/public-repo", | |
"owner": { | |
"login": "ianbattersby", | |
"id": 6752317, | |
"avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", | |
"gravatar_id": "", | |
"url": "https://api.github.com/users/ianbattersby", | |
"html_url": "https://github.com/ianbattersby", | |
"followers_url": "https://api.github.com/users/ianbattersby/followers", | |
"following_url": "https://api.github.com/users/ianbattersby/following{/other_user}", | |
"gists_url": "https://api.github.com/users/ianbattersby/gists{/gist_id}", | |
"starred_url": "https://api.github.com/users/ianbattersby/starred{/owner}{/repo}", | |
"subscriptions_url": "https://api.github.com/users/ianbattersby/subscriptions", | |
"organizations_url": "https://api.github.com/users/ianbattersby/orgs", | |
"repos_url": "https://api.github.com/users/ianbattersby/repos", | |
"events_url": "https://api.github.com/users/ianbattersby/events{/privacy}", | |
"received_events_url": "https://api.github.com/users/ianbattersby/received_events", | |
"type": "User", | |
"site_admin": false | |
}, | |
"private": false, | |
"html_url": "https://github.com/ianbattersby/public-repo", | |
"description": "", | |
"fork": false, | |
"url": "https://api.github.com/repos/ianbattersby/public-repo", | |
"forks_url": "https://api.github.com/repos/ianbattersby/public-repo/forks", | |
"keys_url": "https://api.github.com/repos/ianbattersby/public-repo/keys{/key_id}", | |
"collaborators_url": "https://api.github.com/repos/ianbattersby/public-repo/collaborators{/collaborator}", | |
"teams_url": "https://api.github.com/repos/ianbattersby/public-repo/teams", | |
"hooks_url": "https://api.github.com/repos/ianbattersby/public-repo/hooks", | |
"issue_events_url": "https://api.github.com/repos/ianbattersby/public-repo/issues/events{/number}", | |
"events_url": "https://api.github.com/repos/ianbattersby/public-repo/events", | |
"assignees_url": "https://api.github.com/repos/ianbattersby/public-repo/assignees{/user}", | |
"branches_url": "https://api.github.com/repos/ianbattersby/public-repo/branches{/branch}", | |
"tags_url": "https://api.github.com/repos/ianbattersby/public-repo/tags", | |
"blobs_url": "https://api.github.com/repos/ianbattersby/public-repo/git/blobs{/sha}", | |
"git_tags_url": "https://api.github.com/repos/ianbattersby/public-repo/git/tags{/sha}", | |
"git_refs_url": "https://api.github.com/repos/ianbattersby/public-repo/git/refs{/sha}", | |
"trees_url": "https://api.github.com/repos/ianbattersby/public-repo/git/trees{/sha}", | |
"statuses_url": "https://api.github.com/repos/ianbattersby/public-repo/statuses/{sha}", | |
"languages_url": "https://api.github.com/repos/ianbattersby/public-repo/languages", | |
"stargazers_url": "https://api.github.com/repos/ianbattersby/public-repo/stargazers", | |
"contributors_url": "https://api.github.com/repos/ianbattersby/public-repo/contributors", | |
"subscribers_url": "https://api.github.com/repos/ianbattersby/public-repo/subscribers", | |
"subscription_url": "https://api.github.com/repos/ianbattersby/public-repo/subscription", | |
"commits_url": "https://api.github.com/repos/ianbattersby/public-repo/commits{/sha}", | |
"git_commits_url": "https://api.github.com/repos/ianbattersby/public-repo/git/commits{/sha}", | |
"comments_url": "https://api.github.com/repos/ianbattersby/public-repo/comments{/number}", | |
"issue_comment_url": "https://api.github.com/repos/ianbattersby/public-repo/issues/comments{/number}", | |
"contents_url": "https://api.github.com/repos/ianbattersby/public-repo/contents/{+path}", | |
"compare_url": "https://api.github.com/repos/ianbattersby/public-repo/compare/{base}...{head}", | |
"merges_url": "https://api.github.com/repos/ianbattersby/public-repo/merges", | |
"archive_url": "https://api.github.com/repos/ianbattersby/public-repo/{archive_format}{/ref}", | |
"downloads_url": "https://api.github.com/repos/ianbattersby/public-repo/downloads", | |
"issues_url": "https://api.github.com/repos/ianbattersby/public-repo/issues{/number}", | |
"pulls_url": "https://api.github.com/repos/ianbattersby/public-repo/pulls{/number}", | |
"milestones_url": "https://api.github.com/repos/ianbattersby/public-repo/milestones{/number}", | |
"notifications_url": "https://api.github.com/repos/ianbattersby/public-repo/notifications{?since,all,participating}", | |
"labels_url": "https://api.github.com/repos/ianbattersby/public-repo/labels{/name}", | |
"releases_url": "https://api.github.com/repos/ianbattersby/public-repo/releases{/id}", | |
"created_at": "2015-05-05T23:40:12Z", | |
"updated_at": "2015-05-05T23:40:30Z", | |
"pushed_at": "2015-05-05T23:40:38Z", | |
"git_url": "git://github.com/ianbattersby/public-repo.git", | |
"ssh_url": "[email protected]:ianbattersby/public-repo.git", | |
"clone_url": "https://github.com/ianbattersby/public-repo.git", | |
"svn_url": "https://github.com/ianbattersby/public-repo", | |
"homepage": null, | |
"size": 0, | |
"stargazers_count": 0, | |
"watchers_count": 0, | |
"language": null, | |
"has_issues": true, | |
"has_downloads": true, | |
"has_wiki": true, | |
"has_pages": true, | |
"forks_count": 0, | |
"mirror_url": null, | |
"open_issues_count": 2, | |
"forks": 0, | |
"open_issues": 2, | |
"watchers": 0, | |
"default_branch": "master" | |
}, | |
"sender": { | |
"login": "ianbattersby", | |
"id": 6752317, | |
"avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", | |
"gravatar_id": "", | |
"url": "https://api.github.com/users/ianbattersby", | |
"html_url": "https://github.com/ianbattersby", | |
"followers_url": "https://api.github.com/users/ianbattersby/followers", | |
"following_url": "https://api.github.com/users/ianbattersby/following{/other_user}", | |
"gists_url": "https://api.github.com/users/ianbattersby/gists{/gist_id}", | |
"starred_url": "https://api.github.com/users/ianbattersby/starred{/owner}{/repo}", | |
"subscriptions_url": "https://api.github.com/users/ianbattersby/subscriptions", | |
"organizations_url": "https://api.github.com/users/ianbattersby/orgs", | |
"repos_url": "https://api.github.com/users/ianbattersby/repos", | |
"events_url": "https://api.github.com/users/ianbattersby/events{/privacy}", | |
"received_events_url": "https://api.github.com/users/ianbattersby/received_events", | |
"type": "User", | |
"site_admin": false | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"deployment": { | |
"url": "https://api.github.com/repos/ianbattersby/public-repo/deployments/710692", | |
"id": 9910692, | |
"sha": "9049f1265b7d61be4a8904a9a27120d2064dab3b", | |
"ref": "master", | |
"task": "deploy", | |
"payload": { | |
}, | |
"environment": "production", | |
"description": null, | |
"creator": { | |
"login": "ianbattersby", | |
"id": 6752317, | |
"avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", | |
"gravatar_id": "", | |
"url": "https://api.github.com/users/ianbattersby", | |
"html_url": "https://github.com/ianbattersby", | |
"followers_url": "https://api.github.com/users/ianbattersby/followers", | |
"following_url": "https://api.github.com/users/ianbattersby/following{/other_user}", | |
"gists_url": "https://api.github.com/users/ianbattersby/gists{/gist_id}", | |
"starred_url": "https://api.github.com/users/ianbattersby/starred{/owner}{/repo}", | |
"subscriptions_url": "https://api.github.com/users/ianbattersby/subscriptions", | |
"organizations_url": "https://api.github.com/users/ianbattersby/orgs", | |
"repos_url": "https://api.github.com/users/ianbattersby/repos", | |
"events_url": "https://api.github.com/users/ianbattersby/events{/privacy}", | |
"received_events_url": "https://api.github.com/users/ianbattersby/received_events", | |
"type": "User", | |
"site_admin": false | |
}, | |
"created_at": "2015-11-28T23:40:38Z", | |
"updated_at": "2015-11-28T23:40:38Z", | |
"statuses_url": "https://api.github.com/repos/ianbattersby/public-repo/deployments/710692/statuses", | |
"repository_url": "https://api.github.com/repos/ianbattersby/public-repo" | |
}, | |
"repository": { | |
"id": 47172074, | |
"name": "public-repo", | |
"full_name": "ianbattersby/public-repo", | |
"owner": { | |
"login": "ianbattersby", | |
"id": 6752317, | |
"avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", | |
"gravatar_id": "", | |
"url": "https://api.github.com/users/ianbattersby", | |
"html_url": "https://github.com/ianbattersby", | |
"followers_url": "https://api.github.com/users/ianbattersby/followers", | |
"following_url": "https://api.github.com/users/ianbattersby/following{/other_user}", | |
"gists_url": "https://api.github.com/users/ianbattersby/gists{/gist_id}", | |
"starred_url": "https://api.github.com/users/ianbattersby/starred{/owner}{/repo}", | |
"subscriptions_url": "https://api.github.com/users/ianbattersby/subscriptions", | |
"organizations_url": "https://api.github.com/users/ianbattersby/orgs", | |
"repos_url": "https://api.github.com/users/ianbattersby/repos", | |
"events_url": "https://api.github.com/users/ianbattersby/events{/privacy}", | |
"received_events_url": "https://api.github.com/users/ianbattersby/received_events", | |
"type": "User", | |
"site_admin": false | |
}, | |
"private": false, | |
"html_url": "https://github.com/ianbattersby/public-repo", | |
"description": "", | |
"fork": false, | |
"url": "https://api.github.com/repos/ianbattersby/public-repo", | |
"forks_url": "https://api.github.com/repos/ianbattersby/public-repo/forks", | |
"keys_url": "https://api.github.com/repos/ianbattersby/public-repo/keys{/key_id}", | |
"collaborators_url": "https://api.github.com/repos/ianbattersby/public-repo/collaborators{/collaborator}", | |
"teams_url": "https://api.github.com/repos/ianbattersby/public-repo/teams", | |
"hooks_url": "https://api.github.com/repos/ianbattersby/public-repo/hooks", | |
"issue_events_url": "https://api.github.com/repos/ianbattersby/public-repo/issues/events{/number}", | |
"events_url": "https://api.github.com/repos/ianbattersby/public-repo/events", | |
"assignees_url": "https://api.github.com/repos/ianbattersby/public-repo/assignees{/user}", | |
"branches_url": "https://api.github.com/repos/ianbattersby/public-repo/branches{/branch}", | |
"tags_url": "https://api.github.com/repos/ianbattersby/public-repo/tags", | |
"blobs_url": "https://api.github.com/repos/ianbattersby/public-repo/git/blobs{/sha}", | |
"git_tags_url": "https://api.github.com/repos/ianbattersby/public-repo/git/tags{/sha}", | |
"git_refs_url": "https://api.github.com/repos/ianbattersby/public-repo/git/refs{/sha}", | |
"trees_url": "https://api.github.com/repos/ianbattersby/public-repo/git/trees{/sha}", | |
"statuses_url": "https://api.github.com/repos/ianbattersby/public-repo/statuses/{sha}", | |
"languages_url": "https://api.github.com/repos/ianbattersby/public-repo/languages", | |
"stargazers_url": "https://api.github.com/repos/ianbattersby/public-repo/stargazers", | |
"contributors_url": "https://api.github.com/repos/ianbattersby/public-repo/contributors", | |
"subscribers_url": "https://api.github.com/repos/ianbattersby/public-repo/subscribers", | |
"subscription_url": "https://api.github.com/repos/ianbattersby/public-repo/subscription", | |
"commits_url": "https://api.github.com/repos/ianbattersby/public-repo/commits{/sha}", | |
"git_commits_url": "https://api.github.com/repos/ianbattersby/public-repo/git/commits{/sha}", | |
"comments_url": "https://api.github.com/repos/ianbattersby/public-repo/comments{/number}", | |
"issue_comment_url": "https://api.github.com/repos/ianbattersby/public-repo/issues/comments{/number}", | |
"contents_url": "https://api.github.com/repos/ianbattersby/public-repo/contents/{+path}", | |
"compare_url": "https://api.github.com/repos/ianbattersby/public-repo/compare/{base}...{head}", | |
"merges_url": "https://api.github.com/repos/ianbattersby/public-repo/merges", | |
"archive_url": "https://api.github.com/repos/ianbattersby/public-repo/{archive_format}{/ref}", | |
"downloads_url": "https://api.github.com/repos/ianbattersby/public-repo/downloads", | |
"issues_url": "https://api.github.com/repos/ianbattersby/public-repo/issues{/number}", | |
"pulls_url": "https://api.github.com/repos/ianbattersby/public-repo/pulls{/number}", | |
"milestones_url": "https://api.github.com/repos/ianbattersby/public-repo/milestones{/number}", | |
"notifications_url": "https://api.github.com/repos/ianbattersby/public-repo/notifications{?since,all,participating}", | |
"labels_url": "https://api.github.com/repos/ianbattersby/public-repo/labels{/name}", | |
"releases_url": "https://api.github.com/repos/ianbattersby/public-repo/releases{/id}", | |
"created_at": "2015-05-05T23:40:12Z", | |
"updated_at": "2015-05-05T23:40:30Z", | |
"pushed_at": "2015-05-05T23:40:38Z", | |
"git_url": "git://github.com/ianbattersby/public-repo.git", | |
"ssh_url": "[email protected]:ianbattersby/public-repo.git", | |
"clone_url": "https://github.com/ianbattersby/public-repo.git", | |
"svn_url": "https://github.com/ianbattersby/public-repo", | |
"homepage": null, | |
"size": 0, | |
"stargazers_count": 0, | |
"watchers_count": 0, | |
"language": null, | |
"has_issues": true, | |
"has_downloads": true, | |
"has_wiki": true, | |
"has_pages": true, | |
"forks_count": 0, | |
"mirror_url": null, | |
"open_issues_count": 2, | |
"forks": 0, | |
"open_issues": 2, | |
"watchers": 0, | |
"default_branch": "master" | |
}, | |
"sender": { | |
"login": "ianbattersby", | |
"id": 6752317, | |
"avatar_url": "https://avatars.githubusercontent.com/u/6752317?v=3", | |
"gravatar_id": "", | |
"url": "https://api.github.com/users/ianbattersby", | |
"html_url": "https://github.com/ianbattersby", | |
"followers_url": "https://api.github.com/users/ianbattersby/followers", | |
"following_url": "https://api.github.com/users/ianbattersby/following{/other_user}", | |
"gists_url": "https://api.github.com/users/ianbattersby/gists{/gist_id}", | |
"starred_url": "https://api.github.com/users/ianbattersby/starred{/owner}{/repo}", | |
"subscriptions_url": "https://api.github.com/users/ianbattersby/subscriptions", | |
"organizations_url": "https://api.github.com/users/ianbattersby/orgs", | |
"repos_url": "https://api.github.com/users/ianbattersby/repos", | |
"events_url": "https://api.github.com/users/ianbattersby/events{/privacy}", | |
"received_events_url": "https://api.github.com/users/ianbattersby/received_events", | |
"type": "User", | |
"site_admin": false | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": "9386735572", | |
"type": "IssuesEvent", | |
"actor": { | |
"id": 508260, | |
"login": "matthill", | |
"gravatar_id": "", | |
"url": "https://api.github.com/users/matthill", | |
"avatar_url": "https://avatars.githubusercontent.com/u/508260?" | |
}, | |
"repo": { | |
"id": 47172074, | |
"name": "openalpr/openalpr", | |
"url": "https://api.github.com/repos/openalpr/openalpr" | |
}, | |
"payload": { | |
"action": "opened", | |
"issue": { | |
"url": "https://api.github.com/repos/openalpr/openalpr/issues/223", | |
"labels_url": "https://api.github.com/repos/openalpr/openalpr/issues/223/labels{/name}", | |
"comments_url": "https://api.github.com/repos/openalpr/openalpr/issues/223/comments", | |
"events_url": "https://api.github.com/repos/openalpr/openalpr/issues/223/events", | |
"html_url": "https://github.com/openalpr/openalpr/issues/223", | |
"id": 118478322, | |
"number": 223, | |
"title": "Python 3 support", | |
"user": { | |
"login": "jk1ng", | |
"id": 6633760, | |
"avatar_url": "https://avatars.githubusercontent.com/u/6633760?v=3", | |
"gravatar_id": "", | |
"url": "https://api.github.com/users/jk1ng", | |
"html_url": "https://github.com/jk1ng", | |
"followers_url": "https://api.github.com/users/jk1ng/followers", | |
"following_url": "https://api.github.com/users/jk1ng/following{/other_user}", | |
"gists_url": "https://api.github.com/users/jk1ng/gists{/gist_id}", | |
"starred_url": "https://api.github.com/users/jk1ng/starred{/owner}{/repo}", | |
"subscriptions_url": "https://api.github.com/users/jk1ng/subscriptions", | |
"organizations_url": "https://api.github.com/users/jk1ng/orgs", | |
"repos_url": "https://api.github.com/users/jk1ng/repos", | |
"events_url": "https://api.github.com/users/jk1ng/events{/privacy}", | |
"received_events_url": "https://api.github.com/users/jk1ng/received_events", | |
"type": "User", | |
"site_admin": false | |
}, | |
"labels": [], | |
"state": "opened", | |
"locked": false, | |
"assignee": null, | |
"milestone": null, | |
"comments": 0, | |
"created_at": "2015-11-23T21:38:18Z", | |
"updated_at": "2015-11-27T20:40:51Z", | |
"closed_at": "2015-11-27T20:40:51Z", | |
"body": "Hi!\r\n\r\nIt seems that with Python 3, the current binding for OpenALPR in Python does not work.\r\n\r\nThis is because str/unicode in Python 2 have now become bytes/str in Python 3.\r\n\r\nThanks!" | |
} | |
}, | |
"public": true, | |
"created_at": "2015-11-27T20:40:51Z", | |
"org": { | |
"id": 5896442, | |
"login": "openalpr", | |
"gravatar_id": "", | |
"url": "https://api.github.com/orgs/openalpr", | |
"avatar_url": "https://avatars.githubusercontent.com/u/5896442?" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": "9386735597", | |
"type": "PushEvent", | |
"actor": { | |
"id": 293685, | |
"login": "mattbellis", | |
"gravatar_id": "", | |
"url": "https://api.github.com/users/mattbellis", | |
"avatar_url": "https://avatars.githubusercontent.com/u/293685?" | |
}, | |
"repo": { | |
"id": 47172074, | |
"name": "particle-physics-playground/playground", | |
"url": "https://api.github.com/repos/particle-physics-playground/playground" | |
}, | |
"payload": { | |
"push_id": 882178636, | |
"size": 1, | |
"distinct_size": 1, | |
"ref": "refs/heads/master", | |
"head": "0c35be9660a1ea300559a82b25b3776038028a12", | |
"before": "cbba8b2441cff4142b4546347ad4907509812db5", | |
"commits": [ | |
{ | |
"sha": "0c35be9660a1ea300559a82b25b3776038028a12", | |
"author": { | |
"email": "[email protected]", | |
"name": "Matthew Bellis" | |
}, | |
"message": "Fixed #223 new URL for downloading data.", | |
"distinct": true, | |
"url": "https://api.github.com/repos/particle-physics-playground/playground/commits/0c35be9660a1ea300559a82b25b3776038028a12" | |
} | |
] | |
}, | |
"public": true, | |
"created_at": "2015-11-27T20:40:52Z", | |
"org": { | |
"id": 10271404, | |
"login": "particle-physics-playground", | |
"gravatar_id": "", | |
"url": "https://api.github.com/orgs/particle-physics-playground", | |
"avatar_url": "https://avatars.githubusercontent.com/u/10271404?" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When want to process issues and ideally by their repository's own tracked | |
// issue number, so it makes sense to split this data into per-repository | |
// streams; thus all events for a certain repository end up in their own stream. | |
fromCategory("github") | |
.foreachStream() | |
.when({ | |
"IssuesEvent": function(s,e) { | |
// In an ideal world we'd use linkTo here but it causes a problem | |
// when consumingn with foreachStream, the problem being it doesn't | |
// maintain the state correctly (TBC eventstore-guys). | |
emit("repo-" + e.data.repo.id, e.eventType, e.data); | |
return s; | |
}, | |
"PushEvent": function(s,e) { | |
// You will notice with an emit (opposed to a linkTo) we need to pass | |
// the ES-EventType and the data object (not the whole event object). | |
emit("repo-" + e.data.repo.id, e.eventType, e.data); | |
return s; | |
}, | |
"DeploymentEvent": function(s,e) { | |
// This is hypothetical based on GitHubAPI documentation - as it's | |
// a trigger-only event so likely never comes through events API. | |
emit("repo-" + e.data.repository.id, e.eventType, e.data); | |
return s; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How do we match descriptions that close issues/etc? | |
var closingCommitRegEx = new RegExp("(((close|resolve)(s|d)?)|fix(e(s|d))?) #(\\d+)", "i"); | |
// How do we tell the difference between two ISO8601 date strings? | |
function iso8601StringDateDiffInDays(date1, date2) { | |
var msPerDay = 1000 * 60 * 60 * 24; | |
var a = new Date(date1); | |
var b = new Date(date2); | |
var utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate()); | |
var utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate()); | |
return Math.floor((utc2 - utc1) / msPerDay); | |
} | |
// Some operating variables | |
var starRepositoryEventQualifiesInDays = 5; | |
var superRepositoryEventQualifiesInDays = 3; | |
var emitToStream = "proj.repoLeaderBoard"; | |
// The projection | |
fromCategory("repo") | |
.foreachStream() | |
.when({ | |
$init: function() { | |
return { | |
trackedIssues: [] | |
}; | |
}, | |
"IssuesEvent": function(s, e) { | |
if (e.data.payload.action && e.data.payload.action === "opened" && e.data.payload.issue.number) { | |
s.trackedIssues[e.data.payload.issue.number] = { | |
createdOn: e.data.payload.issue.created_at, | |
fixedOn: null, | |
deployedOn: null | |
}; | |
} | |
return s; | |
}, | |
"PushEvent": function(s, e) { | |
if (s.trackedIssues.length > 0 && e.data.payload.commits && e.data.payload.commits.length > 0) { | |
for (var i = 0; i < e.data.payload.commits.length; i++) { | |
if (e.data.payload.commits[i].message && closingCommitRegEx.test(e.data.payload.commits[i].message)) { | |
var issueNumber = closingCommitRegEx.exec(e.data.payload.commits[i].message).reverse()[0]; | |
//Are we tracking this issue? | |
if (s.trackedIssues[issueNumber] !== undefined && s.trackedIssues[issueNumber] !== null && s.trackedIssues[issueNumber].createdOn !== null) { | |
//s.trackedIssues[issueNumber].fixedOn = e.data.payload.commits[i].timestamp; | |
s.trackedIssues[issueNumber].fixedOn = e.data.created_at; | |
if (iso8601StringDateDiffInDays(s.trackedIssues[issueNumber].createdOn, s.trackedIssues[issueNumber].fixedOn) <= starRepositoryEventQualifiesInDays) { | |
emit(emitToStream, "StarRepositoryEvent", e.data); | |
break; | |
} | |
} else { | |
// Is it possible we'll encounter the issue after the push? Erm. | |
// If we decide to do this we'll need to remove the length condition | |
// above so we get in here. | |
} | |
} | |
} | |
} | |
return s; | |
}, | |
"DeploymentEvent": function(s, e) { | |
if (e.data.deployment.environment === "production") { | |
var thisDeploymentDate = e.data.deployment.created_at; | |
if (e.data.deployment.description && closingCommitRegEx.test(e.data.deployment.description)) { | |
var issueNumber = closingCommitRegEx.exec(e.data.deployment.description).reverse()[0]; | |
//Are we tracking this issue? | |
if (s.trackedIssues[issueNumber] !== undefined && s.trackedIssues[issueNumber] !== null) { | |
s.trackedIssues[issueNumber].deployedOn = thisDeploymentDate; | |
if (iso8601StringDateDiffInDays(s.trackedIssues[issueNumber].fixedOn, thisDeploymentDate) <= superRepositoryEventQualifiesInDays) { | |
emit(emitToStream, "SuperDuperRepositoryEvent", e.data); | |
} | |
} | |
} else { | |
// Could be we don't have a description :-( | |
for (var idx in s.trackedIssues) { | |
if (s.trackedIssues.hasOwnProperty(idx)) { | |
if (s.trackedIssues[idx] !== undefined && s.trackedIssues[idx] !== null && s.trackedIssues[idx].fixedOn !== null && thisDeploymentDate > s.trackedIssues[idx].fixedOn) { | |
//We'll assume any issues we are tracking or deployed if this is after they were fixed! | |
s.trackedIssues[idx].deployedOn = thisDeploymentDate; | |
if (iso8601StringDateDiffInDays(s.trackedIssues[idx].fixedOn, thisDeploymentDate) <= superRepositoryEventQualifiesInDays) { | |
emit(emitToStream, "SuperRepositoryEvent", e.data); | |
} | |
} | |
} | |
} | |
} | |
} | |
return s; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment