From d31aaac18f311f3ce38b2f1f8f2edb44f15343a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 29 Oct 2022 15:28:09 +0200 Subject: [PATCH 01/14] Updated the dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak go: upgraded github.com/hashicorp/go-cleanhttp v0.5.0 => v0.5.2 go: upgraded github.com/hashicorp/go-retryablehttp v0.5.1 => v0.7.1 go: upgraded github.com/konsorten/go-windows-terminal-sequences v1.0.1 => v1.0.3 go: upgraded github.com/pkg/errors v0.8.1 => v0.9.1 go: upgraded github.com/sirupsen/logrus v1.4.2 => v1.9.0 --- go.mod | 10 +++++----- go.sum | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 69921bb..d0c6377 100644 --- a/go.mod +++ b/go.mod @@ -5,10 +5,10 @@ go 1.19 require github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.13 require ( - github.com/hashicorp/go-cleanhttp v0.5.0 // indirect - github.com/hashicorp/go-retryablehttp v0.5.1 // indirect - github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect - github.com/pkg/errors v0.8.1 // indirect - github.com/sirupsen/logrus v1.4.2 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-retryablehttp v0.7.1 // indirect + github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/sirupsen/logrus v1.9.0 // indirect golang.org/x/sys v0.1.0 // indirect ) diff --git a/go.sum b/go.sum index 9ac799c..d56ad1b 100644 --- a/go.sum +++ b/go.sum @@ -3,29 +3,45 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-retryablehttp v0.5.1 h1:Vsx5XKPqPs3M6sM4U4GWyUqFS8aBiL9U5gkgvpkg4SE= github.com/hashicorp/go-retryablehttp v0.5.1/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= +github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ= +github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= +github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.13 h1:nV98dkBpqaYbDnhefmOQ+Rn4hE+jD6AtjYHXaU5WyJI= github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.13/go.mod h1:4OjcxgwdXzezqytxN534MooNmrxRD50geWZxTD7845s= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From e2f4bade6c336464d2b8a786fe2afc50a23936f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 29 Oct 2022 18:29:44 +0200 Subject: [PATCH 02/14] Updated the README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a0ae9fd..83e540c 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ go get ### How to use it in the console? ```bash -go run main.go --apiKey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --scheduleName "YEAR_2023" --scheduleYear 2023 +go run main.go --apiKey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --scheduleTeam TestTeam --scheduleName "YEAR_2023" --scheduleYear 2023 ``` ### Output console From 67549e7b05c85b80a50eaa9bffc8c3a7ca4ebc31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 29 Oct 2022 18:32:27 +0200 Subject: [PATCH 03/14] Added the value `defaultSchedule` instead of the values in the function --- main.go | 87 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/main.go b/main.go index 70f9e78..c736b54 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,48 @@ var startMinuteWorkWeek uint32 = 0 var endHourWorkWeek uint32 = 9 var endMinWorkWeek uint32 = 0 +var defaultSchedule = [...]og.Restriction{ + { + StartDay: "monday", + EndDay: "tuesday", + EndHour: &endHourWorkWeek, + EndMin: &endMinWorkWeek, + StartHour: &startHourWorkWeek, + StartMin: &startMinuteWorkWeek, + }, + { + StartDay: "tuesday", + EndDay: "wednesday", + EndHour: &endHourWorkWeek, + EndMin: &endMinWorkWeek, + StartHour: &startHourWorkWeek, + StartMin: &startMinuteWorkWeek, + }, + { + StartDay: "wednesday", + EndDay: "thursday", + EndHour: &endHourWorkWeek, + EndMin: &endMinWorkWeek, + StartHour: &startHourWorkWeek, + StartMin: &startMinuteWorkWeek, + }, + { + StartDay: "thursday", + EndDay: "friday", + EndHour: &endHourWorkWeek, + EndMin: &endMinWorkWeek, + StartHour: &startHourWorkWeek, + StartMin: &startMinuteWorkWeek, + }, + { + StartDay: "friday", + EndDay: "monday", + EndHour: &endHourWorkWeek, + EndMin: &endMinWorkWeek, + StartHour: &startHourWorkWeek, + StartMin: &startMinuteWorkWeek, + }, +} func getFirstMonday(year int, month time.Month) int { t := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC) firstMonday := ((8-int(t.Weekday()))%7 + 1) @@ -70,49 +112,8 @@ func restrictionCreator(scheduleClient schedule.Client, scheduleName string, yea }, }, TimeRestriction: &og.TimeRestriction{ - Type: og.WeekdayAndTimeOfDay, - RestrictionList: []og.Restriction{ - { - StartDay: "monday", - EndDay: "tuesday", - EndHour: &endHourWorkWeek, - EndMin: &endMinWorkWeek, - StartHour: &startHourWorkWeek, - StartMin: &startMinuteWorkWeek, - }, - { - StartDay: "tuesday", - EndDay: "wednesday", - EndHour: &endHourWorkWeek, - EndMin: &endMinWorkWeek, - StartHour: &startHourWorkWeek, - StartMin: &startMinuteWorkWeek, - }, - { - StartDay: "wednesday", - EndDay: "thursday", - EndHour: &endHourWorkWeek, - EndMin: &endMinWorkWeek, - StartHour: &startHourWorkWeek, - StartMin: &startMinuteWorkWeek, - }, - { - StartDay: "thursday", - EndDay: "friday", - EndHour: &endHourWorkWeek, - EndMin: &endMinWorkWeek, - StartHour: &startHourWorkWeek, - StartMin: &startMinuteWorkWeek, - }, - { - StartDay: "friday", - EndDay: "monday", - EndHour: &endHourWorkWeek, - EndMin: &endMinWorkWeek, - StartHour: &startHourWorkWeek, - StartMin: &startMinuteWorkWeek, - }, - }, + Type: og.WeekdayAndTimeOfDay, + RestrictionList: defaultSchedule[:], }, }, ScheduleIdentifierType: schedule.Name, From 76f8fcb79050c5d52629f7e345300c46e2641323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 29 Oct 2022 18:33:03 +0200 Subject: [PATCH 04/14] Changed the `scheduleEnabled` to `scheduleEnabledFlag` --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index c736b54..e4e7935 100644 --- a/main.go +++ b/main.go @@ -72,11 +72,11 @@ func getNumberOfWeeks(year int, month time.Month) int { return numberOfWeeks } -func scheduleCreator(scheduleClient schedule.Client, scheduleName string, scheduleTimezone string, scheduleTeam string, scheduleEnabled bool) schedule.CreateResult { +func scheduleCreator(scheduleClient schedule.Client, scheduleName string, scheduleTimezone string, scheduleTeam string, scheduleEnabledFlag bool) schedule.CreateResult { scheduleResult, err := scheduleClient.Create(nil, &schedule.CreateRequest{ Name: scheduleName, Timezone: scheduleTimezone, - Enabled: &scheduleEnabled, + Enabled: &scheduleEnabledFlag, OwnerTeam: &og.OwnerTeam{ Name: scheduleTeam, }, @@ -131,7 +131,7 @@ func main() { scheduleTimezone := flag.String("scheduleTimezone", "Europe/Warsaw", "# Timezone of the schedule") scheduleTeam := flag.String("scheduleTeam", "TestTeam", "# Name of the team in the schedule") scheduleYear := flag.Int("scheduleYear", 2022, "# Year of the schedule") - scheduleEnabled := flag.Bool("scheduleEnabled", true, "# Schedule is enabled") + scheduleEnabledFlag := flag.Bool("scheduleEnabledFlag", true, "# Schedule is enabled") flag.Parse() if (*apiKey == "") || (apiKey == nil) { From 08d6da62c1324b1c6a06493ea4c7b18007f0e33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 29 Oct 2022 18:33:44 +0200 Subject: [PATCH 05/14] Changed the output of the errors --- main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index e4e7935..aaa1890 100644 --- a/main.go +++ b/main.go @@ -83,7 +83,9 @@ func scheduleCreator(scheduleClient schedule.Client, scheduleName string, schedu }) if err != nil { - fmt.Printf("Error in scheduleCreator create: %d", err) + fmt.Printf("Schedule %s with id: %s has been NOT created. Error: %d \n", scheduleResult.Name, scheduleResult.Id, err) + } else { + fmt.Printf("Schedule %s with id: %s has been created.\n", scheduleResult.Name, scheduleResult.Id) } return *scheduleResult From 69d9023594f3001daaea124e00adcda57ffe9cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 29 Oct 2022 18:34:22 +0200 Subject: [PATCH 06/14] Added function for deleting the schedule --- main.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index aaa1890..2671be2 100644 --- a/main.go +++ b/main.go @@ -126,14 +126,27 @@ func restrictionCreator(scheduleClient schedule.Client, scheduleName string, yea } } -func main() { +func deleteSchedule(scheduleClient schedule.Client, scheduleID string) { + _, err := scheduleClient.Delete(nil, &schedule.DeleteRequest{ + IdentifierType: schedule.Id, + IdentifierValue: scheduleID, + }) + if err != nil { + fmt.Printf("Schedule %s has been NOT deleted.\n", scheduleID) + } else { + fmt.Printf("Schedule %s has been deleted.\n", scheduleID) + } +} + +func main() { apiKey := flag.String("apiKey", "", "# ApiKey for use in that script") scheduleName := flag.String("scheduleName", "Test Schedule", "# Name of schedule") scheduleTimezone := flag.String("scheduleTimezone", "Europe/Warsaw", "# Timezone of the schedule") scheduleTeam := flag.String("scheduleTeam", "TestTeam", "# Name of the team in the schedule") scheduleYear := flag.Int("scheduleYear", 2022, "# Year of the schedule") scheduleEnabledFlag := flag.Bool("scheduleEnabledFlag", true, "# Schedule is enabled") + delete := flag.Bool("delete", false, "# Delete schedule ") flag.Parse() if (*apiKey == "") || (apiKey == nil) { @@ -147,8 +160,14 @@ func main() { if err != nil { fmt.Printf("Error in scheduleClient create: %d", err) + if *delete && *scheduleName == "TestSchedule" && *scheduleID != "XXXXXXXXXXXXXXX" { + deleteSchedule(*scheduleClient, *scheduleID) } createdSchedule := scheduleCreator(*scheduleClient, *scheduleName, *scheduleTimezone, *scheduleTeam, *scheduleEnabled) restrictionCreator(*scheduleClient, createdSchedule.Name, *scheduleYear) + if *delete { + scheduleID = &createdSchedule.Id + deleteSchedule(*scheduleClient, *scheduleID) + } } From 3af07bee9e6904f21b9aff542aeda644a41a0eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 29 Oct 2022 18:34:59 +0200 Subject: [PATCH 07/14] Added function for creating schedule.Client --- main.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 2671be2..82f85ac 100644 --- a/main.go +++ b/main.go @@ -58,6 +58,24 @@ var defaultSchedule = [...]og.Restriction{ StartMin: &startMinuteWorkWeek, }, } + +func createApi(apiKey string) *schedule.Client { + if apiKey == "" { + fmt.Printf("Empty apiKey... Please use -apiKey \n") + os.Exit(1) + } + + scheduleClient, err := schedule.NewClient(&client.Config{ + ApiKey: apiKey, + }) + + if err != nil { + fmt.Printf("Error in scheduleClient create: %d", err) + } + + return scheduleClient +} + func getFirstMonday(year int, month time.Month) int { t := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC) firstMonday := ((8-int(t.Weekday()))%7 + 1) @@ -149,17 +167,8 @@ func main() { delete := flag.Bool("delete", false, "# Delete schedule ") flag.Parse() - if (*apiKey == "") || (apiKey == nil) { - fmt.Printf("Empty apiKey... Please use -apiKey \n") - os.Exit(1) - } + scheduleClient := createApi(*apiKey) - scheduleClient, err := schedule.NewClient(&client.Config{ - ApiKey: *apiKey, - }) - - if err != nil { - fmt.Printf("Error in scheduleClient create: %d", err) if *delete && *scheduleName == "TestSchedule" && *scheduleID != "XXXXXXXXXXXXXXX" { deleteSchedule(*scheduleClient, *scheduleID) } From 0dcfbd7ff51015b9906d2f334bcfa480ddcb19a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 29 Oct 2022 18:35:33 +0200 Subject: [PATCH 08/14] Added new values --- main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 82f85ac..5c52c91 100644 --- a/main.go +++ b/main.go @@ -160,6 +160,7 @@ func deleteSchedule(scheduleClient schedule.Client, scheduleID string) { func main() { apiKey := flag.String("apiKey", "", "# ApiKey for use in that script") scheduleName := flag.String("scheduleName", "Test Schedule", "# Name of schedule") + scheduleID := flag.String("scheduleID", "XXXXXXXXXXXXXXX", "# ID of schedule") scheduleTimezone := flag.String("scheduleTimezone", "Europe/Warsaw", "# Timezone of the schedule") scheduleTeam := flag.String("scheduleTeam", "TestTeam", "# Name of the team in the schedule") scheduleYear := flag.Int("scheduleYear", 2022, "# Year of the schedule") @@ -173,8 +174,9 @@ func main() { deleteSchedule(*scheduleClient, *scheduleID) } - createdSchedule := scheduleCreator(*scheduleClient, *scheduleName, *scheduleTimezone, *scheduleTeam, *scheduleEnabled) + createdSchedule := scheduleCreator(*scheduleClient, *scheduleName, *scheduleTimezone, *scheduleTeam, *scheduleEnabledFlag) restrictionCreator(*scheduleClient, createdSchedule.Name, *scheduleYear) + if *delete { scheduleID = &createdSchedule.Id deleteSchedule(*scheduleClient, *scheduleID) From d8180532d5852f13ef488ce0255b1a8c8d59773e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 29 Oct 2022 18:45:48 +0200 Subject: [PATCH 09/14] Updated README --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 83e540c..6d59488 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,12 @@ go get ``` -apiKey string # ApiKey for use in that script - -scheduleEnabled + -delete + # Delete schedule + -scheduleEnabledFlag # Schedule is enabled (default true) + -scheduleID string + # ID of schedule (default "XXXXXXXXXXXXXXX") -scheduleName string # Name of schedule (default "Test Schedule") -scheduleTeam string From 10df0832f50451425994ad2e89181bebe808ec47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 29 Oct 2022 19:58:10 +0200 Subject: [PATCH 10/14] Misspelt in the equals value --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 5c52c91..82a4a58 100644 --- a/main.go +++ b/main.go @@ -170,7 +170,7 @@ func main() { scheduleClient := createApi(*apiKey) - if *delete && *scheduleName == "TestSchedule" && *scheduleID != "XXXXXXXXXXXXXXX" { + if *delete && *scheduleName == "Test Schedule" && *scheduleID != "XXXXXXXXXXXXXXX" { deleteSchedule(*scheduleClient, *scheduleID) } From 8963ed26d35f009785e3d3ce23e0af58c52edf33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 29 Oct 2022 21:03:02 +0200 Subject: [PATCH 11/14] Changed the `scheduleName` to `scheduleID` (better using is a ID) --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 82a4a58..9c08945 100644 --- a/main.go +++ b/main.go @@ -136,8 +136,8 @@ func restrictionCreator(scheduleClient schedule.Client, scheduleName string, yea RestrictionList: defaultSchedule[:], }, }, - ScheduleIdentifierType: schedule.Name, - ScheduleIdentifierValue: scheduleName, + ScheduleIdentifierType: schedule.Id, + ScheduleIdentifierValue: scheduleID, }) fmt.Printf("Rotation %s has been created for schedule %s.\n", weekName, scheduleName) @@ -175,7 +175,7 @@ func main() { } createdSchedule := scheduleCreator(*scheduleClient, *scheduleName, *scheduleTimezone, *scheduleTeam, *scheduleEnabledFlag) - restrictionCreator(*scheduleClient, createdSchedule.Name, *scheduleYear) + restrictionCreator(*scheduleClient, createdSchedule.Id, *scheduleYear) if *delete { scheduleID = &createdSchedule.Id From faace86b2a4c93c474247a50e1d2d5c856649a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sat, 29 Oct 2022 21:03:25 +0200 Subject: [PATCH 12/14] Added function `getListRotation` function --- main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/main.go b/main.go index 9c08945..069f3e9 100644 --- a/main.go +++ b/main.go @@ -157,6 +157,19 @@ func deleteSchedule(scheduleClient schedule.Client, scheduleID string) { } } +func getListRotation(scheduleClient schedule.Client, scheduleID string) *schedule.ListRotationsResult { + scheduleResult, err := scheduleClient.ListRotations(nil, &schedule.ListRotationsRequest{ + ScheduleIdentifierType: schedule.Id, + ScheduleIdentifierValue: scheduleID, + }) + + if err != nil { + fmt.Printf("Schedule %s can not be get.\n", scheduleID) + os.Exit(1) + } + return scheduleResult +} + func main() { apiKey := flag.String("apiKey", "", "# ApiKey for use in that script") scheduleName := flag.String("scheduleName", "Test Schedule", "# Name of schedule") From d8b7e215c13653ad161904b8133d17d479eda7f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sun, 30 Oct 2022 00:10:53 +0200 Subject: [PATCH 13/14] Changes in the function `restrictionCreator` --- main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 069f3e9..a1deced 100644 --- a/main.go +++ b/main.go @@ -109,7 +109,7 @@ func scheduleCreator(scheduleClient schedule.Client, scheduleName string, schedu return *scheduleResult } -func restrictionCreator(scheduleClient schedule.Client, scheduleName string, year int) { +func restrictionCreator(scheduleClient schedule.Client, scheduleID string, year int) { month := time.Month(1) firstMonday := getFirstMonday(year, month) numberOfWeeks := getNumberOfWeeks(year, month) @@ -120,7 +120,7 @@ func restrictionCreator(scheduleClient schedule.Client, scheduleName string, yea nextMonday = nextMonday.AddDate(0, 0, 7) weekName := fmt.Sprintf("w%d-%d.%d-%d.%d", week, monday.Day(), monday.Month(), nextMonday.Day(), nextMonday.Month()) - scheduleClient.CreateRotation(nil, &schedule.CreateRotationRequest{ + _, err := scheduleClient.CreateRotation(nil, &schedule.CreateRotationRequest{ Rotation: &og.Rotation{ Name: weekName, StartDate: &monday, @@ -140,7 +140,11 @@ func restrictionCreator(scheduleClient schedule.Client, scheduleName string, yea ScheduleIdentifierValue: scheduleID, }) - fmt.Printf("Rotation %s has been created for schedule %s.\n", weekName, scheduleName) + if err != nil { + fmt.Printf("Rotation %s has been NOT created for schedule %s.\n", weekName, scheduleID) + } else { + fmt.Printf("Rotation %s has been created for schedule %s.\n", weekName, scheduleID) + } } } From fc27fc3abc1cc83261d27108b42d0959c9e3f791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sun, 30 Oct 2022 00:13:24 +0200 Subject: [PATCH 14/14] Run the prieetier --- main.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index a1deced..74541a5 100644 --- a/main.go +++ b/main.go @@ -71,6 +71,7 @@ func createApi(apiKey string) *schedule.Client { if err != nil { fmt.Printf("Error in scheduleClient create: %d", err) + os.Exit(1) } return scheduleClient @@ -102,6 +103,7 @@ func scheduleCreator(scheduleClient schedule.Client, scheduleName string, schedu if err != nil { fmt.Printf("Schedule %s with id: %s has been NOT created. Error: %d \n", scheduleResult.Name, scheduleResult.Id, err) + os.Exit(1) } else { fmt.Printf("Schedule %s with id: %s has been created.\n", scheduleResult.Name, scheduleResult.Id) } @@ -163,13 +165,12 @@ func deleteSchedule(scheduleClient schedule.Client, scheduleID string) { func getListRotation(scheduleClient schedule.Client, scheduleID string) *schedule.ListRotationsResult { scheduleResult, err := scheduleClient.ListRotations(nil, &schedule.ListRotationsRequest{ - ScheduleIdentifierType: schedule.Id, - ScheduleIdentifierValue: scheduleID, + ScheduleIdentifierType: schedule.Id, + ScheduleIdentifierValue: scheduleID, }) if err != nil { fmt.Printf("Schedule %s can not be get.\n", scheduleID) - os.Exit(1) } return scheduleResult }