Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4 from thepwagner/repository-dispatch
Browse files Browse the repository at this point in the history
Repository dispatch
  • Loading branch information
Pete Wagner authored Oct 8, 2020
2 parents 6ff699c + 0b91405 commit c563fea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
17 changes: 13 additions & 4 deletions actions/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
)

type Handlers struct {
IssueComment func(context.Context, *github.IssueCommentEvent) error
PullRequest func(context.Context, *github.PullRequestEvent) error
Schedule func(context.Context) error
WorkflowDispatch func(context.Context) error
IssueComment func(context.Context, *github.IssueCommentEvent) error
PullRequest func(context.Context, *github.PullRequestEvent) error
RepositoryDispatch func(context.Context, *github.RepositoryDispatchEvent) error
Schedule func(context.Context) error
WorkflowDispatch func(context.Context) error
}

// Handle invokes the appropriate handler for an given actions Environment.
Expand Down Expand Up @@ -72,6 +73,14 @@ func (h *Handlers) handler(event string) func(context.Context, interface{}) erro
return h.PullRequest(ctx, evt.(*github.PullRequestEvent))
}

case "repository_dispatch":
if h.RepositoryDispatch == nil {
return nil
}
return func(ctx context.Context, evt interface{}) error {
return h.RepositoryDispatch(ctx, evt.(*github.RepositoryDispatchEvent))
}

case "schedule":
if h.Schedule == nil {
return nil
Expand Down
12 changes: 9 additions & 3 deletions actions/updateaction/handlers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package updateaction

import (
"context"

"github.com/go-git/go-git/v5"
"github.com/google/go-github/v32/github"
"github.com/thepwagner/action-update/actions"
gitrepo "github.com/thepwagner/action-update/repo"
"github.com/thepwagner/action-update/updater"
Expand All @@ -16,9 +19,12 @@ type HandlerParams interface {
func NewHandlers(p HandlerParams) *actions.Handlers {
h := &handler{cfg: p.env(), updaterFactory: p}
return &actions.Handlers{
IssueComment: IssueComment,
PullRequest: h.PullRequest,
Schedule: h.UpdateAll,
IssueComment: IssueComment,
PullRequest: h.PullRequest,
Schedule: h.UpdateAll,
RepositoryDispatch: func(ctx context.Context, _ *github.RepositoryDispatchEvent) error {
return h.UpdateAll(ctx)
},
WorkflowDispatch: h.UpdateAll,
}
}
Expand Down

0 comments on commit c563fea

Please sign in to comment.