Skip to content

Commit

Permalink
Check for VBA code with no file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
DecimalTurn authored Sep 6, 2024
1 parent df3759b commit 97e9d3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion .github/workflows/gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,31 @@ def clone_repo(repo_url, destination_folder):
raise ValueError("Problem with cloning.")

def count_vba_related_files(repo_path):
vba_extensions = ['.bas', '.cls', '.frm', '.vba', '.vbs', '.vb', '.d.vb', '.vbproj']
vba_extensions = ['.bas', '.cls', '.frm', '.vba', '.vbs', '.vb', '.d.vb', '.vbproj', 'No ext']
counts = {ext: 0 for ext in vba_extensions}

for root, dirs, files in os.walk(repo_path):
for file in files:
for ext in vba_extensions:
if file.endswith(ext):
counts[ext] += 1
if ext == 'No ext' and '.' not in file:
file_path = os.path.join(root, file)
with open(file_path, 'r', encoding='cp1252') as f:
file_content = f.read()
if has_vba_code(file_content):
counts[ext] += 1

# Print the counts
for ext, count in counts.items():
print(f"Number of '{ext}' files: {count}")

return counts

def has_vba_code(file_content):
vba_pattern = re.compile(r'^\s*(Public|Private)?\s*(Sub|Function)\s+', re.MULTILINE)
return bool(vba_pattern.search(file_content))

# Get the labels for the issue and extract the name of the check (Check A, Check B, etc.)
def get_check(issue):
labels = issue['labels']
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/scan_and_suggest.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def fix_file_extensions_issue(token, repo):
# VBScript extension used for VBA code
create_issue_wrapper(token, repo, 'detected as VBScript', 'Check B: Use of vbs extension.md', 'Check B')

if repo['language'] == 'None' and counts['No ext'] > 0:
print(f"🔴 The repo contains VBA files with no file extension")

except Exception as e:
print(f"🔴 An unexpected error occurred: {e}")

Expand Down

0 comments on commit 97e9d3b

Please sign in to comment.