mirror of
https://github.com/open-goal/jak-project
synced 2026-07-07 06:05:15 -04:00
CI: check for removed goal_src code that we want or need to perserve (#2987)
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# Gets the diff between this PR and `origin/master`
|
||||
# If there are any 'og:preserve-this' lines removed, the script returns 1
|
||||
|
||||
import unidiff
|
||||
from colorama import Fore
|
||||
|
||||
with open("lint-changes.diff", encoding="utf-8") as f:
|
||||
diff = f.read()
|
||||
|
||||
patch_set = unidiff.PatchSet.from_string(diff)
|
||||
|
||||
flagged_deletions = []
|
||||
|
||||
for patched_file in patch_set:
|
||||
file_path = patched_file.path
|
||||
for hunk in patched_file:
|
||||
for line in hunk:
|
||||
if line.is_removed and "og:preserve-this" in line.value.strip():
|
||||
flagged_deletions.append(
|
||||
{
|
||||
"file": file_path,
|
||||
"line_num": line.source_line_no,
|
||||
"deletion": line.value.strip(),
|
||||
}
|
||||
)
|
||||
|
||||
print(flagged_deletions)
|
||||
|
||||
if len(flagged_deletions) > 0:
|
||||
print(
|
||||
Fore.RED
|
||||
+ "Flagged goal_src code has been deleted, either you made a mistake or you better know what you're doing!" + Fore.RESET
|
||||
)
|
||||
for flagged_deletion in flagged_deletions:
|
||||
print(
|
||||
" - {}{}{}:{}{}{} - {}{}{}".format(
|
||||
Fore.CYAN,
|
||||
flagged_deletion["file"],
|
||||
Fore.RESET,
|
||||
Fore.GREEN,
|
||||
flagged_deletion["line_num"],
|
||||
Fore.RESET,
|
||||
Fore.RED,
|
||||
flagged_deletion["deletion"],
|
||||
Fore.RESET,
|
||||
)
|
||||
)
|
||||
print(Fore.RESET)
|
||||
exit(1)
|
||||
print("No flagged goal_src code was deleted (hopefully!)")
|
||||
exit(0)
|
||||
Reference in New Issue
Block a user