nix-dotfiles/utils/inject-diff.py
ahuston-0 95620e20cc
All checks were successful
Check flake.lock / Check health of `flake.lock` (pull_request) Successful in 42s
Check Nix formatting / Perform Nix format checks (pull_request) Successful in 3m24s
Check Nix flake / Perform Nix flake checks (pull_request) Successful in 6m12s
truncate diff if longer than 60k
2025-05-27 10:57:12 -04:00

34 lines
959 B
Python
Executable File

#!/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()
if len(src_content) > 60000:
logging.warning(f"{source_file} is longer than 60k characters, truncating")
src_content = src_content[:60000]
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)
with open(target_file,'w') as tgt:
tgt.writelines(out)
if __name__ == "__main__":
logging.basicConfig( level=logging.INFO)
inject_diff()