Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: new github action which limit the file changes in single PR to 20 #1316

Merged
merged 9 commits into from
Jan 6, 2024
42 changes: 42 additions & 0 deletions .github/workflows/check_changed_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
import sys

def count_changed_files(base_branch, current_branch):
try:
base_branch = f"origin/{base_branch}"
current_branch = f"origin/{current_branch}"
# Run git command to get the list of changed files
command = f"git diff --name-only {base_branch}...{current_branch} | wc -l"
file_count = int(os.popen(command).read().strip())
return file_count
except Exception as e:
print(f"Error: {e}")
sys.exit(1)

def main():
try:
# Get base branch and current commit
base_branch = sys.argv[1]
print(base_branch)
current_branch = sys.argv[2]
print(current_branch)

# Count changed files
file_count = count_changed_files(base_branch, current_branch)

print(f"Number of changed files: {file_count}")

# Check if the count exceeds 20
if file_count > 20:
print("Error: Too many files (greater than 20) changed in the pull request.")
print("Possible issues:")
print("- Contributor may be merging into an incorrect branch.")
print("- Source branch may be incorrect please use develop as source branch.")
sys.exit(1)

except IndexError:
print("Error: Please provide base branch and current commit as command line arguments.")
sys.exit(1)

if __name__ == "__main__":
main()
28 changes: 28 additions & 0 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,34 @@ jobs:
run: npm run lint:check


Check-Changed-Files:
runs-on: ubuntu-latest
needs: Code-Quality-Checks

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install dependencies
Tarunmeena0901 marked this conversation as resolved.
Show resolved Hide resolved
run: |
python -m pip install --upgrade pip
pip install black pydocstyle

- name: Run Python script
run: |
python .github/workflows/check_changed_files.py "${{ github.base_ref }}" "${{ github.head_ref }}"

- name: Run Black
Tarunmeena0901 marked this conversation as resolved.
Show resolved Hide resolved
run: black .

- name: Run Pydocstyle
run: pydocstyle .

Test-Application:
name: Test Application
runs-on: ubuntu-latest
Expand Down