-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hooks: include plugin name in hook data #5030
Conversation
71fe473
to
7bcce0b
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #5030 +/- ##
==========================================
+ Coverage 61.05% 61.10% +0.05%
==========================================
Files 295 295
Lines 20647 20656 +9
==========================================
+ Hits 12605 12621 +16
+ Misses 7146 7138 -8
- Partials 896 897 +1 |
7bcce0b
to
6a1d249
Compare
I yet have to dive into the changes in this PR, but wondering if there's cases where "global" flags could cause issues, e.g. |
It operates on the args already processed by cobra, so it also works fine with global flags. |
6a1d249
to
975696c
Compare
Before, for plugin commands, only the plugin name (such as `buildx`) would be both included as `RootCmd` when passed to the hook plugin, which isn't enough information for a plugin to decide whether to execute a hook or not since plugins implement multiple varied commands (`buildx build`, `buildx prune`, etc.). This commit changes the hook logic to account for this situation, so that the the entire configured hook is passed, i.e., if a user has a hook configured for `buildx imagetools inspect` and the command `docker buildx imagetools inspect alpine` is called, then the plugin hooks will be passed `buildx imagetools inspect`. This logic works for aliased commands too, so whether `docker build ...` or `docker buildx build` is executed (unless Buildx is disabled) the hook will be invoked with `buildx build`. Signed-off-by: Laura Brehm <laurabrehm@hey.com> hooks: include full match when invoking plugins Signed-off-by: Laura Brehm <laurabrehm@hey.com>
975696c
to
9d8320d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
- What I did
Before, for plugin commands, only the plugin name (such as
buildx
) would be included inRootCmd
when passed to the hook plugin, which isn't enough information for a plugin to decide whether to execute a hook or not since plugins implement multiple varied commands (buildx build
,buildx prune
, etc.).- How I did it
This commit changes the hook logic to account for this situation, so that both the plugin name and base command will get passed (separated by a SPACE, such as
buildx prune
).This logic works for aliased commands too, so whether
docker build ...
ordocker buildx build
is executed (unless Buildx is disabled) the hook will be invoked withbuildx build
.- A picture of a cute animal (not mandatory but encouraged)