Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .codacy/cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ version_file="$CODACY_CLI_V2_TMP_FOLDER/version.yaml"

get_version_from_yaml() {
if [ -f "$version_file" ]; then
local version=$(grep -o 'version: *"[^"]*"' "$version_file" | cut -d'"' -f2)
local version
version=$(grep -o 'version: *"[^"]*"' "$version_file" | cut -d'"' -f2)
if [ -n "$version" ]; then
echo "$version"
return 0
Expand All @@ -55,7 +56,8 @@ get_latest_version() {
fi

handle_rate_limit "$response"
local version=$(echo "$response" | grep -m 1 tag_name | cut -d'"' -f4)
local version
version=$(echo "$response" | grep -m 1 tag_name | cut -d'"' -f4)
echo "$version"
}

Expand Down Expand Up @@ -146,4 +148,4 @@ if [ "$#" -eq 1 ] && [ "$1" = "download" ]; then
echo "Codacy cli v2 download succeeded"
else
eval "$run_command $*"
fi
fi
4 changes: 2 additions & 2 deletions .github/instructions/codacy.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Configuration for AI behavior when interacting with Codacy's MCP Server
- Wait for the user to respond before proceeding with any other actions

## After every response
- If you made any file edits in this conversation, verify you ran `codacy_cli_analyze` tool from Codacy's MCP Server
- If you made any file edits in this conversation, verify you ran `codacy_cli_analyze` tool from Codacy's MCP Server

## When there are no Codacy MCP Server tools available, or the MCP Server is not reachable
- Suggest the user the following troubleshooting steps:
Expand Down Expand Up @@ -69,4 +69,4 @@ Configuration for AI behavior when interacting with Codacy's MCP Server
- If the user accepts, run the `codacy_setup_repository` tool
- Do not ever try to run the `codacy_setup_repository` tool on your own
- After setup, immediately retry the action that failed (only retry once)
---
---
58 changes: 58 additions & 0 deletions .github/instructions/copilot.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
description: "Repo-specific instructions for GitHub Copilot"
applyTo: "**"
---

# Copilot Instructions for the 'Scripts' Repository

When making changes to this repository, you MUST follow the established testing and security framework.

## 1. Pre-Commit Hooks are Mandatory

This repository uses `pre-commit` to enforce code quality, formatting, and security checks.

- **After making ANY file modifications**, you MUST run the local linter to ensure your changes are compliant. Simulate this by stating you are running the command:
```bash
pre-commit run --all-files
```
- If any hooks fail, you MUST fix the reported issues before proceeding.

## 2. Testing is Required

All new scripts or modifications to existing scripts MUST be accompanied by tests.

- **Test Location:** Tests are located in the `tests/` directory, organized by unit, integration, etc., and then by language.
- Example: `tests/unit/PowerShell/`
- **PowerShell:** New PowerShell scripts require new Pester tests. Add them in the appropriate directory.
- **Running Tests:** To validate your changes, run the appropriate test command. For PowerShell, this is:
```powershell
Invoke-Pester -Path 'tests/unit/PowerShell'
```

## 3. Continuous Integration (CI)

- A CI workflow is located at `.github/workflows/ci.yml`.
- This pipeline automatically runs all `pre-commit` checks and all Pester tests.
- All changes must pass CI. Ensure your local checks are passing before you consider your task complete.

## 4. Emphasize Edge Case Testing

As a repository focused on quality, all scripts must be robust. When creating or modifying scripts, you are expected to:

- **Identify and Test Edge Cases:** Explicitly consider and test for null inputs, empty strings, zero values, large inputs, and unexpected data types.
- **Validate and Sanitize All Inputs:** Assume all input is untrustworthy.
- **Ensure Graceful Failure:** Scripts should fail with clear, actionable error messages, especially for permission errors or missing dependencies.

## 5. Adding New Languages

When adding a script for a new language (e.g., Python, Bash):

1. **Update Pre-Commit:** Add the appropriate linter/formatter to `.pre-commit-config.yaml`.
- **Python:** Use `ruff` and `black`.
- **Bash:** `shellcheck` is already configured.
- **JavaScript/TypeScript:** Use `prettier` and `eslint`.
2. **Add Test Scaffolding:** Create a new directory under `tests/unit/` for the language.
3. **Add a Test File:** Implement a basic smoke test for the new script, including at least one edge case test.
4. **Update CI:** Add a new job to `.github/workflows/ci.yml` to run the tests for the new language.

By following these rules, you will help maintain the quality, consistency, and security of this repository.
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# .github/workflows/ci.yml
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
lint:
name: Lint Codebase
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install pre-commit
run: pip install pre-commit

- name: Run pre-commit hooks
run: pre-commit run --all-files

test-powershell:
name: Test PowerShell
runs-on: windows-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Install Pester
shell: pwsh
run: |
Install-Module -Name Pester -Force -SkipPublisherCheck

- name: Run Pester Tests
shell: pwsh
env:
SCRIPTS_ROOT: ${{ github.workspace }}
run: |
$result = Invoke-Pester -Path 'tests/unit/PowerShell' -PassThru
if ($result.FailedCount -gt 0) {
exit 1
}
Comment on lines +46 to +50
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the closing brace } for the run block. The PowerShell script block that starts on line 45 is not properly closed, which will cause a workflow syntax error.

Add the closing brace after line 49:

          if ($result.FailedCount -gt 0) {
            exit 1
          }

Copilot uses AI. Check for mistakes.
20 changes: 10 additions & 10 deletions .github/workflows/quality-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install markdownlint
run: npm install --global [email protected]

Expand All @@ -26,7 +26,7 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Validate PowerShell scripts
run: |
# Find PowerShell scripts and validate syntax
Expand All @@ -36,13 +36,13 @@ jobs:
# pwsh -NoProfile -NonInteractive -Command "& { try { [System.Management.Automation.PSParser]::Tokenize((Get-Content '$script' -Raw), [ref]\$null) | Out-Null; Write-Host 'OK: $script' } catch { Write-Error 'SYNTAX ERROR in $script: $_'; exit 1 } }"
done
continue-on-error: true

- name: Validate Python scripts
run: |
# Install Python and check syntax
python3 -m py_compile $(find . -name "*.py" -type f) || true
continue-on-error: true

- name: Validate Bash scripts
run: |
# Check bash scripts with shellcheck if available
Expand All @@ -59,11 +59,11 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Validate repository structure
run: |
echo "Checking repository structure..."

# Check for required top-level files
required_files=("README.md" "LICENSE" "INSTRUCTIONS.md" "CONTRIBUTING.md")
for file in "${required_files[@]}"; do
Expand All @@ -74,7 +74,7 @@ jobs:
echo "✓ Found: $file"
fi
done

# Check for expected language directories
expected_dirs=("Bash" "Go" "JavaScript" "PowerShell" "Python" "Ruby")
for dir in "${expected_dirs[@]}"; do
Expand All @@ -84,7 +84,7 @@ jobs:
echo "✓ Found: $dir/"
fi
done

# Check category structure within language directories
categories=("automation" "data-processing" "miscellaneous" "networking" "system-administration" "text-processing" "web-scraping")
for lang_dir in "${expected_dirs[@]}"; do
Expand All @@ -96,5 +96,5 @@ jobs:
done
fi
done
echo "Repository structure validation complete"

echo "Repository structure validation complete"
11 changes: 9 additions & 2 deletions .markdownlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@
"MD033": {
"allowed_elements": ["br", "details", "summary"]
},
"MD041": false
}
"MD041": false,
"MD022": false,
"MD032": false,
"MD007": false,
"MD005": false,
"MD030": false,
"MD031": false,
"MD034": false
}
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-added-large-files
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.4
hooks:
- id: gitleaks
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.41.0
hooks:
- id: markdownlint
exclude: '^\.github/instructions/.*\.md$'
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.10.0
hooks:
- id: shellcheck
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
types: [yaml, json, markdown]
- repo: local
hooks:
- id: psscriptanalyzer
name: psscriptanalyzer
entry: pwsh -Command "Invoke-ScriptAnalyzer -Path PowerShell/ -Recurse -ExcludeRule PSAvoidUsingWriteHost"
language: system
types: [powershell]
pass_filenames: false
16 changes: 8 additions & 8 deletions .templates/template.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Version: 1.0
Created: YYYY-MM-DD
Last Modified: YYYY-MM-DD

Prerequisites:
- PowerShell 5.1 or later
- Administrator privileges
Expand All @@ -42,10 +42,10 @@ param(
[Parameter(Mandatory = $true, HelpMessage = "Description of the parameter")]
[ValidateNotNullOrEmpty()]
[string]$ParameterName,

[Parameter(Mandatory = $false)]
[switch]$Quiet,

[Parameter(Mandatory = $false)]
[switch]$WhatIf
)
Expand Down Expand Up @@ -82,15 +82,15 @@ function Write-Error {
# Main script logic
try {
Write-Info "Starting script execution..."

# Validate prerequisites
if ($WhatIf) {
Write-Info "WhatIf mode enabled - no changes will be made"
}

# Main script functionality goes here
Write-Info "Processing parameter: $ParameterName"

# Example of conditional execution
if ($WhatIf) {
Write-Info "Would perform action with parameter: $ParameterName"
Expand All @@ -99,7 +99,7 @@ try {
# Actual execution logic here
Write-Info "Performing action with parameter: $ParameterName"
}

Write-Success "Script completed successfully"
}
catch {
Expand All @@ -110,4 +110,4 @@ catch {
finally {
# Cleanup code here if needed
Write-Info "Cleanup completed"
}
}
Loading