Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into develop
  • Loading branch information
nitishkumar333 committed Jan 22, 2024
2 parents 30d88c8 + d42f252 commit ad8bb6a
Show file tree
Hide file tree
Showing 153 changed files with 25,494 additions and 4,189 deletions.
6 changes: 5 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ REACT_APP_USE_RECAPTCHA=
REACT_APP_RECAPTCHA_SITE_KEY=

# has to be inserted in the env file to use plugins and other websocket based features.
REACT_APP_BACKEND_WEBSOCKET_URL=ws://localhost:4000/graphql
REACT_APP_BACKEND_WEBSOCKET_URL=ws://localhost:4000/graphql

# If you want to logs Compiletime and Runtime error , warning and info write YES or if u want to
# keep the console clean leave it blank
ALLOW_LOGS=""
18 changes: 16 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@
},

// Specify the ESLint plugins tobe used
"plugins": ["react", "@typescript-eslint", "jest"],
"plugins": [
"react",
"@typescript-eslint",
"jest",
"import",
"eslint-plugin-tsdoc"
],
"rules": {
"react/destructuring-assignment": ["off"],
"@typescript-eslint/no-explicit-any": ["off"],
// "@typescript-eslint/no-explicit-any": ["off"],
"@typescript-eslint/explicit-module-boundary-types": ["off"],
"react/no-multi-comp": [
"error",
Expand All @@ -44,6 +50,14 @@
"extensions": [".tsx"]
}
],
"import/no-duplicates": "error",
"tsdoc/syntax": "error",
"@typescript-eslint/ban-ts-comment": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/no-duplicate-enum-values": "error",
"@typescript-eslint/array-type": "error",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/authorized-changes-detection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ on:
- 'vite.config.ts'
- 'CODEOWNERS'
- 'LICENSE'
- 'setup.ts'

jobs:
Checking-for-unauthorized-file-changes:
Expand Down
132 changes: 132 additions & 0 deletions .github/workflows/count_changed_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""Script to limit number of file changes in single PR.
Methodology:
Analyses the Pull request to find if the count of file changed in a pr
exceeds a pre-defined nummber 20
This scripts encourages contributors to align with project practices,
reducing the likelihood of unintentional merges into incorrect branches.
NOTE:
This script complies with our python3 coding and documentation standards.
It complies with:
1) Pylint
2) Pydocstyle
3) Pycodestyle
4) Flake8
"""

import sys
import argparse
import subprocess


def _count_changed_files(base_branch, pr_branch):
"""
Count the number of changed files between two branches.
Args:
base_branch (str): The base branch.
pr_branch (str): The PR branch.
Returns:
int: The number of changed files.
Raises:
SystemExit: If an error occurs during execution.
"""
base_branch = f"origin/{base_branch}"
pr_branch = f"origin/{pr_branch}"

command = f"git diff --name-only {base_branch}...{pr_branch} | wc -l"

try:
# Run git command to get the list of changed files
process = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
output, error = process.communicate()
except Exception as e:
print(f"Error: {e}")
sys.exit(1)

file_count = int(output.strip())
return file_count

def _arg_parser_resolver():
"""Resolve the CLI arguments provided by the user.
Args:
None
Returns:
result: Parsed argument object
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--base_branch",
type=str,
required=True,
help="Base branch where pull request should be made."
),
parser.add_argument(
"--pr_branch",
type=str,
required=True,
help="PR branch from where the pull request is made.",
),
parser.add_argument(
"--file_count",
type=int,
default=20,
help="Number of files changes allowed in a single commit")
return parser.parse_args()


def main():
"""
Execute the script's main functionality.
This function serves as the entry point for the script. It performs
the following tasks:
1. Validates and retrieves the base branch and PR commit from
command line arguments.
2. Counts the number of changed files between the specified branches.
3. Checks if the count of changed files exceeds the acceptable
limit (20).
4. Provides informative messages based on the analysis.
Raises:
SystemExit: If an error occurs during execution.
"""

args = _arg_parser_resolver()

base_branch = args.base_branch
pr_branch = args.pr_branch

print(f"You are trying to merge on branch: {base_branch}")
print(f"You are making commit from your branch: {pr_branch}")

# Count changed files
file_count = _count_changed_files(base_branch, pr_branch)
print(f"Number of changed files: {file_count}")

# Check if the count exceeds 20
if file_count > args.file_count:
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)


if __name__ == "__main__":
main()
97 changes: 97 additions & 0 deletions .github/workflows/md_mpx_format_adjuster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
Script to make Markdown files MPX compatible.
This script scans Markdown files and escapes special characters (<, >, {, })
to make them compatible with the MPX standard used in Docusaurus v3.
This script complies with:
1) Pylint
2) Pydocstyle
3) Pycodestyle
4) Flake8
"""

import os
import argparse
import re

def escape_mpx_characters(text):
"""
Escape special characters in a text string for MPX compatibility.
Avoids escaping already escaped characters.
Args:
text: A string containing the text to be processed.
Returns:
A string with special characters (<, >, {, }) escaped, avoiding
double escaping.
"""
# Regular expressions to find unescaped special characters
patterns = {
"<": r"(?<!\\)<",
">": r"(?<!\\)>",
"{": r"(?<!\\){",
"}": r"(?<!\\)}"
}

# Replace unescaped special characters
for char, pattern in patterns.items():
text = re.sub(pattern, f"\\{char}", text)

return text

def process_file(filepath):
"""
Process a single Markdown file for MPX compatibility.
Args:
filepath: The path to the Markdown file to process.
Returns:
None, writes the processed content back to the file only if there are changes.
"""
with open(filepath, 'r', encoding='utf-8') as file:
content = file.read()

# Escape MPX characters
new_content = escape_mpx_characters(content)

# Write the processed content back to the file only if there is a change
if new_content != content:
with open(filepath, 'w', encoding='utf-8') as file:
file.write(new_content)

def main():
"""
Main function to process all Markdown files in a given directory.
Scans for all Markdown files in the specified directory and processes each
one for MPX compatibility.
Args:
None
Returns:
None
"""
parser = argparse.ArgumentParser(description="Make Markdown files MPX compatible.")
parser.add_argument(
"--directory",
type=str,
required=True,
help="Directory containing Markdown files to process."
)

args = parser.parse_args()

# Process each Markdown file in the directory
for root, _, files in os.walk(args.directory):
for file in files:
if file.lower().endswith(".md"):
process_file(os.path.join(root, file))

if __name__ == "__main__":
main()
41 changes: 37 additions & 4 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Count number of lines
run: |
chmod +x ./.github/workflows/countline.py
./.github/workflows/countline.py --lines 1000 --exclude_files src/screens/LoginPage/LoginPage.tsx
./.github/workflows/countline.py --lines 600 --exclude_files src/screens/LoginPage/LoginPage.tsx
- name: Get changed TypeScript files
id: changed-files
Expand All @@ -57,6 +57,22 @@ jobs:
python .github/workflows/compare_translations.py --directory public/locales
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: Run Python script
run: |
python .github/workflows/count_changed_files.py --base_branch "${{ github.base_ref }}" --pr_branch "${{ github.head_ref }}"
Test-Application:
name: Test Application
runs-on: ubuntu-latest
Expand Down Expand Up @@ -111,9 +127,26 @@ jobs:

- name: resolve dependency
run: npm install -g @graphql-inspector/cli

- name: Clone API repository
run: git clone https://github.com/PalisadoesFoundation/talawa-api && ls -a

- name: Clone API Repository
run: |
# Retrieve the complete branch name directly from the GitHub context
FULL_BRANCH_NAME=${{ github.base_ref }}
echo "FULL_Branch_NAME: $FULL_BRANCH_NAME"
# Clone the specified repository using the extracted branch name
git clone --branch $FULL_BRANCH_NAME https://github.com/PalisadoesFoundation/talawa-api && ls -a
- name: Validate Documents
run: graphql-inspector validate './src/GraphQl/**/*.ts' './talawa-api/schema.graphql'

Check-Target-Branch:
name: Check Target Branch
runs-on: ubuntu-latest
steps:
- name: Check if the target branch is develop
if: github.event.pull_request.base.ref != 'develop'
run: |
echo "Error: Pull request target branch must be 'develop'. Please refer PR_GUIDELINES.md"
exit 1
18 changes: 14 additions & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ jobs:

Generate-Documentation:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/automated-docs'
steps:
- name: Checkout the Repository
uses: actions/checkout@v3

- name: Node.js Version
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Restore node_modules from cache
id: cache-npm
uses: actions/cache@v3
Expand Down Expand Up @@ -91,9 +95,14 @@ jobs:

- name: Generate Documentation of Markdown pages
run: |
yarn global add typedoc
yarn add typedoc-plugin-markdown
yarn typedoc --entryPoints src/components src/screens --out talawa-admin-docs --plugin typedoc-plugin-markdown --theme markdown --entryPointStrategy expand --exclude "**/*.test.ts" --exclude "**/*.css"
npm install --global typedoc
npm install typedoc-plugin-markdown
npm install --save-dev @types/node
npx typedoc --entryPoints src/components src/screens --out talawa-admin-docs --plugin typedoc-plugin-markdown --theme markdown --entryPointStrategy expand --exclude "**/*.test.ts" --exclude "**/*.css"
- name: Make Markdown Files MPX Compatible
run: python ./.github/workflows/md_mpx_format_adjuster.py --directory talawa-admin-docs


- name: Checking doc updated
id: DocUpdated
Expand Down Expand Up @@ -132,6 +141,7 @@ jobs:
path: talawa-admin-docs

Copy-docs-to-talawa-docs:
needs: Generate-Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
Loading

0 comments on commit ad8bb6a

Please sign in to comment.