oncall

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const NoHeaderKey = "no-header"

Variables

View Source
var OncallCmd = &cobra.Command{
	Use:     "on-call",
	Short:   "Get all current on calls",
	Aliases: []string{},
	Args:    cobra.MaximumNArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		client := betteruptime.NewClient()

		onCalls, err := client.GetOnCall()
		if err != nil {
			return fmt.Errorf("failed to fetch on call engineers")
		}

		body := make([][]string, 0, len(onCalls.Data))

		for _, oncallSchedules := range onCalls.Data {
			onCallUsersInSchedule := []betteruptime.UserReferences{}

			for _, ref := range oncallSchedules.Relationships.OnCallUsers.Data {
				for _, userReference := range onCalls.Included {
					if ref.Id == userReference.Id {
						onCallUsersInSchedule = append(onCallUsersInSchedule, userReference)
					}
				}
			}

			for _, userReference := range onCallUsersInSchedule {
				body = append(body, []string{
					oncallSchedules.Attributes.Name,
					fmt.Sprint(oncallSchedules.Attributes.DefaultCalendar),
					userReference.Attributes.FirstName + " " + userReference.Attributes.LastName,
					userReference.Attributes.Email,
					strings.Join(userReference.Attributes.PhoneNumbers, ","),
				})
			}
		}

		if noHeader {
			table.Print(nil, body)
		} else {
			table.Print([]string{"Schedule", "Default", "Name", "Email", "Phone"}, body)
		}
		return nil
	},
}

OncallCmd represents the get command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL