Skip to content

Commit

Permalink
Added function for deleting the schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
y0rune committed Oct 29, 2022
1 parent 08d6da6 commit 69d9023
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}

0 comments on commit 69d9023

Please sign in to comment.