Skip to content

Commit

Permalink
feat(core): Add support for looking up Slack usernames on summon
Browse files Browse the repository at this point in the history
References: #40, #15
  • Loading branch information
etcinit committed Oct 17, 2016
1 parent 39c93ee commit 9b84a7d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/etcinit/phabulous/app/modules/core"
"github.com/etcinit/phabulous/app/modules/dev"
"github.com/etcinit/phabulous/app/modules/extension"
"github.com/jacobstr/confer"
"github.com/nlopes/slack"
)

Expand Down Expand Up @@ -234,6 +235,11 @@ func (b *Bot) MakeSlack() *slack.Client {
return b.Slacker.Slack
}

// MakeConfig returns an instance of the configuration store.
func (b *Bot) MakeConfig() *confer.Config {
return b.Slacker.Config
}

// HandleUsage shows usage tip.
func (b *Bot) HandleUsage(ev *slack.MessageEvent, matches []string) {
b.Slacker.SimplePost(
Expand Down
41 changes: 41 additions & 0 deletions app/modules/core/command_summon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strings"

"github.com/etcinit/gonduit/requests"
"github.com/etcinit/phabulous/app/gonduit/extensions"
phabulousRequests "github.com/etcinit/phabulous/app/gonduit/extensions/requests"
"github.com/etcinit/phabulous/app/messages"
"github.com/etcinit/phabulous/app/modules"
"github.com/nlopes/slack"
Expand Down Expand Up @@ -94,9 +96,48 @@ func (c *SummonCommand) GetHandler() modules.Handler {
return
}

slackMap, err := extensions.PhabulousToSlack(
conn,
phabulousRequests.PhabulousToSlackRequest{
UserPHIDs: (*res)[0].Reviewers,
},
)
if err != nil {
s.Excuse(ev, err)
return
}

slackUsers, err := s.MakeSlack().GetUsers()
if err != nil {
s.Excuse(ev, err)
return
}

reviewerNames := []string{}

for _, reviewerPHID := range (*res)[0].Reviewers {
if slackUserInfo, ok := (*slackMap)[reviewerPHID]; ok {
var foundUser *slack.User
for _, user := range slackUsers {
if user.ID == slackUserInfo.AccountID {
foundUser = &user
break
}
}

if foundUser != nil {
reviewerNames = append(
reviewerNames,
fmt.Sprintf(
"@%s :slack:",
foundUser.Name,
),
)

continue
}
}

nameRes, err := conn.PHIDQuerySingle(reviewerPHID)
if err != nil {
s.Excuse(ev, err)
Expand Down
4 changes: 2 additions & 2 deletions app/modules/extension/command_whois.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func toSlack(
if len(*accounts) == 0 {
s.Post(
ev.Channel,
"I was unable to find a Phabricator user linked with that "+
"Slack account. Make sure they are linked under "+
"I was unable to find a Slack user linked with that "+
"Phabricator account. Make sure they are linked under "+
"_External Accounts_ in the user's Phabricator settings.",
messages.IconTasks,
true,
Expand Down
2 changes: 2 additions & 0 deletions app/modules/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package modules
import (
"github.com/etcinit/gonduit"
"github.com/etcinit/phabulous/app/messages"
"github.com/jacobstr/confer"
"github.com/nlopes/slack"
)

Expand All @@ -22,6 +23,7 @@ type Service interface {
MakeGonduit() (*gonduit.Conn, error)
MakeRTM() *slack.RTM
MakeSlack() *slack.Client
MakeConfig() *confer.Config
GetModules() []Module
}

Expand Down

0 comments on commit 9b84a7d

Please sign in to comment.