Skip to content

Commit

Permalink
Tag @team within working hours
Browse files Browse the repository at this point in the history
  • Loading branch information
arnested committed Jul 17, 2019
1 parent d10017e commit b610bfe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
33 changes: 33 additions & 0 deletions webhook/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"log"
"net/http"
"os"
"time"

"github.com/rickar/cal"
"github.com/wm/go-flowdock/flowdock"
"gopkg.in/go-playground/webhooks.v5/github"
)
Expand Down Expand Up @@ -88,6 +90,10 @@ func Handle(w http.ResponseWriter, r *http.Request) {
pullRequest.PullRequest.User.Login,
)

if withinWorkingHours() {
str = fmt.Sprintf("@team, %s", str)
}

err = flowpost(str)

if err != nil {
Expand Down Expand Up @@ -143,3 +149,30 @@ func flowpost(msg string) error {

return err
}

func withinWorkingHours() bool {
c := workCalendar()
now := time.Now()

if !c.IsWorkday(now) {
return false
}

if (now.Hour() < 8) || (now.Hour() > 17) {
return false
}

return true
}

func workCalendar() *cal.Calendar {
c := cal.NewCalendar()

cal.AddDanishHolidays(c)
c.AddHoliday(
cal.DKJuleaften,
cal.DKNytaarsaften,
)

return c
}
1 change: 1 addition & 0 deletions webhook/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.11
require (
github.com/bernerdschaefer/eventsource v0.0.0-20130606115634-220e99a79763 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/rickar/cal v1.0.1
github.com/stretchr/testify v1.3.0 // indirect
github.com/wm/go-flowdock v0.0.0-20171019142228-93c0a78fc14f
gopkg.in/go-playground/webhooks.v5 v5.12.0
Expand Down
2 changes: 2 additions & 0 deletions webhook/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASu
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rickar/cal v1.0.1 h1:Tyjkk4sBvVC3gcXCgLowEM53R2eVfFcoi1gtQuocrmk=
github.com/rickar/cal v1.0.1/go.mod h1:3GBx8OBrvh4/y/JTxM0e1bUUIHMnqILl1rMANHWExxQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down

0 comments on commit b610bfe

Please sign in to comment.