2017-12-20 19:04:12 +00:00
|
|
|
package hipchat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/keel-hq/keel/types"
|
|
|
|
)
|
|
|
|
|
2017-12-27 13:46:38 +00:00
|
|
|
func (b *Bot) RequestApproval(req *types.Approval) error {
|
2017-12-22 11:40:44 +00:00
|
|
|
msg := fmt.Sprintf(ApprovalRequiredTempl,
|
2018-01-10 08:02:04 +00:00
|
|
|
req.Message, req.Identifier, req.Identifier,
|
2017-12-20 19:04:12 +00:00
|
|
|
req.VotesReceived, req.VotesRequired, req.Delta(), req.Identifier,
|
|
|
|
req.Provider.String())
|
2017-12-22 11:40:44 +00:00
|
|
|
return b.postMessage(formatAsSnippet(msg))
|
2017-12-20 19:04:12 +00:00
|
|
|
}
|
|
|
|
|
2017-12-27 13:46:38 +00:00
|
|
|
func (b *Bot) ReplyToApproval(approval *types.Approval) error {
|
2017-12-20 19:04:12 +00:00
|
|
|
switch approval.Status() {
|
|
|
|
case types.ApprovalStatusPending:
|
2017-12-22 11:40:44 +00:00
|
|
|
msg := fmt.Sprintf(VoteReceivedTempl,
|
2017-12-21 13:20:50 +00:00
|
|
|
approval.VotesReceived, approval.VotesRequired, approval.Delta(), approval.Identifier)
|
2017-12-21 17:17:04 +00:00
|
|
|
b.postMessage(formatAsSnippet(msg))
|
2017-12-20 19:04:12 +00:00
|
|
|
case types.ApprovalStatusRejected:
|
2017-12-22 11:40:44 +00:00
|
|
|
msg := fmt.Sprintf(ChangeRejectedTempl,
|
2017-12-21 13:20:50 +00:00
|
|
|
approval.Status().String(), approval.VotesReceived, approval.VotesRequired,
|
|
|
|
approval.Delta(), approval.Identifier)
|
2017-12-21 17:17:04 +00:00
|
|
|
b.postMessage(formatAsSnippet(msg))
|
2017-12-20 19:04:12 +00:00
|
|
|
case types.ApprovalStatusApproved:
|
2017-12-22 11:40:44 +00:00
|
|
|
msg := fmt.Sprintf(UpdateApprovedTempl,
|
2017-12-21 13:20:50 +00:00
|
|
|
approval.VotesReceived, approval.VotesRequired, approval.Delta(), approval.Identifier)
|
2017-12-21 17:17:04 +00:00
|
|
|
b.postMessage(formatAsSnippet(msg))
|
2017-12-20 19:04:12 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|