Skip to content

Commit

Permalink
feat: allow this to work with a cron schedule (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
garethjevans authored Mar 30, 2021
1 parent 9f36f39 commit 2e5bbb7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,26 @@ func main() {

log.Printf("Trigger event: %s", os.Getenv("GITHUB_EVENT_NAME"))

err = newLabeler(gh, config).HandleEvent(eventName, eventPayload)
if err != nil {
log.Printf("Unable to execute action: %+v", err)
l := newLabeler(gh, config)

if eventName == "schedule" {
t := strings.Split(os.Getenv("GITHUB_REPOSITORY"), "/")
owner, repoName := t[0], t[1]

prs, _, err := gh.PullRequests.List(context.Background(), owner, repoName, &github.PullRequestListOptions{})
if err != nil {
return
}

for _, pr := range prs {
err = l.ExecuteOn(pr)
log.Printf("Unable to execute action: %+v", err)
}
} else {
err = l.HandleEvent(eventName, eventPayload)
if err != nil {
log.Printf("Unable to execute action: %+v", err)
}
}

}
Expand Down
4 changes: 2 additions & 2 deletions pkg/labeler.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ func (l *Labeler) HandleEvent(
}
switch event := event.(type) {
case *gh.PullRequestEvent:
err = l.executeOn(event.PullRequest)
err = l.ExecuteOn(event.PullRequest)
}
return err
}

func (l *Labeler) executeOn(pr *gh.PullRequest) error {
func (l *Labeler) ExecuteOn(pr *gh.PullRequest) error {
owner := pr.Base.Repo.GetOwner().GetLogin()
repoName := *pr.Base.Repo.Name

Expand Down

0 comments on commit 2e5bbb7

Please sign in to comment.