Skip to content

Commit

Permalink
Merge branch 'develop' into anshul/org-card-unit-test
Browse files Browse the repository at this point in the history
  • Loading branch information
AnshulKahar2729 authored Oct 31, 2024
2 parents 2b9d5bb + af2f509 commit bd7de25
Show file tree
Hide file tree
Showing 112 changed files with 16,310 additions and 37,248 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
"@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-unsafe-function-type": "error",
"@typescript-eslint/no-wrapper-object-types": "error",
"@typescript-eslint/no-empty-object-type": "error",
"@typescript-eslint/no-duplicate-enum-values": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/consistent-type-assertions": "error",
Expand Down
4 changes: 2 additions & 2 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ updates:
directory: "/"
# Schedule automated updates to run weekly
schedule:
interval: "weekly"
interval: "monthly"
# Labels to apply to Dependabot PRs
labels:
- "dependencies"
# Specify the target branch for PRs
target-branch: "develop"
# Customize commit message prefix
commit-message:
prefix: "chore(deps):"
prefix: "chore(deps):"
3 changes: 2 additions & 1 deletion .github/workflows/codeql-codescan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ on:
- '**'
jobs:
CodeQL:
name: Analyse code with codeQL on push
if: ${{ github.actor != 'dependabot[bot]' }}
name: Analyse Code With CodeQL
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down
30 changes: 28 additions & 2 deletions .github/workflows/compare_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@ def compare_translations(default_translation,
errors.append(error_msg)
return errors

def flatten_json(nested_json, parent_key=""):
"""
Flattens a nested JSON, concatenating keys to represent the hierarchy.
Args:
nested_json (dict): The JSON object to flatten.
parent_key (str): The base key for recursion (used to track key hierarchy).
Returns:
dict: A flattened dictionary with concatenated keys.
"""
flat_dict = {}

for key, value in nested_json.items():
# Create the new key by concatenating parent and current key
new_key = f"{parent_key}.{key}" if parent_key else key

if isinstance(value, dict):
# Recursively flatten the nested dictionary
flat_dict.update(flatten_json(value, new_key))
else:
# Assign the value to the flattened key
flat_dict[new_key] = value

return flat_dict

def load_translation(filepath):
"""Load translation from a file.
Expand All @@ -104,7 +129,8 @@ def load_translation(filepath):
if not content.strip():
raise ValueError(f"File {filepath} is empty.")
translation = json.loads(content)
return translation
flattened_translation = flatten_json(translation)
return flattened_translation
except json.JSONDecodeError as e:
raise ValueError(f"Error decoding JSON from file {filepath}: {e}")

Expand Down Expand Up @@ -170,7 +196,7 @@ def main():
"--directory",
type=str,
nargs="?",
default=os.path.join(os.getcwd(), "locales"),
default=os.path.join(os.getcwd(), "public/locales"),
help="Directory containing translation files(relative to the root directory).",
)
args = parser.parse_args()
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/eslint_disable_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ def has_eslint_disable(file_path):
Returns:
bool: True if eslint-disable statement is found, False otherwise.
"""
with open(file_path, 'r') as file:
content = file.read()
return re.search(r'//\s*eslint-disable', content)
eslint_disable_pattern = re.compile(r'//\s*eslint-disable(?:-next-line|-line)?', re.IGNORECASE)

try:
with open(file_path, 'r', encoding='utf-8') as file:
content = file.read()
return bool(eslint_disable_pattern.search(content))
except Exception as e:
print(f"Error reading file {file_path}: {e}")
return False

def check_eslint(directory):
"""
Expand Down Expand Up @@ -72,7 +78,6 @@ def arg_parser_resolver():
Returns:
result: Parsed argument object
"""
parser = argparse.ArgumentParser()
parser.add_argument(
Expand All @@ -98,7 +103,6 @@ def main():
Raises:
SystemExit: If an error occurs during execution.
"""

args = arg_parser_resolver()

if not os.path.exists(args.directory):
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Count number of lines
run: |
chmod +x ./.github/workflows/countline.py
./.github/workflows/countline.py --lines 600 --exclude_files src/screens/LoginPage/LoginPage.tsx src/GraphQl/Queries/Queries.ts src/screens/OrgList/OrgList.tsx src/GraphQl/Mutations/mutations.ts src/components/EventListCard/EventListCardModals.tsx
./.github/workflows/countline.py --lines 600 --exclude_files src/screens/LoginPage/LoginPage.tsx src/GraphQl/Queries/Queries.ts src/screens/OrgList/OrgList.tsx src/GraphQl/Mutations/mutations.ts src/components/EventListCard/EventListCardModals.tsx src/screens/ManageTag/ManageTag.tsx
- name: Get changed TypeScript files
id: changed-files
Expand All @@ -56,7 +56,7 @@ jobs:
if: steps.changed-files.outputs.only_changed != 'true'
env:
CHANGED_FILES: ${{ steps.changed_files.outputs.all_changed_files }}
run: npx eslint ${CHANGED_FILES}
run: npx eslint ${CHANGED_FILES} && python .github/workflows/eslint_disable_check.py

- name: Check for TSDoc comments
run: npm run check-tsdoc # Run the TSDoc check script
Expand All @@ -79,8 +79,9 @@ jobs:
echo "Error: Source and Target Branches are the same. Please ensure they are different."
exit 1
Check-Unauthorized-Changes:
name: Checks if no unauthorized files are changed
Check-Sensitive-Files:
if: ${{ github.actor != 'dependabot[bot]' }}
name: Checks if sensitive files have been changed without authorization
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand Down Expand Up @@ -110,6 +111,14 @@ jobs:
LICENSE
setup.ts
.coderabbit.yaml
CODE_OF_CONDUCT.md
CODE_STYLE.md
CONTRIBUTING.md
DOCUMENTATION.md
INSTALLATION.md
ISSUE_GUIDELINES.md
PR_GUIDELINES.md
README.md
- name: List all changed unauthorized files
if: steps.changed-unauth-files.outputs.any_changed == 'true' || steps.changed-unauth-files.outputs.any_deleted == 'true'
Expand All @@ -122,6 +131,7 @@ jobs:
exit 1
Count-Changed-Files:
if: ${{ github.actor != 'dependabot[bot]' }}
name: Checks if number of files changed is acceptable
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -212,6 +222,7 @@ jobs:
min_coverage: 95.0

Graphql-Inspector:
if: ${{ github.actor != 'dependabot[bot]' }}
name: Runs Introspection on the GitHub talawa-api repo on the schema.graphql file
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -239,6 +250,7 @@ jobs:
run: graphql-inspector validate './src/GraphQl/**/*.ts' './talawa-api/schema.graphql'

Check-Target-Branch:
if: ${{ github.actor != 'dependabot[bot]' }}
name: Check Target Branch
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ env:

jobs:
Code-Coverage:
if: ${{ github.actor != 'dependabot[bot]' }}
name: Test and Calculate Code Coverage
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
96 changes: 96 additions & 0 deletions .github/workflows/talawa_admin_md_mdx_format_adjuster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
Script to make Markdown files MDX compatible.
This script scans Markdown files and escapes special characters (<, >, {, })
to make them compatible with the MDX 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_mdx_characters(text):
"""
Escape special characters in a text string for MDX 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 MDX 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 MDX characters
new_content = escape_mdx_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 MDX compatibility.
Args:
None
Returns:
None
"""
parser = argparse.ArgumentParser(description="Make Markdown files MDX 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()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Core features include:
1. The `talawa` documentation can be found at our [docs.talawa.io](https://docs.talawa.io) site.
1. It is automatically generated from the markdown files stored in our [Talawa-Docs GitHub repository](https://github.com/PalisadoesFoundation/talawa-docs). This makes it easy for you to update our documenation.

# Videos
# Videos

1. Visit our [YouTube Channel playlists](https://www.youtube.com/@PalisadoesOrganization/playlists) for more insights
1. The "[Getting Started - Developers](https://www.youtube.com/watch?v=YpBUoHxEeyg&list=PLv50qHwThlJUIzscg9a80a9-HmAlmUdCF&index=1)" videos are extremely helpful for new open source contributors.
8 changes: 8 additions & 0 deletions config/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
presets: [
'@babel/preset-env', // Transforms modern JavaScript
'@babel/preset-typescript', // Transforms TypeScript
'@babel/preset-react', // Transforms JSX
],
plugins: ['babel-plugin-transform-import-meta'],
};
30 changes: 30 additions & 0 deletions config/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import viteTsconfigPaths from 'vite-tsconfig-paths';
import svgrPlugin from 'vite-plugin-svgr';
import EnvironmentPlugin from 'vite-plugin-environment';

export default defineConfig({
// depending on your application, base can also be "/"
build: {
outDir: 'build',
},
base: '',
plugins: [
react(),
viteTsconfigPaths(),
EnvironmentPlugin('all'),
svgrPlugin({
svgrOptions: {
icon: true,
// ...svgr options (https://react-svgr.com/docs/options/)
},
}),
],
server: {
// this ensures that the browser opens upon server start
open: true,
// this sets a default port to 3000
port: 4321,
},
});
15 changes: 10 additions & 5 deletions public/index.html → index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon_palisadoes.ico" />
<link rel="icon" href="/favicon_palisadoes.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/favicon.ico" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="apple-touch-icon" href="/favicon.ico" />
<link rel="manifest" href="/manifest.json" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
Expand All @@ -18,10 +18,15 @@
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
referrerpolicy="no-referrer"
/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" referrerpolicy="no-referrer" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
referrerpolicy="no-referrer"
/>
<title>Talawa Admin</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
Loading

0 comments on commit bd7de25

Please sign in to comment.