Exemple #1
1
func runCreateCmd(cmd *commander.Command, args []string) error {
	if err := validateSubUsage(cmd, args); err != nil {
		return err
	}
	c, err := Client()
	if err != nil {
		return err
	}
	hookSchema, _, err := GetHookSchema(c, args[2])
	if err != nil {
		return err
	}

	hook := new(github.Hook)
	hook.Name = hookSchema.Name

	active := true
	hook.Active = &active

	events := make([]string, 0)
	for _, event := range hookSchema.Events {
		events = append(events, event)
	}
	hook.Events = events

	hook.Config = make(map[string]interface{})

	newHook, err := edit(
		hook,
		hookSchema,
	)

	if err != nil {
		return err
	}

	if _, _, err := c.Repositories.CreateHook(args[0], args[1], newHook); err != nil {
		return err
	}

	return nil
}
Exemple #2
0
func createHookFromToml(reader io.Reader) (*github.Hook, error) {
	tomlHook := new(TomlHook)
	if _, err := toml.DecodeReader(reader, tomlHook); err != nil {
		return nil, err
	}

	hook := new(github.Hook)
	if tomlHook.Name != nil {
		hook.Name = tomlHook.Name
	}
	if tomlHook.Active != nil {
		hook.Active = tomlHook.Active
	}
	if tomlHook.Events != nil {
		hook.Events = tomlHook.Events
	}
	if tomlHook.Config != nil {
		hook.Config = tomlHook.Config
	}

	return hook, nil
}