-
Notifications
You must be signed in to change notification settings - Fork 74
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
Supply update result value to the commit message template #119
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It's desirable (see #6) to be able to enumerate the updates that were made by automation, in the commit message and perhaps in an event announcing success. Doing this is counter-intuitively difficult. A `kyaml.setters2.Set` filter will keep a count of the times its used. Previously, one `Set` was used with the `SetAll` flag set, which would replace any marker that corresponded to an image, in one traversal. But to keep track of images individually, you need to have a setter for _each_ image (and its tag, and its name, since those can be used separately). This means `3 x policies` traversals of each node! The saving grace, possibly, is that only files with a marker in them are considered. Since you might want to dice the results in different ways, the result returned is a nested map of file->object->image. Signed-off-by: Michael Bridgen <[email protected]>
Signed-off-by: Michael Bridgen <[email protected]>
There is a core chuck of testing that is repeated for {SSH,HTTP} x {go-git,libgit2}, which is done by repeating a func value in different contexts. Instead of mutating variables in the func's closure, it's a bit clearer (and shorter) to pass them to a higher-order func. Signed-off-by: Michael Bridgen <[email protected]>
This commit: - passes a value including the update result to the commit message template - gives the template result a method for enumerating the objects regardless of file This means you can access the images updated either by file (`.Files`), by object (`.Objects()`), or just as a list (`.Images()`). The additional test case shows how to use these. Signed-off-by: Michael Bridgen <[email protected]>
This explains the data available to the commit message template in the API guide. While writing it, I realised it could be made more convenient, so: - mask external types by embedding them - make the most useful parts of an image ref available using a wrapper struct and interface Signed-off-by: Michael Bridgen <[email protected]>
148a624
to
df7d570
Compare
Signed-off-by: Michael Bridgen <[email protected]>
After reading the API docs I don't get how to use this feature, is this intended to place a go template inside |
The message template is used in YAML files, not in go code. I've also explained up-front that it's a text template -- something not mentioned to this point. Signed-off-by: Michael Bridgen <[email protected]>
0694585
to
cfa5a9c
Compare
stefanprodan
approved these changes
Mar 4, 2021
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
Thanks @squaremo 🥇
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The effect of this PR is to give the commit message template some data to work with. Specifically: a data structure (definition given below) which holds the images updated for each object, for each file; and the name of the image automation object that created the commit.
This is the update result:
.. where the map keys are file paths and
{APIVersion, Kind, Name, Namespace}
, andname.Reference
is an image name.Here's a template that uses the result structure to print out what was updated, in different ways:
(There are methods on the Result type to make enumerating the objects and image names possible without descending into the structure.)
EDIT While writing the guide I made the template data more convenient to use (see the commit):
EDIT Not sure whether these are worth it: