diff --git a/.github/action.yml b/.github/action.yml new file mode 100644 index 0000000..609454f --- /dev/null +++ b/.github/action.yml @@ -0,0 +1,105 @@ +name: Generate Wiki from Code + +on: + pull_request: + branches: [ main ] + types: [ closed ] + +jobs: + call-adapts-api: + if: github.event.pull_request.merged == true # skip if PR is merely closed + runs-on: ubuntu-latest + + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install runtime deps + run: | + pip install --upgrade pip requests adaptsapi + # gh CLI comes pre‑installed on GitHub‑hosted runners + + # ───────────────────── Fetch developer e‑mail ───────────────────── + - name: Get PR author e-mail (enterprise) + id: pr_author + env: + GH_TOKEN: ${{ secrets.ENTERPRISE_READ_TOKEN }} # PAT or App token with read:org + run: | + login="${{ github.event.pull_request.user.login }}" + org="${{ github.repository_owner }}" + + # Single-line GraphQL avoids the UNKNOWN_CHAR error + email=$(gh api graphql \ + -f query='query($login:String!,$org:String!){user(login:$login){organizationVerifiedDomainEmails(login:$org)}}' \ + -f login="$login" \ + -f org="$org" \ + --jq '.data.user.organizationVerifiedDomainEmails[0]') + + # Fallback to HEAD-commit author e-mail if nothing came back + if [ -z "$email" ] || [ "$email" = "null" ]; then + sha="${{ github.event.pull_request.head.sha }}" + email=$(git show -s --format='%ae' "$sha") + fi + + echo "email=$email" >>"$GITHUB_OUTPUT" + + - name: Get repo size + id: repo_size + run: | + size=$(git ls-files | xargs cat | wc -c) + echo "size=${size:-0}" >> $GITHUB_OUTPUT + + # ───────────────────── Call Adapts API ───────────────────── + - name: Invoke Adapts API + env: + ADAPTS_API_KEY: ${{ secrets.ADAPTS_API_KEY }} + AUTHOR_EMAIL: ${{ steps.pr_author.outputs.email }} + REPO_LANG: ${{ steps.repo_lang.outputs.language }} + REPO_SIZE: ${{ steps.repo_size.outputs.size }} + REFRESH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + python <<'PY' + import os, json + from adaptsapi.generate_docs import post, PayloadValidationError + + repo_full = os.getenv("GITHUB_REPOSITORY") + repo_name = repo_full.split("/")[-1] + repo_url = f"https://github.com/{repo_full}" + branch = os.getenv("GITHUB_REF_NAME") + + payload = { + "email_address": os.getenv("AUTHOR_EMAIL"), + "user_name": os.getenv("GITHUB_ACTOR"), + "repo_object": { + "repository_name": repo_name, + "source": "github", + "repository_url": repo_url, + "branch": branch, + "size": os.getenv("REPO_SIZE"), + "language": os.getenv("REPO_LANG") or "Unknown", + "is_private": False, + "git_provider_type": "github", + "refresh_token": os.getenv("REFRESH_TOKEN"), + }, + } + + try: + resp = post( + "https://ycdwnfjohl.execute-api.us-east-1.amazonaws.com/prod/generate_wiki_docs", + os.environ["ADAPTS_API_KEY"], + payload, + ) + resp.raise_for_status() + print("✅ Success:", json.dumps(resp.json(), indent=2)) + except PayloadValidationError as e: + print("❌ Invalid payload:", e) + raise + except Exception as e: + print("❌ Request failed:", e) + raise + PY \ No newline at end of file diff --git a/README.md b/README.md index 5e520d8..818ff58 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # GUI-based-Algorithm-Calculator -Java Graphical User Interface application which contain 6 type of sorting algorithms. +Java Graphical User Interface application which contain 6 type of sorting algorithms. Check it out. # 1. Abstract: Algorithm calculator is a graphical user interface application software. Where user can compute the sorting operations on any integer array and get instant answer. This could be time saving for student and faculty while learning and teaching the algorithms.