// newSlackServer returns an http handler for handling Slack slash commands at <url>/slack. func newSlackServer(q conveyor.BuildQueue, c *cli.Context) http.Handler { ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: c.String("github.token")}, ) tc := oauth2.NewClient(oauth2.NoContext, ts) cy := github.NewClient(tc) r := slash.NewMux() r.Match(slash.MatchSubcommand(`help`), slack.Help) r.MatchText( regexp.MustCompile(`enable (?P<owner>\S+?)/(?P<repo>\S+)`), slack.NewEnable( cy, slack.NewHook(c.String("url"), c.String("github.secret")), ), ) r.MatchText( regexp.MustCompile(`build (?P<owner>\S+?)/(?P<repo>\S+)@(?P<branch>\S+)`), slack.NewBuild( cy, q, fmt.Sprintf(logsURLTemplate, c.String("url")), ), ) return slash.NewServer(slash.ValidateToken(r, c.String("slack.token"))) }
// newSlackServer returns an http handler for handling Slack slash commands at <url>/slack. func newSlackServer(c *cli.Context) http.Handler { ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: c.String("github.token")}, ) tc := oauth2.NewClient(oauth2.NoContext, ts) client := github.NewClient(tc) r := slash.NewMux() r.MatchText( regexp.MustCompile(`setup (?P<owner>\S+?)/(?P<repo>\S+)`), slack.NewWebhookHandler( client, slack.NewHook(c.String("url"), c.String("github.secret")), ), ) return slash.NewServer(slash.ValidateToken(r, c.String("slack.token"))) }
// newSlackServer returns an http handler for handling Slack slash commands at <url>/slack. func newSlackServer(cy *conveyor.Conveyor, c *cli.Context) http.Handler { s := slack.New(cy) s.URLTemplate = template.Must(template.New("url").Parse(fmt.Sprintf(logsURLTemplate, c.String("url")))) return slash.NewServer(slash.ValidateToken(s, c.String("slack.token"))) }