Skip to content

Commit

Permalink
add inherit command
Browse files Browse the repository at this point in the history
  • Loading branch information
seletskiy committed Oct 20, 2020
1 parent affd74d commit 63e3fd8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ func (api *API) DisableHook(project, repository, key string) error {
return err
}

func (api *API) InheritHook(project, repository, key string) error {
_, err := request(
"DELETE",
api.sub(project, repository).Res("settings").
Res("hooks").Res(key),
)

return err
}

func (api *API) SetHookSettings(project, repository, key string, settings *HookSettings) error {
_, err := request(
"PUT",
Expand Down
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Usage:
bitbucket-external-hook [options] print -b <bitbucket-uri> -p <project> [-r <repo>] <hook>
bitbucket-external-hook [options] enable -b <bitbucket-uri> -p <project> [-r <repo>] <hook>
bitbucket-external-hook [options] disable -b <bitbucket-uri> -p <project> [-r <repo>] <hook>
bitbucket-external-hook [options] inherit -b <bitbucket-uri> -p <project> [-r <repo>] <hook>
bitbucket-external-hook [options] set -b <bitbucket-uri> -p <project> [-r <repo>] <hook> [-e <path>] [-s] [<param>...]
bitbucket-external-hook count -b <bitbucket-uri> [--debug] [<hook>]
bitbucket-external-hook -h | --help
Expand Down Expand Up @@ -54,6 +55,7 @@ type (
Print bool
Enable bool
Disable bool
Inherit bool

Set bool
Executable string
Expand Down Expand Up @@ -98,6 +100,8 @@ func main() {
err = handleEnable(api, opts)
case opts.Disable:
err = handleDisable(api, opts)
case opts.Inherit:
err = handleInherit(api, opts)
case opts.Set:
err = handleSet(api, opts)
case opts.Count:
Expand Down Expand Up @@ -153,6 +157,18 @@ func handleDisable(api *API, opts Options) error {
return nil
}

func handleInherit(api *API, opts Options) error {
err := api.InheritHook(opts.Project, opts.Repository, opts.Hook)
if err != nil {
return karma.Format(
err,
"unable to enable hook",
)
}

return nil
}

func handlePrint(api *API, opts Options) error {
hook, err := api.GetHook(opts.Project, opts.Repository, opts.Hook)
if err != nil {
Expand Down

0 comments on commit 63e3fd8

Please sign in to comment.