Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek committed Nov 8, 2018
1 parent 97ef0b2 commit 63a29fb
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions func.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"log"
"net/url"
"strings"
"time"

"github.com/ChimeraCoder/anaconda"
fdk "github.com/fnproject/fdk-go"
Expand All @@ -22,8 +21,6 @@ func main() {
}

func webhookHandler(ctx context.Context, in io.Reader, out io.Writer) {
log.Println("invoked webhook on ", time.Now())

fnCtx := fdk.GetContext(ctx)
eventType := fnCtx.Header().Get("X-GitHub-Event")
log.Println("eventType ", eventType)
Expand All @@ -33,10 +30,8 @@ func webhookHandler(ctx context.Context, in io.Reader, out io.Writer) {
buf := new(bytes.Buffer)
buf.ReadFrom(in)
payload := buf.String()
//log.Println(payload)

signatureFromGithub := fnCtx.Header().Get("X-Hub-Signature")
//log.Println("signatureFromGithub ", signatureFromGithub)

if !matchSignature(signatureFromGithub, fnCtx.Config()["github_webhook_secret"], payload) {
log.Println("Signature did not match. Webhook was not invoked by Github")
Expand All @@ -47,16 +42,14 @@ func webhookHandler(ctx context.Context, in io.Reader, out io.Writer) {

json.NewDecoder(strings.NewReader(payload)).Decode(&notification)

//out.Write([]byte("eventType ? " + eventType))
//out.Write([]byte("message " + notification.Details()))
err := tweet(notification.Details(), fnCtx.Config()["twitter_consumerkey"], fnCtx.Config()["twitter_consumersecret"], fnCtx.Config()["twitter_accesstoken"], fnCtx.Config()["twitter_accesstokensecret"])
if err != nil {
fdk.WriteStatus(out, 500)
prob := "Could not tweet new release details due to " + err.Error()
log.Println(prob)
return
//out.Write([]byte(prob))
}

log.Println(notification.Details())
out.Write([]byte(notification.Details()))
}
Expand Down Expand Up @@ -84,13 +77,10 @@ func tweet(tweet, consumerkey, consumersecret, accesstoken, accesstokensecret st
_, err := api.PostTweet(tweet, url.Values{})

if err != nil {
//log.Println("COULD NOT POST TWEET")
return err
}

return nil
//return "tweeted new release details !!!"

}

type newReleaseNotification struct {
Expand All @@ -108,5 +98,5 @@ type repo struct {
}

func (notification newReleaseNotification) Details() string {
return "Release " + notification.Release.Version + " for " + notification.Repository.Name + " in out! Grab it while it's hot - " + notification.Release.Link
return "Release " + notification.Release.Version + " for " + notification.Repository.Name + " is out! Grab it while it's hot - " + notification.Release.Link
}

0 comments on commit 63a29fb

Please sign in to comment.