Exemple #1
0
// 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")))
}
Exemple #2
0
func Example() {
	r := slash.NewMux()
	r.Command("/weather", "secrettoken", slash.HandlerFunc(Weather))

	s := slash.NewServer(r)
	http.ListenAndServe(":8080", s)
}
Exemple #3
0
// Weather is the primary slash handler for the /weather command.
func Weather(ctx context.Context, command slash.Command) (string, error) {
	h := slash.NewMux()

	var zipcodeRegex = regexp.MustCompile(`(?P<zip>[0-9])`)
	h.MatchText(zipcodeRegex, slash.HandlerFunc(Zipcode))

	return h.ServeCommand(ctx, command)
}
Exemple #4
0
func newSlack(c client) *Slack {
	r := slash.NewMux()
	s := &Slack{client: c, mux: r}

	r.Match(slash.MatchSubcommand(`help`), Help)
	r.MatchText(
		regexp.MustCompile(`enable (?P<owner>\S+?)/(?P<repo>\S+)`),
		slash.HandlerFunc(s.Enable),
	)
	r.MatchText(
		regexp.MustCompile(`build (?P<owner>\S+?)/(?P<repo>\S+)@(?P<branch>\S+)`),
		slash.HandlerFunc(s.Build),
	)

	return s
}
Exemple #5
0
// 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")))
}