-
-
Notifications
You must be signed in to change notification settings - Fork 6
Enhancement: Add PR analysis using linting tools, static analysis and Github API. #14
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
Open
AyushBurde
wants to merge
31
commits into
keploy:main
Choose a base branch
from
AyushBurde:pr-analysis-linting-feature
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
e441889
feat: add PR linting, static analysis, and GitHub API integration
AyushBurde 561f76a
test: trigger GitHub Action for linting
AyushBurde 7c5f87b
test: trigger GitHub Action for linting
AyushBurde 7cfc47d
test: trigger GitHub Action for linting
AyushBurde e34a49e
Add custom TestGPT workflow
AyushBurde 049ee88
done
AyushBurde 963736a
done
AyushBurde 3104821
Disable CLA workflow in fork
AyushBurde b1feb67
done
AyushBurde 294c35b
done
AyushBurde 7dba443
d
AyushBurde 70e8cd0
d
AyushBurde 876988a
done
AyushBurde 390650d
done
AyushBurde 66b233c
d
AyushBurde 8310f2d
f
AyushBurde f08185a
done
AyushBurde e8020b4
d
AyushBurde cfbeb10
d
AyushBurde a500ff6
d
AyushBurde fbb06ef
Test: Updated dummy.js for Keploy testing
AyushBurde d72ae44
fd
AyushBurde e5eeef8
Added keploy record before test
AyushBurde 55c367a
done
AyushBurde 7a23c34
done
AyushBurde 8d1fb27
d
AyushBurde f6d1e03
done
AyushBurde c74622a
d
AyushBurde e1a8867
d
AyushBurde b523f6c
d
AyushBurde 7197e98
d
AyushBurde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,29 @@ | ||
| name: "CLA Assistant" | ||
| # name: "CLA Assistant" | ||
|
|
||
| on: | ||
| issue_comment: | ||
| types: | ||
| - "created" | ||
| pull_request_target: | ||
| types: | ||
| - "opened" | ||
| - "closed" | ||
| - "synchronize" | ||
| # on: | ||
| # issue_comment: | ||
| # types: | ||
| # - "created" | ||
| # pull_request_target: | ||
| # types: | ||
| # - "opened" | ||
| # - "closed" | ||
| # - "synchronize" | ||
|
|
||
| jobs: | ||
| cla-assistant: | ||
| runs-on: "ubuntu-latest" | ||
| steps: | ||
| - name: "CLA Assistant" | ||
| if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target') | ||
| uses: "cla-assistant/github-action@v2.1.3-beta" | ||
| env: | ||
| GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
| PERSONAL_ACCESS_TOKEN: "${{ secrets.PRO_ACCESS_TOKEN }}" | ||
| with: | ||
| remote-organization-name: "keploy" | ||
| remote-repository-name: "keploy" | ||
| path-to-signatures: "etc/cla-signatures/signatures.json" | ||
| path-to-document: "https://github.com/keploy/keploy/tree/main/.github/CLA.md" | ||
| branch: "cla-signatures" | ||
| allowlist: "keploy-bot,renovate" | ||
| # jobs: | ||
| # cla-assistant: | ||
| # runs-on: "ubuntu-latest" | ||
| # steps: | ||
| # - name: "CLA Assistant" | ||
| # if: github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target' | ||
| # uses: "cla-assistant/github-action@v2.1.3-beta" | ||
| # env: | ||
| # GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
| # PERSONAL_ACCESS_TOKEN: "${{ secrets.PRO_ACCESS_TOKEN }}" | ||
| # with: | ||
| # remote-organization-name: "keploy" | ||
| # remote-repository-name: "keploy" | ||
| # path-to-signatures: "etc/cla-signatures/signatures.json" | ||
| # path-to-document: "https://github.com/keploy/keploy/tree/main/.github/CLA.md" | ||
| # branch: "cla-signatures" | ||
| # allowlist: "keploy-bot,renovate" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| name: Keploy Test & Lint | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ main ] | ||
|
|
||
| jobs: | ||
| keploy-test-and-lint: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Run Keploy TestGPT Action | ||
| id: keploy-test-report | ||
| uses: keploy/testGPT@main | ||
| with: | ||
| working-directory: ./ # Adjust if project structure differs | ||
| command: 'your-test-command-here' # Update this | ||
| keploy-path: ./ # Path where Keploy binary is installed | ||
| delay: 10 | ||
|
|
||
|
|
||
|
|
||
| - name: Fetch PR Details | ||
| id: pr-details | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| github-token: ${{ github.token }} | ||
| script: | | ||
| const pr = context.payload.pull_request; | ||
| if (!pr) { | ||
| console.log("Not a PR event."); | ||
| return; | ||
| } | ||
| const prDetails = await github.rest.pulls.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: pr.number, | ||
| }); | ||
| const changedFiles = await github.paginate(github.rest.pulls.listFiles, { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: pr.number, | ||
| per_page: 100, | ||
| }); | ||
| const filePaths = changedFiles.map(file => file.filename); | ||
| console.log("Changed Files:", filePaths); | ||
| const metadata = { | ||
| title: pr.title, | ||
| author: pr.user.login, | ||
| files: filePaths | ||
| }; | ||
| console.log("PR Metadata:", metadata); | ||
|
|
||
| return metadata; | ||
|
|
||
|
|
||
|
|
||
| - name: Detect Programming Languages | ||
| id: lang-detect | ||
| run: | | ||
| echo "Detecting languages..." | ||
| files=$(echo '${{ steps.pr-details.outputs.result }}' | jq -r '.files[]') | ||
|
|
||
| touch languages.txt | ||
| for file in $files; do | ||
| ext="${file##*.}" | ||
| case "$ext" in | ||
| js|ts) echo "JavaScript" >> languages.txt ;; | ||
| go) echo "Go" >> languages.txt ;; | ||
| py) echo "Python" >> languages.txt ;; | ||
| *) echo "Unknown" >> languages.txt ;; | ||
| esac | ||
| done | ||
|
|
||
| echo "Languages detected:" | ||
| cat languages.txt | ||
| shell: bash | ||
|
|
||
| - name: Lint Changed Files | ||
| run: | | ||
| echo "Running linters..." | ||
| files=$(echo '${{ steps.pr-details.outputs.result }}' | jq -r '.files[]') | ||
| touch lint_report.txt | ||
|
|
||
| for file in $files; do | ||
| ext="${file##*.}" | ||
| if [[ "$ext" == "js" || "$ext" == "ts" ]]; then | ||
| echo "Linting $file with ESLint..." >> lint_report.txt | ||
| eslint "$file" >> lint_report.txt 2>&1 || echo "Errors in $file" >> lint_report.txt | ||
| elif [[ "$ext" == "go" ]]; then | ||
| echo "Linting $file with Golint..." >> lint_report.txt | ||
| golint "$file" >> lint_report.txt 2>&1 | ||
| else | ||
| echo "No linter for $file" >> lint_report.txt | ||
| fi | ||
| done | ||
|
|
||
| cat lint_report.txt | ||
| shell: bash | ||
|
|
||
| - name: Comment Lint Results on PR | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| github-token: ${{ github.token }} | ||
| script: | | ||
| const fs = require('fs'); | ||
| const lintReport = fs.readFileSync('lint_report.txt', 'utf8'); | ||
| const pr = context.payload.pull_request; | ||
| if (!pr) { | ||
| console.log("No PR context."); | ||
| return; | ||
| } | ||
| github.rest.issues.createComment({ | ||
| issue_number: pr.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: `### 🧹 Lint Report:\n\`\`\`\n${lintReport}\n\`\`\`` | ||
| }); | ||
|
|
||
| - name: Comment Keploy Test Report on PR | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| github-token: ${{ github.token }} | ||
| script: | | ||
| const report = `${{ steps.keploy-test-report.outputs.KEPLOY_REPORT }}`; | ||
| if (!report) { | ||
| console.error('Error: KEPLOY_REPORT not found.'); | ||
| return; | ||
| } | ||
| github.rest.issues.createComment({ | ||
| issue_number: context.payload.pull_request.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: report | ||
| }); | ||
| - name: Debug Context | ||
| run: echo "${{ toJson(github) }}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # name: Test TestGPT Lint + Static Analysis | ||
|
|
||
| # on: | ||
| # pull_request: | ||
| # types: [opened, synchronize, reopened] | ||
|
|
||
| # jobs: | ||
| # run-testgpt: | ||
| # runs-on: ubuntu-latest | ||
|
|
||
| # steps: | ||
| # - name: Checkout Code | ||
| # uses: actions/checkout@v2 | ||
|
|
||
| # # 👇 Add this to test your custom TestGPT Action locally | ||
| # - name: Run Custom TestGPT Action | ||
| # uses: ./ # This refers to the action.yml in the root directory | ||
| # with: | ||
| # working-directory: ./ | ||
| # keploy-path: ./ | ||
| # command: "echo Hello from TestGPT!" | ||
|
|
||
| # # Optional: Show files changed in PR (testing GitHub API call) | ||
| # - name: Show Changed Files | ||
| # run: | | ||
| # echo "Fetching changed files..." | ||
| # curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
| # https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files \ | ||
| # | jq '.[].filename' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,89 +0,0 @@ | ||
| name: 'Keploy TestGPT' | ||
| description: "TestGPT is a GitHub Action designed to execute Keploy test cases and generate detailed test reports." | ||
| author: Sonichigo | ||
| branding: | ||
| icon: 'aperture' | ||
| color: 'orange' | ||
|
|
||
| inputs: | ||
| working-directory: | ||
| description: Relative path under $GITHUB_WORKSPACE where the repository was checked out | ||
| required: true | ||
| command: | ||
| description: Command to run the application | ||
| required: true | ||
| keploy-path: | ||
| description: Path to keploy | ||
| required: true | ||
| default: ./ | ||
| delay: | ||
| description: Time to start application | ||
| required: true | ||
| default: 10 | ||
| container-name: | ||
| description: Name of the container in case of "docker compose" command | ||
| build-delay: | ||
| description: Time to wait for docker container build | ||
| default: 50s | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Setup GITHUB_PATH for script | ||
| run: | | ||
| echo "${{ github.action_path }}" >> $GITHUB_PATH | ||
| echo "${{ inputs.working-directory }}" | ||
| shell: bash | ||
| - name: Grant permissions | ||
| run: chmod +x ${GITHUB_ACTION_PATH}/install.sh | ||
| shell: bash | ||
| - id: keploy-test-report | ||
| name: Run Script | ||
| run: | | ||
| ${GITHUB_ACTION_PATH}/install.sh > ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt | ||
| cat ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt | ||
|
|
||
| # Search for the complete testrun summary and extract total tests, total test passed, and total test failed data | ||
| grep -oE "COMPLETE TESTRUN SUMMARY\.\s+Total tests: [0-9]+" ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt | sed -r "s/\x1B\[[0-9;]*[mGK]//g" > ${GITHUB_WORKSPACE}/${WORKDIR}/final_total_tests.out | ||
| grep -oE "COMPLETE TESTRUN SUMMARY\.\s+Total test passed: [0-9]+" ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt | sed -r "s/\x1B\[[0-9;]*[mGK]//g" > ${GITHUB_WORKSPACE}/${WORKDIR}/final_total_passed.out | ||
| grep -oE "COMPLETE TESTRUN SUMMARY\.\s+Total test failed: [0-9]+" ${GITHUB_WORKSPACE}/${WORKDIR}/report.txt | sed -r "s/\x1B\[[0-9;]*[mGK]//g" > ${GITHUB_WORKSPACE}/${WORKDIR}/final_total_failed.out | ||
|
|
||
| # Combine the results into a single file and prepare output | ||
| cat ${GITHUB_WORKSPACE}/${WORKDIR}/final_total_tests.out ${GITHUB_WORKSPACE}/${WORKDIR}/final_total_passed.out ${GITHUB_WORKSPACE}/${WORKDIR}/final_total_failed.out > ${GITHUB_WORKSPACE}/${WORKDIR}/final.out | ||
| echo 'KEPLOY_REPORT<<EOF' > $GITHUB_OUTPUT | ||
| cat ${GITHUB_WORKSPACE}/${WORKDIR}/final.out >> $GITHUB_OUTPUT | ||
| echo 'EOF' >> $GITHUB_OUTPUT | ||
| cat $GITHUB_OUTPUT | ||
| shell: bash | ||
| env: | ||
| WORKDIR: ${{ inputs.working-directory }} | ||
| DELAY: ${{ inputs.delay }} | ||
| COMMAND : ${{ inputs.command }} | ||
| KEPLOY_PATH: ${{inputs.keploy-path}} | ||
| - name: Check if report is generated | ||
| run: | | ||
| if [ -s ${GITHUB_WORKSPACE}/${WORKDIR}/final.out ]; then | ||
| echo "Report generated successfully." | ||
| else | ||
| echo "Error: Report not generated." >&2 | ||
| exit 1 | ||
| fi | ||
| shell: bash | ||
| - name: Comment on PR | ||
| if: success() | ||
| uses: actions/github-script@v6 | ||
| env: | ||
| KEPLOY_REPORT: ${{ steps.keploy-test-report.outputs.KEPLOY_REPORT }} | ||
| with: | ||
| github-token: ${{ github.token }} | ||
| script: | | ||
| if (!process.env.KEPLOY_REPORT) { | ||
| console.error('Error: KEPLOY_REPORT not found.'); | ||
| process.exit(1); | ||
| } | ||
| github.rest.issues.createComment({ | ||
| issue_number: context.issue.number, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: process.env.KEPLOY_REPORT | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| const http = require('http'); | ||
|
|
||
| const server = http.createServer((req, res) => { | ||
| res.write('Hello Keploy'); | ||
| res.end(); | ||
| }); | ||
|
|
||
| server.listen(3000, () => { | ||
| console.log('Server running at http://localhost:3000/'); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving the language detection and lint logic into reusable shell scripts instead of inline bash – it'll keep the workflow clean and easier to maintain.