Last active
April 24, 2017 18:47
-
-
Save deankarn/de773b863e8b5e0f4301c20a10d8020d to your computer and use it in GitHub Desktop.
Release WebHook & Tweet
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"log" | |
twitter "github.com/ChimeraCoder/anaconda" | |
"gopkg.in/go-playground/webhooks.v3" | |
"gopkg.in/go-playground/webhooks.v3/github" | |
) | |
func main() { | |
// Setup Twitter API | |
twitter.SetConsumerKey("KYdUVVkPNtjQpiLV4Rksq4np5") | |
twitter.SetConsumerSecret("FKGf0lGw6hQsmzXkyFYwpYngvI9liVInKBRMN3sge1pHEcs07Y") | |
twitterAPI := twitter.NewTwitterApi("850339775936593920-5V0rd9m1yyzgfpbYr5uhwXLbmF1bCGu", "uiI2jQRNSgCidiQaNOXmz0zCAwCa3W1orUa64Ku8F9OaX") // Access Token + Secret | |
// Setup GitHub webhook events and Listen | |
hook := github.New(&github.Config{Secret: "mySuperWebHookSecret"}) | |
hook.RegisterEvents(func(payload interface{}, header webhooks.Header) { | |
pl := payload.(github.ReleasePayload) | |
// only want to tweet about full releases... for now | |
if pl.Release.Draft || pl.Release.Prerelease || pl.Release.TargetCommitish != "master" { | |
return | |
} | |
post := fmt.Sprintf("%s %s %s #%s", pl.Repository.Name, pl.Release.TagName, pl.Release.HTMLURL, pl.Repository.FullName[:len(pl.Repository.FullName)-len(pl.Repository.Name)-1]) | |
_, err := twitterAPI.PostTweet(post, nil) | |
if err != nil { | |
log.Println(err) | |
} | |
}, github.ReleaseEvent) | |
err := webhooks.Run(hook, fmt.Sprintf(":%d", 4434), "/webhook") | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you mean to leave your twitter api secrets in this gist?