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

#2970:autodoc-generate #3151

Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{

Check warning on line 1 in .eslintrc.json

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

File ignored by default.
"env": {
"browser": true,
"node": true,
Expand Down Expand Up @@ -152,6 +152,7 @@
"docs/docusaurus.config.ts",
"docs/sidebars.ts",
"docs/src/**",
"docs/blog/**"
"docs/blog/**",
"docs/docs/**"
]
}
136 changes: 136 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
##############################################################################

Check warning on line 1 in .github/workflows/pull-request.yml

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

File ignored by default.
##############################################################################
#
# NOTE!
Expand Down Expand Up @@ -449,3 +449,139 @@
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_REPOSITORY: ${{ github.repository }}

Merge-Conflict-Check:
name: Check for Merge Conflicts
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
needs: [Code-Quality-Checks]
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Check Mergeable Status via API
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
max_retries=3
retry_delay=5

for ((i=1; i<=max_retries; i++)); do
echo "Attempt $i of $max_retries"

response=$(curl -s -f -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER")

if [ $? -ne 0 ]; then
echo "Failed to call GitHub API"
if [ $i -eq $max_retries ]; then
exit 1
fi
sleep $retry_delay
continue
fi

mergeable=$(echo "$response" | jq -r '.mergeable')
if [ "$mergeable" == "true" ]; then
echo "No conflicts detected."
exit 0
elif [ "$mergeable" == "false" ]; then
echo "Merge conflicts detected."
exit 1
else
echo "Mergeable status unknown."
if [ $i -eq $max_retries ]; then
exit 1
fi
sleep $retry_delay
fi
done

Comment on lines +453 to +498
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance robustness and security of the merge conflict check.

The implementation needs several improvements:

  1. Add timeout to curl command to prevent hanging.
  2. Move retry configuration to environment variables.
  3. Use direct exit code checking for better error handling.

Apply these changes:

  Merge-Conflict-Check:
    name: Check for Merge Conflicts
    runs-on: ubuntu-latest
    if: github.actor != 'dependabot[bot]'
    needs: [Code-Quality-Checks]
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4

      - name: Check Mergeable Status via API
+       env:
+         MAX_RETRIES: 3
+         RETRY_DELAY: 5
+         CURL_TIMEOUT: 10
        run: |  
          PR_NUMBER=${{ github.event.pull_request.number }}
-         max_retries=3
-         retry_delay=5
          
-         for ((i=1; i<=max_retries; i++)); do
+         for ((i=1; i<=$MAX_RETRIES; i++)); do
-           echo "Attempt $i of $max_retries"
+           echo "Attempt $i of $MAX_RETRIES"
            
-           response=$(curl -s -f -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
+           if ! response=$(curl -s -f --max-time $CURL_TIMEOUT -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
              "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER")
-           if [ $? -ne 0 ]; then
+           then
              echo "Failed to call GitHub API"
-             if [ $i -eq $max_retries ]; then
+             if [ $i -eq $MAX_RETRIES ]; then
                exit 1
              fi
-             sleep $retry_delay
+             sleep $RETRY_DELAY
              continue
            fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Merge-Conflict-Check:
name: Check for Merge Conflicts
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
needs: [Code-Quality-Checks]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Check Mergeable Status via API
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
max_retries=3
retry_delay=5
for ((i=1; i<=max_retries; i++)); do
echo "Attempt $i of $max_retries"
response=$(curl -s -f -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER")
if [ $? -ne 0 ]; then
echo "Failed to call GitHub API"
if [ $i -eq $max_retries ]; then
exit 1
fi
sleep $retry_delay
continue
fi
mergeable=$(echo "$response" | jq -r '.mergeable')
if [ "$mergeable" == "true" ]; then
echo "No conflicts detected."
exit 0
elif [ "$mergeable" == "false" ]; then
echo "Merge conflicts detected."
exit 1
else
echo "Mergeable status unknown."
if [ $i -eq $max_retries ]; then
exit 1
fi
sleep $retry_delay
fi
done
Merge-Conflict-Check:
name: Check for Merge Conflicts
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
needs: [Code-Quality-Checks]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Check Mergeable Status via API
env:
MAX_RETRIES: 3
RETRY_DELAY: 5
CURL_TIMEOUT: 10
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
for ((i=1; i<=$MAX_RETRIES; i++)); do
echo "Attempt $i of $MAX_RETRIES"
if ! response=$(curl -s -f --max-time $CURL_TIMEOUT -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER")
then
echo "Failed to call GitHub API"
if [ $i -eq $MAX_RETRIES ]; then
exit 1
fi
sleep $RETRY_DELAY
continue
fi
mergeable=$(echo "$response" | jq -r '.mergeable')
if [ "$mergeable" == "true" ]; then
echo "No conflicts detected."
exit 0
elif [ "$mergeable" == "false" ]; then
echo "Merge conflicts detected."
exit 1
else
echo "Mergeable status unknown."
if [ $i -eq $max_retries ]; then
exit 1
fi
sleep $retry_delay
fi
done
🧰 Tools
🪛 actionlint (1.7.4)

463-463: shellcheck reported issue in this script: SC2181:style:11:8: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?

(shellcheck)

🪛 yamllint (1.35.1)

[error] 463-463: trailing spaces

(trailing-spaces)


[error] 467-467: trailing spaces

(trailing-spaces)


[error] 470-470: trailing spaces

(trailing-spaces)


[error] 473-473: trailing spaces

(trailing-spaces)


[error] 482-482: trailing spaces

(trailing-spaces)


[error] 498-498: trailing spaces

(trailing-spaces)

generate-docs:
name: Generate Auto Documentation
runs-on: ubuntu-latest
needs: [Code-Quality-Checks, Test-Application, Start-App-Without-Docker, Docker-Start-Check]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for getting full git history

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'npm'

- name: Install dependencies
run: |
npm ci
npm install -g typedoc typedoc-plugin-markdown

- name: Create documentation directory
run: |
mkdir -p docs/docs/auto-docs
mkdir -p docs/docs/user-guide
mkdir -p docs/docs/developer-guide/reference

- name: Generate Documentation
run: |
# Generate the documentation
typedoc \
--out docs/docs/auto-docs \
--plugin typedoc-plugin-markdown \
--theme markdown \
--tsconfig tsconfig.json \
--excludePrivate \
--excludeProtected \
--excludeExternals \
--hideGenerator \
--categorizeByGroup true \
--entryPointStrategy expand \
--entryPoints "src/**/*.ts" "src/**/*.tsx" \
--exclude "**/*.{test,spec,stories}.{ts,tsx}" \
--exclude "**/__tests__/**" \
--exclude "**/__mocks__/**" \
--exclude "**/node_modules/**" \
--cleanOutputDir true
Comment on lines +525 to +544
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling to documentation generation.

The TypeDoc command needs error handling and validation of the output.

Apply these changes:

      - name: Generate Documentation
        run: |
+         set -e  # Exit on any error
+         
          # Generate the documentation
-         typedoc \
+         if ! typedoc \
            --out docs/docs/auto-docs \
            --plugin typedoc-plugin-markdown \
            --theme markdown \
            --tsconfig tsconfig.json \
            --excludePrivate \
            --excludeProtected \
            --excludeExternals \
            --hideGenerator \
            --categorizeByGroup true \
            --entryPointStrategy expand \
            --entryPoints "src/**/*.ts" "src/**/*.tsx" \
            --exclude "**/*.{test,spec,stories}.{ts,tsx}" \
            --exclude "**/__tests__/**" \
            --exclude "**/__mocks__/**" \
            --exclude "**/node_modules/**" \
-           --cleanOutputDir true
+           --cleanOutputDir true; then
+           echo "Documentation generation failed"
+           exit 1
+         fi
+         
+         # Verify documentation was generated
+         if [ ! -d "docs/docs/auto-docs" ] || [ -z "$(ls -A docs/docs/auto-docs)" ]; then
+           echo "Documentation directory is empty or missing"
+           exit 1
+         fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Generate Documentation
run: |
# Generate the documentation
typedoc \
--out docs/docs/auto-docs \
--plugin typedoc-plugin-markdown \
--theme markdown \
--tsconfig tsconfig.json \
--excludePrivate \
--excludeProtected \
--excludeExternals \
--hideGenerator \
--categorizeByGroup true \
--entryPointStrategy expand \
--entryPoints "src/**/*.ts" "src/**/*.tsx" \
--exclude "**/*.{test,spec,stories}.{ts,tsx}" \
--exclude "**/__tests__/**" \
--exclude "**/__mocks__/**" \
--exclude "**/node_modules/**" \
--cleanOutputDir true
- name: Generate Documentation
run: |
set -e # Exit on any error
# Generate the documentation
if ! typedoc \
--out docs/docs/auto-docs \
--plugin typedoc-plugin-markdown \
--theme markdown \
--tsconfig tsconfig.json \
--excludePrivate \
--excludeProtected \
--excludeExternals \
--hideGenerator \
--categorizeByGroup true \
--entryPointStrategy expand \
--entryPoints "src/**/*.ts" "src/**/*.tsx" \
--exclude "**/*.{test,spec,stories}.{ts,tsx}" \
--exclude "**/__tests__/**" \
--exclude "**/__mocks__/**" \
--exclude "**/node_modules/**" \
--cleanOutputDir true; then
echo "Documentation generation failed"
exit 1
fi
# Verify documentation was generated
if [ ! -d "docs/docs/auto-docs" ] || [ -z "$(ls -A docs/docs/auto-docs)" ]; then
echo "Documentation directory is empty or missing"
exit 1
fi


- name: Create placeholder documentation
run: |
# Create User Guide placeholder
echo "# User Guide

This section contains the user guide for Talawa Admin.
" > docs/docs/user-guide/intro.md

# Create Developer Guide placeholder
echo "# Developer Guide

This section contains the developer guide for Talawa Admin.
" > docs/docs/developer-guide/intro.md

# Create Reference placeholder
echo "# API Reference

This section contains the auto-generated API documentation for Talawa Admin.
" > docs/docs/developer-guide/reference/README.md

- name: Setup Git Config
run: |
git config user.name "GitHub Actions Bot"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

- name: Check and Commit Documentation
run: |
# Check if there are any changes
if [[ -n "$(git status --porcelain)" ]]; then
# Add all changes
git add docs/docs/auto-docs
git add docs/docs/user-guide
git add docs/docs/developer-guide

# Commit changes
git commit -m "docs: update auto-generated documentation [skip ci]"

# Push changes
git push
else
echo "No changes to commit"
fi
Comment on lines +571 to +587
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Address security concerns in git operations.

The git operations need proper error handling and secure token usage.

Apply these changes:

      - name: Check and Commit Documentation
+       env:
+         GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
+         set -e  # Exit on any error
+         
          # Check if there are any changes
          if [[ -n "$(git status --porcelain)" ]]; then
            # Add all changes
            git add docs/docs/auto-docs
            git add docs/docs/user-guide
            git add docs/docs/developer-guide
            
            # Commit changes
            git commit -m "docs: update auto-generated documentation [skip ci]"
            
            # Push changes
-           git push
+           if ! git push https://${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:${GITHUB_REF}; then
+             echo "Failed to push changes"
+             exit 1
+           fi
          else
            echo "No changes to commit"
          fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Check and Commit Documentation
run: |
# Check if there are any changes
if [[ -n "$(git status --porcelain)" ]]; then
# Add all changes
git add docs/docs/auto-docs
git add docs/docs/user-guide
git add docs/docs/developer-guide
# Commit changes
git commit -m "docs: update auto-generated documentation [skip ci]"
# Push changes
git push
else
echo "No changes to commit"
fi
- name: Check and Commit Documentation
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e # Exit on any error
# Check if there are any changes
if [[ -n "$(git status --porcelain)" ]]; then
# Add all changes
git add docs/docs/auto-docs
git add docs/docs/user-guide
git add docs/docs/developer-guide
# Commit changes
git commit -m "docs: update auto-generated documentation [skip ci]"
# Push changes
if ! git push https://${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:${GITHUB_REF}; then
echo "Failed to push changes"
exit 1
fi
else
echo "No changes to commit"
fi
🧰 Tools
🪛 yamllint (1.35.1)

[error] 579-579: trailing spaces

(trailing-spaces)


[error] 582-582: trailing spaces

(trailing-spaces)

Binary file modified .gitignore
Binary file not shown.
10 changes: 0 additions & 10 deletions .husky/pre-commit

This file was deleted.

9 changes: 4 additions & 5 deletions src/components/CheckIn/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@
}
inputs.push({ name: data.name.trim() });
const pdf = await generate({ template: tagTemplate, inputs });
// istanbul ignore next
const blob = new Blob([pdf.buffer], { type: 'application/pdf' });
// istanbul ignore next

// Convert ArrayBuffer to Uint8Array before creating Blob
const uint8Array = new Uint8Array(pdf.buffer);
const blob = new Blob([uint8Array], { type: 'application/pdf' });

Check warning on line 78 in src/components/CheckIn/TableRow.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/CheckIn/TableRow.tsx#L77-L78

Added lines #L77 - L78 were not covered by tests
const url = URL.createObjectURL(blob);
// istanbul ignore next
window.open(url);
// istanbul ignore next
toast.success('PDF generated successfully!');
} catch (error: unknown) {
const errorMessage =
Expand Down
Loading