diff --git a/ci.go b/ci.go index b9f50eb..9085b80 100644 --- a/ci.go +++ b/ci.go @@ -40,27 +40,26 @@ func (s *Session) ciHandler() error { s.msgID++ case p := <-dServer.Out: var parent string - parent, ok := s.commitParent[p.Commit.SHA] + parent, ok := s.commitParent[p.Build.Commit] if !ok { parent = "" } var emoji string - if p.Commit.Status == "Success" { + if p.Build.Status == "success" { emoji = ":white_check_mark:" } else { emoji = ":no_entry:" } - // https://drone.in.euphoria.io/github.com/euphoria-io/heim/master/b816f23ec209d6f6d2f99788515329099e3d92d0 - url := fmt.Sprintf("drone.in.euphoria.io/%s/%s/%s/%s/%s", - p.Repository.Host, - p.Repository.Owner, - p.Repository.Name, - p.Commit.Branch, - p.Commit.SHA) + // https://drone.in.euphoria.io/euphoria-io/heim/77 + url := fmt.Sprintf("drone.in.euphoria.io/%s/%s/%v", + p.Repo.Name, + p.Build.Branch, + p.Build.Number, + ) str := fmt.Sprintf("%s [ drone.io | %s | Branch: %s ] (%s)", emoji, - p.Repository.Name, - p.Commit.Branch, + p.Repo.Name, + p.Build.Branch, url, ) s.sendMessage(str, diff --git a/github.go b/github.go index 83eebcc..1d419f6 100644 --- a/github.go +++ b/github.go @@ -19,8 +19,6 @@ func (s *Session) hookServer(port int, secret string, sendReplyChan chan PacketE et := <-gServer.EventAndTypes s.logger.Infof("Received hook event of type '%s'.", et.Type) switch et.Type { - case gohook.PingEventType: - continue case gohook.CommitCommentEventType: payload, ok := et.Event.(*gohook.CommitCommentEvent) if !ok { @@ -88,7 +86,7 @@ func (s *Session) hookServer(port int, secret string, sendReplyChan chan PacketE panic("Malformed *PullRequestEvent.") } action := payload.Action - if action == "synced" { + if action == "synchronize" { action = "New commits made to synced branch." } msg := fmt.Sprintf(":pencil: [ %s | PR: %s ] %s (%s)", @@ -97,8 +95,28 @@ func (s *Session) hookServer(port int, secret string, sendReplyChan chan PacketE action, payload.PullRequest.HTMLURL, ) - s.sendMessage(msg, "", strconv.Itoa(s.msgID)) s.msgID++ + t := strconv.Itoa(int(time.Now().Unix())) + s.waiting = true + s.sendMessage(msg, "", t) + var reply PacketEvent + for s.waiting { + reply = <-sendReplyChan + if reply.ID == t { + s.waiting = false + } + } + srPayload, err := reply.Payload() + if err != nil { + s.logger.Fatalln(err) + } + + // need send-reply for msgID to reply to + data, ok := srPayload.(*SendReply) + if !ok { + s.logger.Fatalln("Could not assert *SendReply as such.") + } + s.commitParent[payload.PullRequest.Head.SHA] = data.ID case gohook.PullRequestReviewCommentEventType: payload, ok := et.Event.(*gohook.PullRequestReviewCommentEvent) if !ok { @@ -131,7 +149,7 @@ func (s *Session) hookServer(port int, secret string, sendReplyChan chan PacketE panic("Malformed *PushEvent.") } if payload.HeadCommit.Message == "" { - return + continue } var msg string if len(payload.Commits) > 1 { @@ -171,6 +189,14 @@ func (s *Session) hookServer(port int, secret string, sendReplyChan chan PacketE s.logger.Fatalln("Could not assert *SendReply as such.") } s.commitParent[payload.HeadCommit.ID] = data.ID + case gohook.PingEventType: + //payload, ok := et.Event.(*gohook.PingEvent) + //if !ok { + // panic("Malformed *PingEvent") + //} + s.sendMessage("[ Github Webhook | ping ]", "", strconv.Itoa(s.msgID)) + s.msgID++ } + } }