func (s *Slack) Enable(ctx context.Context, r slash.Responder, command slash.Command) error { params := slash.Params(ctx) owner, repo := params["owner"], params["repo"] if err := s.client.EnableRepo(ctx, fmt.Sprintf("%s/%s", owner, repo)); err != nil { return r.Respond(slash.Reply(fmt.Sprintf("error: %v", err))) } return r.Respond(slash.Reply(fmt.Sprintf("Installed webhook on %s/%s", owner, repo))) }
func (s *Slack) Build(ctx context.Context, r slash.Responder, command slash.Command) error { params := slash.Params(ctx) owner, repo, branch := params["owner"], params["repo"], params["branch"] r.Respond(slash.Reply("One moment...")) if err := s.build(ctx, r, owner, repo, branch); err != nil { return r.Respond(slash.Reply(fmt.Sprintf("error: %s", err))) } return nil }
func (b *Build) build(ctx context.Context, r slash.Responder, owner, repo, branch string) error { sha, err := b.resolveBranch(owner, repo, branch) if err != nil { return r.Respond(slash.Reply(err.Error())) } fullRepo := fmt.Sprintf("%s/%s", owner, repo) id := newID() opts := builder.BuildOptions{ ID: id, Repository: fullRepo, Branch: branch, Sha: sha, } if err := b.Queue.Push(ctx, opts); err != nil { return r.Respond(slash.Reply(err.Error())) } url, err := b.url(opts) if err != nil { return r.Respond(slash.Reply(err.Error())) } return r.Respond(slash.Reply(fmt.Sprintf("Building %s@%s: %s", fullRepo, branch, url))) }
func Handle(ctx context.Context, r slash.Responder, command slash.Command) error { if err := r.Respond(slash.Reply("Cool beans")); err != nil { return err } for i := 0; i < 4; i++ { <-time.After(time.Second) if err := r.Respond(slash.Reply(fmt.Sprintf("Async response %d", i))); err != nil { return err } } return nil }
func (s *Slack) build(ctx context.Context, r slash.Responder, owner, repo, branch string) error { fullRepo := fmt.Sprintf("%s/%s", owner, repo) build, err := s.client.Build(ctx, conveyor.BuildRequest{ Repository: fullRepo, Branch: branch, }) if err != nil { return err } url, err := s.url(build) if err != nil { return err } return r.Respond(slash.Reply(fmt.Sprintf("Building %s@%s: %s", fullRepo, branch, url))) }
// Zipcode is a slash handler that returns the weather for a zip code. func Zipcode(ctx context.Context, r slash.Responder, command slash.Command) error { params := slash.Params(ctx) zip := params["zip"] return r.Respond(slash.Reply(zip)) }