diff --git a/.changelog/_unreleased.toml b/.changelog/_unreleased.toml new file mode 100644 index 00000000..0050f85b --- /dev/null +++ b/.changelog/_unreleased.toml @@ -0,0 +1,8 @@ +[[entries]] +id = "bf3a15ca-a70d-442e-a8bc-2092c71ac08b" +type = "fix" +description = "strip trailing whitespaces from gitignore.io responses" +author = "@tomkarw" +issues = [ + "https://github.com/tomkarw/kraken/issues/81", +] diff --git a/kraken-build/src/kraken/std/git/gitignore/gitignore_io.py b/kraken-build/src/kraken/std/git/gitignore/gitignore_io.py index e5c98462..cc0cca9d 100644 --- a/kraken-build/src/kraken/std/git/gitignore/gitignore_io.py +++ b/kraken-build/src/kraken/std/git/gitignore/gitignore_io.py @@ -61,7 +61,12 @@ def gitignore_io_fetch(tokens: Sequence[str]) -> str: url = GITIGNORE_API_URL + ",".join(tokens) response = http.get(url) response.raise_for_status() - return response.text.replace("\r\n", "\n") + lines = response.text.replace("\r\n", "\n").split("\n") + # gitignore.io sometimes returns files with trailing whitespaces at the end of lines + # this causes issues when editors remove the whitespaces on formatting, causing autogenerated + # parts of .gitignore file to change and fail kraken check + lines = [line.rstrip() for line in lines] + return "\n".join(lines) def gitignore_io_fetch_cached(tokens: Sequence[str], backfill: bool) -> str: