Repository navigation
String substitution in scmOverrides replace - #720
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #720 +/- ##
=======================================
Coverage 89.89% 89.89%
=======================================
Files 50 50
Lines 16897 16901 +4
=======================================
+ Hits 15189 15193 +4
Misses 1708 1708 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jkloetzke
left a comment
There was a problem hiding this comment.
Could you give a use case where this is needed? So far I've never came across the need to replace things in overrides dynamically...
| substitution is applied to the regular expression before it is compiled. A | ||
| literal ``$`` in a ``pattern`` (e.g. the end-of-string anchor) must | ||
| therefore be escaped as ``\$``. Be aware that YAML double quoted strings | ||
| interpret backslashes themselves, so write ``'^.*\$'`` (single quotes) or | ||
| ``"^.*\\$"``. |
There was a problem hiding this comment.
This is exactly why I don't think this is something that should be enabled by default. Writing a regex pattern or replacement (with back references) is already hard enough in Yaml. Additionally substituting the pattern and replacement by Bob makes it very hard to use. How about making this a per-override setting (e.g. replaceSubst: True)?
Ok, I can understand why it might be weird for match:
url: "https://awesometools.org/tools/*"
replace:
url:
pattern: "https://awesometools.org/"
replacement: "${INTERNAL_MIRROR}/awesometools/"for pattern, maybe the following is a bit of an artificial usecase: match:
url: "${GNU_MIRROR}/{tool_a, tool_b}/*"
replace:
url:
pattern: "${GNU_MIRROR}"
replacement: "${INTERNAL_MIRROR}/some_awesome_tools/"
match:
url: "${GNU_MIRROR}/*/*"
replace:
url:
pattern: "${GNU_MIRROR}"
replacement: "${INTERNAL_MIRROR}/other_place_for_awesome_tools/"Not sure if this is 100% valid. I would agree to making string substitution for pattern configurable, but replacement should always have this. |
pattern and replacement will now be subject to string substitution, if the per override setting `substituteReplace` is set to True. default is False to keep the old behaviour. dropped the eager early __init in scm.py. __applyEnv now substitutes `pattern` and `replacement` and then compiles the regexes.
d6ba6b2 to
b046116
Compare
Ok, I have used the per override setting for |
|
Thanks for giving the rationale. LGTM. |
string substitution was not available for
replacein scmOverrides.since it can break some old overrides, it is hidded behind a new policy flag.