inject file directly
This commit is contained in:
31
utils/inject-diff.py
Executable file
31
utils/inject-diff.py
Executable file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env nix
|
||||
#! nix shell nixpkgs#python3 --command python
|
||||
import logging
|
||||
|
||||
def inject_diff():
|
||||
source_file = 'post-diff'
|
||||
target_file = 'pr_body.md'
|
||||
placeholder = "nix-diff-placeholder"
|
||||
|
||||
logging.info(f"injecting '{source_file}' into '{target_file}' using '{placeholder}' as a placeholder")
|
||||
|
||||
out = []
|
||||
with open(source_file,'r') as src:
|
||||
src_content = src.read()
|
||||
with open(target_file,'r') as tgt:
|
||||
for line in tgt.readlines():
|
||||
if placeholder in line:
|
||||
out.append(line.replace(placeholder,src_content))
|
||||
else:
|
||||
out.append(line)
|
||||
logging.info(out)
|
||||
|
||||
with open(target_file,'w') as tgt:
|
||||
tgt.writelines(out)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig( level=logging.INFO)
|
||||
inject_diff()
|
Reference in New Issue
Block a user