Skip to content

Commit 0ff83ef

Browse files
committed
fix: strip trailing whitespaces from gitignore.io responses
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.
1 parent 1e4b772 commit 0ff83ef

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.changelog/_unreleased.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[[entries]]
2+
id = "bf3a15ca-a70d-442e-a8bc-2092c71ac08b"
3+
type = "fix"
4+
description = "strip trailing whitespaces from gitignore.io responses"
5+
author = "@tomkarw"
6+
issues = [
7+
"https://github.com/tomkarw/kraken/issues/81",
8+
]

kraken-build/src/kraken/std/git/gitignore/gitignore_io.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ def gitignore_io_fetch(tokens: Sequence[str]) -> str:
6161
url = GITIGNORE_API_URL + ",".join(tokens)
6262
response = http.get(url)
6363
response.raise_for_status()
64-
return response.text.replace("\r\n", "\n")
64+
lines = response.text.replace("\r\n", "\n").split("\n")
65+
# gitignore.io sometimes returns files with trailing whitespaces at the end of lines
66+
# this causes issues when editors remove the whitespaces on formatting, causing autogenerated
67+
# parts of .gitignore file to change and fail kraken check
68+
lines = [line.rstrip() for line in lines]
69+
return '\n'.join(lines)
6570

6671

6772
def gitignore_io_fetch_cached(tokens: Sequence[str], backfill: bool) -> str:

0 commit comments

Comments
 (0)