mirror of
https://github.com/danielmiessler/SecLists.git
synced 2026-08-17 03:11:23 +00:00
Merge pull request #1008 from molangning/patch-validator
Patch validator for edge cases
This commit is contained in:
+74
-63
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
import os,subprocess,sys
|
import os,subprocess,sys
|
||||||
|
|
||||||
args=sys.argv[1]
|
|
||||||
files=[]
|
files=[]
|
||||||
STEP_SUMMARY_LOCATION="summary.md"
|
STEP_SUMMARY_LOCATION="summary.md"
|
||||||
IS_RUNNING_AS_ACTIONS=False
|
IS_RUNNING_AS_ACTIONS=False
|
||||||
@@ -73,6 +72,19 @@ ERROR_MSG="Errors in file %s on lines %s"
|
|||||||
WARNING_STRING="::warning file=%s,line=%s,col=%s,endColumn=%s::%s"
|
WARNING_STRING="::warning file=%s,line=%s,col=%s,endColumn=%s::%s"
|
||||||
ERROR_STRING="::error file=%s,line=%s,col=%s,endColumn=%s::%s"
|
ERROR_STRING="::error file=%s,line=%s,col=%s,endColumn=%s::%s"
|
||||||
|
|
||||||
|
if "CHANGED_FILES" not in os.environ:
|
||||||
|
print("[!] CHANGED_FILES environment variable not found!")
|
||||||
|
print("[-] This error may occur if you are running this script in your own machine\n")
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print("[!] No arguments set, exiting.")
|
||||||
|
exit(2)
|
||||||
|
|
||||||
|
args=sys.argv[1]
|
||||||
|
else:
|
||||||
|
args=os.environ["CHANGED_FILES"]
|
||||||
|
|
||||||
|
print(f"[+] Checking these files {args}")
|
||||||
|
|
||||||
if "GITHUB_STEP_SUMMARY" not in os.environ:
|
if "GITHUB_STEP_SUMMARY" not in os.environ:
|
||||||
print("[!] GITHUB_STEP_SUMMARY not found in system environments!")
|
print("[!] GITHUB_STEP_SUMMARY not found in system environments!")
|
||||||
print("[-] This error may occur if you are running this script in your own machine\n")
|
print("[-] This error may occur if you are running this script in your own machine\n")
|
||||||
@@ -217,39 +229,39 @@ for name,events,description in failed_checks:
|
|||||||
|
|
||||||
if file not in cleaned_failed_checks.keys():
|
if file not in cleaned_failed_checks.keys():
|
||||||
cleaned_failed_checks[file]={}
|
cleaned_failed_checks[file]={}
|
||||||
cleaned_failed_checks[file]["warn"]=[]
|
|
||||||
cleaned_failed_checks[file]["error"]=[]
|
if name not in cleaned_failed_checks[file].keys():
|
||||||
cleaned_failed_checks[file]["check"]=name
|
cleaned_failed_checks[file][name]={}
|
||||||
cleaned_failed_checks[file]["description"]=description
|
cleaned_failed_checks[file][name]["warn"]=[]
|
||||||
|
cleaned_failed_checks[file][name]["error"]=[]
|
||||||
|
cleaned_failed_checks[file][name]["description"]=description
|
||||||
|
|
||||||
cleaned_failed_checks[file][err_type].append(int(line_number))
|
cleaned_failed_checks[file][name][err_type].append(int(line_number))
|
||||||
|
|
||||||
for file, warn_and_errors in cleaned_failed_checks.items():
|
for file, checker in cleaned_failed_checks.items():
|
||||||
|
for name, warn_and_errors in checker.items():
|
||||||
|
|
||||||
warn=warn_and_errors["warn"]
|
for k,v in warn_and_errors.items():
|
||||||
error=warn_and_errors["error"]
|
|
||||||
|
if k not in ["error","warn"]:
|
||||||
for k,v in warn_and_errors.items():
|
|
||||||
|
|
||||||
if k not in ["error","warn"]:
|
|
||||||
continue
|
|
||||||
|
|
||||||
v.sort()
|
|
||||||
lines=[]
|
|
||||||
|
|
||||||
for i in v:
|
|
||||||
i=int(i)
|
|
||||||
|
|
||||||
if not lines:
|
|
||||||
lines.append([i,i])
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if lines[-1][1]+1==i:
|
v.sort()
|
||||||
lines[-1][1]=i
|
lines=[]
|
||||||
else:
|
|
||||||
lines.append([i,i])
|
|
||||||
|
|
||||||
warn_and_errors[k]=lines
|
for i in v:
|
||||||
|
i=int(i)
|
||||||
|
|
||||||
|
if not lines:
|
||||||
|
lines.append([i,i])
|
||||||
|
continue
|
||||||
|
|
||||||
|
if lines[-1][1]+1==i:
|
||||||
|
lines[-1][1]=i
|
||||||
|
else:
|
||||||
|
lines.append([i,i])
|
||||||
|
|
||||||
|
warn_and_errors[k]=lines
|
||||||
|
|
||||||
if all_pass:
|
if all_pass:
|
||||||
error_text="All good! No checks failed."
|
error_text="All good! No checks failed."
|
||||||
@@ -259,47 +271,46 @@ else:
|
|||||||
error_text=[]
|
error_text=[]
|
||||||
check_results={}
|
check_results={}
|
||||||
|
|
||||||
for file,warn_and_errors in cleaned_failed_checks.items():
|
for file, checker in cleaned_failed_checks.items():
|
||||||
|
for checker_name, warn_and_errors in checker.items():
|
||||||
error_msg=""
|
|
||||||
warn_msg=""
|
|
||||||
current_errors=[]
|
|
||||||
current_warnings=[]
|
|
||||||
checker_name=warn_and_errors["check"]
|
|
||||||
description=warn_and_errors["description"]
|
|
||||||
|
|
||||||
if checker_name not in check_results.keys():
|
|
||||||
check_results.update({checker_name:{"warn":[],"error":[]}})
|
|
||||||
|
|
||||||
for line_numbers in warn_and_errors["warn"]:
|
|
||||||
|
|
||||||
line_numbers[0]=str(line_numbers[0])
|
error_msg=""
|
||||||
line_numbers[1]=str(line_numbers[1])
|
warn_msg=""
|
||||||
|
current_errors=[]
|
||||||
|
current_warnings=[]
|
||||||
|
|
||||||
if line_numbers[0]==line_numbers[1]:
|
if checker_name not in check_results.keys():
|
||||||
current_warnings.append(line_numbers[0])
|
check_results.update({checker_name:{"warn":[],"error":[],"description":warn_and_errors["description"]}})
|
||||||
continue
|
|
||||||
|
|
||||||
current_warnings.append('-'.join(line_numbers))
|
|
||||||
|
|
||||||
for line_numbers in warn_and_errors["error"]:
|
for line_numbers in warn_and_errors["warn"]:
|
||||||
|
|
||||||
|
line_numbers[0]=str(line_numbers[0])
|
||||||
|
line_numbers[1]=str(line_numbers[1])
|
||||||
|
|
||||||
line_numbers[0]=str(line_numbers[0])
|
if line_numbers[0]==line_numbers[1]:
|
||||||
line_numbers[1]=str(line_numbers[1])
|
current_warnings.append(line_numbers[0])
|
||||||
|
continue
|
||||||
|
|
||||||
|
current_warnings.append('-'.join(line_numbers))
|
||||||
|
|
||||||
if line_numbers[0]==line_numbers[1]:
|
for line_numbers in warn_and_errors["error"]:
|
||||||
current_errors.append(line_numbers[0])
|
|
||||||
continue
|
|
||||||
|
|
||||||
current_errors.append('-'.join(line_numbers))
|
|
||||||
|
|
||||||
if current_errors:
|
line_numbers[0]=str(line_numbers[0])
|
||||||
error_msg=ERROR_MSG%(file,', '.join(current_errors))
|
line_numbers[1]=str(line_numbers[1])
|
||||||
check_results[checker_name]["error"].append(error_msg)
|
|
||||||
|
|
||||||
if current_warnings:
|
if line_numbers[0]==line_numbers[1]:
|
||||||
warn_msg=WARN_MSG%(file,', '.join(current_warnings))
|
current_errors.append(line_numbers[0])
|
||||||
check_results[checker_name]["warn"].append(warn_msg)
|
continue
|
||||||
|
|
||||||
|
current_errors.append('-'.join(line_numbers))
|
||||||
|
|
||||||
|
if current_errors:
|
||||||
|
error_msg=ERROR_MSG%(file,', '.join(current_errors))
|
||||||
|
check_results[checker_name]["error"].append(error_msg)
|
||||||
|
|
||||||
|
if current_warnings:
|
||||||
|
warn_msg=WARN_MSG%(file,', '.join(current_warnings))
|
||||||
|
check_results[checker_name]["warn"].append(warn_msg)
|
||||||
|
|
||||||
for checker,results in check_results.items():
|
for checker,results in check_results.items():
|
||||||
|
|
||||||
@@ -312,7 +323,7 @@ else:
|
|||||||
warn_msg='\n'.join(results["warn"])
|
warn_msg='\n'.join(results["warn"])
|
||||||
else:
|
else:
|
||||||
warn_msg="There are no warnings for this check!"
|
warn_msg="There are no warnings for this check!"
|
||||||
error_text.append(FORMATTED_OUTPUT_FORMAT%(checker,description,warn_msg,error_msg))
|
error_text.append(FORMATTED_OUTPUT_FORMAT%(checker,results["description"],warn_msg,error_msg))
|
||||||
|
|
||||||
error_text='\n- - -\n'.join(error_text)
|
error_text='\n- - -\n'.join(error_text)
|
||||||
|
|
||||||
|
|||||||
@@ -28,4 +28,6 @@ jobs:
|
|||||||
uses: tj-actions/changed-files@v34
|
uses: tj-actions/changed-files@v34
|
||||||
- name: Analyze all added or modified files
|
- name: Analyze all added or modified files
|
||||||
run: |
|
run: |
|
||||||
./.bin/validators.py "${{ steps.changed-files.outputs.all_changed_files }}"
|
./.bin/validators.py
|
||||||
|
env:
|
||||||
|
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
|
||||||
Reference in New Issue
Block a user