Skip to content

Instantly share code, notes, and snippets.

@djui
Last active May 25, 2016 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djui/1ba78be5e1020b1895f13153f59c3dd6 to your computer and use it in GitHub Desktop.
Save djui/1ba78be5e1020b1895f13153f59c3dd6 to your computer and use it in GitHub Desktop.
go-github push event handling
github.PushEvent{
Repo:github.PushEventRepository{
CreatedAt:github.Timestamp{2015-10-26 15:42:55 +0000 UTC},
DefaultBranch:"master",
Description:"A simple continuous integration server using Hookbot to subscribe to branch changes on Github hosted repositories.",
Fork:false,
ForksCount:0,
FullName:"scraperwiki/seaeye",
HasDownloads:true,
HasIssues:true,
HasPages:false,
HasWiki:true,
Homepage:"",
HTMLURL:"https://github.com/scraperwiki/seaeye",
ID:44978699,
Language:"Go",
Name:"seaeye",
OpenIssuesCount:0,
Owner:github.PushEventRepoOwner{},
Private:false,
PushedAt:github.Timestamp{2016-05-25 07:11:13 +0000 UTC},
Size:2700,
StargazersCount:0,
UpdatedAt:github.Timestamp{2016-05-12 05:55:14 +0000 UTC},
URL:"https://api.github.com/repos/scraperwiki/seaeye",
WatchersCount:0,
},
Sender:github.User{
AvatarURL:"https://avatars.githubusercontent.com/u/99752?v=3",
EventsURL:"https://api.github.com/users/djui/events{/privacy}",
FollowersURL:"https://api.github.com/users/djui/followers",
FollowingURL:"https://api.github.com/users/djui/following{/other_user}",
GistsURL:"https://api.github.com/users/djui/gists{/gist_id}",
GravatarID:"",
HTMLURL:"https://github.com/djui",
ID:99752,
Login:"djui",
OrganizationsURL:"https://api.github.com/users/djui/orgs",
ReceivedEventsURL:"https://api.github.com/users/djui/received_events",
ReposURL:"https://api.github.com/users/djui/repos",
SiteAdmin:false,
StarredURL:"https://api.github.com/users/djui/starred{/owner}{/repo}",
SubscriptionsURL:"https://api.github.com/users/djui/subscriptions",
Type:"User",
URL:"https://api.github.com/users/djui",
}
}
package main
import (
"encoding/json"
"log"
"net/http"
"github.com/google/go-github/github"
)
func main() {
http.HandleFunc("/", githubHookHandler)
http.ListenAndServe(":8080", nil)
}
func githubHookHandler(w http.ResponseWriter, req *http.Request) {
//event := github.WebHookPayload{}
event := github.PushEvent{}
if err := json.NewDecoder(req.Body).Decode(&event); err != nil {
log.Printf("failed to parse event: %v", err)
}
log.Printf("Event: %v", event)
}
github.WebHookPayload{
Repo:github.Repository{
ArchiveURL:"https://api.github.com/repos/scraperwiki/seaeye/{archive_format}{/ref}",
AssigneesURL:"https://api.github.com/repos/scraperwiki/seaeye/assignees{/user}",
BlobsURL:"https://api.github.com/repos/scraperwiki/seaeye/git/blobs{/sha}",
BranchesURL:"https://api.github.com/repos/scraperwiki/seaeye/branches{/branch}",
CloneURL:"https://github.com/scraperwiki/seaeye.git",
CollaboratorsURL:"https://api.github.com/repos/scraperwiki/seaeye/collaborators{/collaborator}",
CommentsURL:"https://api.github.com/repos/scraperwiki/seaeye/comments{/number}",
CommitsURL:"https://api.github.com/repos/scraperwiki/seaeye/commits{/sha}",
CompareURL:"https://api.github.com/repos/scraperwiki/seaeye/compare/{base}...{head}",
ContentsURL:"https://api.github.com/repos/scraperwiki/seaeye/contents/{+path}",
ContributorsURL:"https://api.github.com/repos/scraperwiki/seaeye/contributors",
CreatedAt:github.Timestamp{2015-10-26 15:42:55 +0000 UTC},
DefaultBranch:"master",
Description:"A simple continuous integration server using Hookbot to subscribe to branch changes on Github hosted repositories.",
DownloadsURL:"https://api.github.com/repos/scraperwiki/seaeye/downloads",
EventsURL:"https://api.github.com/repos/scraperwiki/seaeye/events",
Fork:false,
ForksCount:0,
ForksURL:"https://api.github.com/repos/scraperwiki/seaeye/forks",
FullName:"scraperwiki/seaeye",
GitCommitsURL:"https://api.github.com/repos/scraperwiki/seaeye/git/commits{/sha}",
GitRefsURL:"https://api.github.com/repos/scraperwiki/seaeye/git/refs{/sha}",
GitTagsURL:"https://api.github.com/repos/scraperwiki/seaeye/git/tags{/sha}",
GitURL:"git://github.com/scraperwiki/seaeye.git",
HasDownloads:true,
HasIssues:true,
HasWiki:true,
Homepage:"",
HooksURL:"https://api.github.com/repos/scraperwiki/seaeye/hooks",
HTMLURL:"https://github.com/scraperwiki/seaeye",
ID:44978699,
IssueCommentURL:"https://api.github.com/repos/scraperwiki/seaeye/issues/comments{/number}",
IssueEventsURL:"https://api.github.com/repos/scraperwiki/seaeye/issues/events{/number}",
IssuesURL:"https://api.github.com/repos/scraperwiki/seaeye/issues{/number}",
KeysURL:"https://api.github.com/repos/scraperwiki/seaeye/keys{/key_id}",
LabelsURL:"https://api.github.com/repos/scraperwiki/seaeye/labels{/name}",
Language:"Go",
LanguagesURL:"https://api.github.com/repos/scraperwiki/seaeye/languages",
MergesURL:"https://api.github.com/repos/scraperwiki/seaeye/merges",
MilestonesURL:"https://api.github.com/repos/scraperwiki/seaeye/milestones{/number}",
Name:"seaeye",
NotificationsURL:"https://api.github.com/repos/scraperwiki/seaeye/notifications{?since,all,participating}",
OpenIssuesCount:0,
Owner:github.User{
AvatarURL:"https://avatars.githubusercontent.com/u/1050343?v=3",
EventsURL:"https://api.github.com/users/scraperwiki/events{/privacy}",
FollowersURL:"https://api.github.com/users/scraperwiki/followers",
FollowingURL:"https://api.github.com/users/scraperwiki/following{/other_user}",
GistsURL:"https://api.github.com/users/scraperwiki/gists{/gist_id}",
GravatarID:"",
HTMLURL:"https://github.com/scraperwiki",
ID:1050343,
Login:"scraperwiki",
OrganizationsURL:"https://api.github.com/users/scraperwiki/orgs",
ReceivedEventsURL:"https://api.github.com/users/scraperwiki/received_events",
ReposURL:"https://api.github.com/users/scraperwiki/repos",
SiteAdmin:false,
StarredURL:"https://api.github.com/users/scraperwiki/starred{/owner}{/repo}",
SubscriptionsURL:"https://api.github.com/users/scraperwiki/subscriptions",
Type:"Organization",
URL:"https://api.github.com/users/scraperwiki",
},
Private:false,
PullsURL:"https://api.github.com/repos/scraperwiki/seaeye/pulls{/number}",
PushedAt:github.Timestamp{2016-05-25 07:11:13 +0000 UTC},
ReleasesURL:"https://api.github.com/repos/scraperwiki/seaeye/releases{/id}",
Size:2700,
SSHURL:"git@github.com:scraperwiki/seaeye.git",
StargazersCount:0,
StargazersURL:"https://api.github.com/repos/scraperwiki/seaeye/stargazers",
StatusesURL:"https://api.github.com/repos/scraperwiki/seaeye/statuses/{sha}",
SubscribersURL:"https://api.github.com/repos/scraperwiki/seaeye/subscribers",
SubscriptionURL:"https://api.github.com/repos/scraperwiki/seaeye/subscription",
SVNURL:"https://github.com/scraperwiki/seaeye",
TagsURL:"https://api.github.com/repos/scraperwiki/seaeye/tags",
TeamsURL:"https://api.github.com/repos/scraperwiki/seaeye/teams"
TreesURL:"https://api.github.com/repos/scraperwiki/seaeye/git/trees{/sha}",
UpdatedAt:github.Timestamp{2016-05-12 05:55:14 +0000 UTC},
URL:"https://api.github.com/repos/scraperwiki/seaeye",
WatchersCount:0,
},
Sender:github.User{
AvatarURL:"https://avatars.githubusercontent.com/u/99752?v=3",
EventsURL:"https://api.github.com/users/djui/events{/privacy}",
FollowersURL:"https://api.github.com/users/djui/followers",
FollowingURL:"https://api.github.com/users/djui/following{/other_user}",
GistsURL:"https://api.github.com/users/djui/gists{/gist_id}",
GravatarID:"",
HTMLURL:"https://github.com/djui",
ID:99752,
Login:"djui",
OrganizationsURL:"https://api.github.com/users/djui/orgs",
ReceivedEventsURL:"https://api.github.com/users/djui/received_events",
ReposURL:"https://api.github.com/users/djui/repos",
SiteAdmin:false,
StarredURL:"https://api.github.com/users/djui/starred{/owner}{/repo}",
SubscriptionsURL:"https://api.github.com/users/djui/subscriptions",
Type:"User",
URL:"https://api.github.com/users/djui",
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment