Пример #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
}
Пример #2
0
// CreateHook is a helper function that creates a post-commit hook
// for the specified repository.
func CreateHook(client *github.Client, owner, name, url string) (*github.Hook, error) {
	var hook = new(github.Hook)
	hook.Name = github.String("web")
	hook.Events = []string{"issue_comment", "status", "pull_request"}
	hook.Config = map[string]interface{}{}
	hook.Config["url"] = url
	hook.Config["content_type"] = "json"
	created, _, err := client.Repositories.CreateHook(owner, name, hook)
	return created, err
}
Пример #3
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
}