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/admin docs gen #3157

Open
wants to merge 31 commits into
base: develop-postgres
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f27d655
#2970:autodoc-generate
bint-Eve Jan 5, 2025
69ff3e1
#2970:autodoc-generate
bint-Eve Jan 5, 2025
2184d6c
#2970:autodoc-generate
bint-Eve Jan 5, 2025
7ab86e2
#2970:autodoc-generate
bint-Eve Jan 5, 2025
da69221
Merge branch 'develop-postgres' into feature/admin-docs-refactor
bint-Eve Jan 5, 2025
a1d2a8d
#2970:autodoc-generate-talawa-Admin
bint-Eve Jan 5, 2025
d845f31
#2970:autodoc-generate-talawa-Admin
bint-Eve Jan 5, 2025
8d621fe
#2970:autodoc-generate-talawa-Admin
bint-Eve Jan 5, 2025
d3c57fe
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
7437dbd
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
5d3da67
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
923d293
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
61766d9
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
24753fc
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
070146c
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
81fdf93
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
ad123b0
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
1ba51b5
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
12ea144
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
fd7b82e
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
a39f982
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
0a5ab43
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
30811a5
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 6, 2025
ab2eee9
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 7, 2025
061a3a0
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 7, 2025
21539ef
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 7, 2025
0d72d8e
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 7, 2025
9ed5889
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 7, 2025
c7adccb
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 7, 2025
1972193
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 7, 2025
d181242
#2970: autoGen-talawa-admin-docs-debugging
bint-Eve Jan 7, 2025
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/**"
]
}
144 changes: 144 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 All @@ -16,6 +16,9 @@
branches:
- '**'

permissions:
contents: write

env:
CODECOV_UNIQUE_NAME: CODECOV_UNIQUE_NAME-${{ github.run_id }}-${{ github.run_number }}

Expand Down Expand Up @@ -449,3 +452,144 @@
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
Comment on lines +466 to +484
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

Improve error handling in the API check script.

The current implementation has a few areas for improvement:

  1. Use direct command checking instead of $?
  2. Consider using --fail-with-body with curl to capture error messages

Apply this diff to improve the error handling:

-            if [ $? -ne 0 ]; then
-              echo "Failed to call GitHub API"
+            if ! response=$(curl -s --fail-with-body -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
+              "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER"); then
+              echo "Failed to call GitHub API: $response"

Committable suggestion skipped: line range outside the PR's diff.

🧰 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)


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 +456 to +501
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 error handling and API interaction in merge conflict check.

The implementation can be improved in several areas:

  1. Use direct command checking instead of $?
  2. Include error details from the API response
  3. Consider rate limiting
  4. Move retry configuration to environment variables

Apply this diff to improve the implementation:

  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
        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 }}" \
-             "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
+           if ! response=$(curl -s --fail-with-body -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
+             "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER"); then
+             echo "Failed to call GitHub API: $response"
+             if [ $i -eq $MAX_RETRIES ]; then
                exit 1
              fi
-             sleep $retry_delay
+             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
+             if [ $i -eq $MAX_RETRIES ]; then
                exit 1
              fi
-             sleep $retry_delay
+             sleep $RETRY_DELAY
            fi
          done
📝 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
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 --fail-with-body -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER"); then
echo "Failed to call GitHub API: $response"
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:
# Step 1: Checkout the code
- name: Checkout Code
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

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

# Step 3: Install dependencies
- name: Install Dependencies
run: |
npm ci
npm install -g typedoc typedoc-plugin-markdown

# Step 4: Generate Documentation
- name: Generate Documentation
run: |
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

# Step 5: Create placeholder documentation (only if not present)
- name: Create Placeholder Documentation
run: |
mkdir -p docs/docs/user-guide
mkdir -p docs/docs/developer-guide/reference

if [ ! -f docs/docs/user-guide/intro.md ]; then
printf "# User Guide\n\nThis section contains the user guide for Talawa Admin.\n" > docs/docs/user-guide/intro.md
fi

if [ ! -f docs/docs/developer-guide/intro.md ]; then
printf "# Developer Guide\n\nThis section contains the developer guide for Talawa Admin.\n" > docs/docs/developer-guide/intro.md
fi

if [ ! -f docs/docs/developer-guide/reference/README.md ]; then
printf "# API Reference\n\nThis section contains the auto-generated API documentation for Talawa Admin.\n" > docs/docs/developer-guide/reference/README.md
fi

# Step 6: Set up Git configuration
- name: Setup Git Config
run: |
git config --global user.email "actions@github.com"
git config --global user.name "gh-actions"

# Step 7: Check and Commit Changes
- name: Commit Documentation Changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.event.pull_request.head.repo.full_name }}.git

git fetch origin ${{ github.event.pull_request.head.ref }}
git checkout ${{ github.event.pull_request.head.ref }}

git add docs/docs/auto-docs/
git add docs/docs/developer-guide/
git add docs/docs/user-guide/

if [ -n "$(git status --porcelain)" ]; then
git commit -m "docs: update auto-generated documentation [skip ci]"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
else
echo "No changes to commit."
fi

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

This file was deleted.

Empty file added docs/docs/auto-docs/.gitignore
Empty file.
Empty file.
Empty file added docs/docs/user-guide/.gitignore
Empty file.
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 @@ export const TableRow = ({
}
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' });
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