-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Development: Add client sided endpoints parser (#8580)
- Loading branch information
1 parent
151fcba
commit b67c333
Showing
10 changed files
with
2,812 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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,36 +1,62 @@ | ||
# As this GitHub Workflow currently fails for many valid pull requests, it is currently disabled. | ||
|
||
#name: Analysis-of-Endpoint-Connections | ||
# | ||
#on: | ||
# pull_request: | ||
# types: | ||
# - opened | ||
# - synchronize | ||
# paths: | ||
# - 'src/main/java/**' | ||
# - 'src/main/webapp/**' | ||
# | ||
#jobs: | ||
# analysis-of-endpoint-connections: | ||
# timeout-minutes: 10 | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - name: Checkout code | ||
# uses: actions/checkout@v4 | ||
# with: | ||
# fetch-depth: 0 | ||
# | ||
# - name: Get list of modified files | ||
# run: | | ||
# git diff --name-only origin/${{ github.event.pull_request.base.ref }} HEAD > modified_files.txt | ||
# | ||
# - name: Set up JDK 21 | ||
# uses: actions/setup-java@v2 | ||
# with: | ||
# java-version: '21' | ||
# distribution: 'adopt' | ||
# | ||
# - name: Run analysis-of-endpoint-connections | ||
# run: | | ||
# ./gradlew :supporting_scripts:analysis-of-endpoint-connections:run --args="$(cat modified_files.txt)" | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
types: | ||
- opened | ||
- synchronize | ||
paths: | ||
- 'src/main/java/**' | ||
- 'src/main/webapp/**' | ||
|
||
# Keep in sync with build.yml and test.yml and codeql-analysis.yml | ||
env: | ||
CI: true | ||
node: 20 | ||
java: 21 | ||
|
||
jobs: | ||
analysis-of-endpoint-connections: | ||
timeout-minutes: 10 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Get list of modified files | ||
run: | | ||
git diff --name-only origin/${{ github.event.pull_request.base.ref }} HEAD > modified_files.txt | ||
# Analyze the client sided REST-API calls | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '${{ env.node }}' | ||
|
||
- name: Install and compile TypeScript | ||
run: | | ||
cd supporting_scripts/analysis-of-endpoint-connections/src/main/typeScript/ | ||
npm install | ||
tsc -p tsconfig.analysisOfEndpointConnections.json | ||
- name: Run analysis-of-endpoint-connections-client | ||
run: | | ||
node supporting_scripts/analysis-of-endpoint-connections/src/main/typeScript/AnalysisOfEndpointConnectionsClient.js | ||
- name: Upload JSON file | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: rest-calls-json | ||
path: supporting_scripts/analysis-of-endpoint-connections/restCalls.json | ||
|
||
# Analyze the server sided endpoints | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '${{ env.java }}' | ||
|
||
- name: Run analysis-of-endpoint-connections | ||
run: | | ||
./gradlew :supporting_scripts:analysis-of-endpoint-connections:run --args="$(cat modified_files.txt)" |
This file contains 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
This file contains 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
19 changes: 19 additions & 0 deletions
19
supporting_scripts/analysis-of-endpoint-connections/eslint.conjig.json
This file contains 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,19 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"extends": [ | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"parserOptions": { | ||
"ecmaVersion": 2020, | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"rules": {}, | ||
"settings": { | ||
"react": { | ||
"version": "detect" | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...alysis-of-endpoint-connections/src/main/typeScript/AnalysisOfEndpointConnectionsClient.ts
This file contains 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,49 @@ | ||
import { readdirSync } from 'node:fs'; | ||
import { join, resolve } from 'node:path'; | ||
import { Preprocessor } from './Preprocessor'; | ||
import { Postprocessor } from './Postprocessor'; | ||
import { writeFileSync } from 'node:fs'; | ||
|
||
/** | ||
* Recursively collects all TypeScript files in a directory. | ||
* | ||
* @param dir - The directory to search for TypeScript files. | ||
* @param files - An array to store the collected TypeScript file paths. | ||
* @returns An array of TypeScript file paths relative to 'src/main/webapp/app'. | ||
*/ | ||
function collectTypeScriptFiles(dir: string, files: string[] = []) : string[] { | ||
const entries = readdirSync(dir, { withFileTypes: true }); | ||
for (const entry of entries) { | ||
const fullPath = join(dir, entry.name); | ||
|
||
const filePathFromSrcFolder = fullPath.substring(fullPath.indexOf('src/main/webapp/app')); | ||
if (entry.isDirectory()) { | ||
collectTypeScriptFiles(fullPath, files); | ||
} else if (entry.isFile() && entry.name.endsWith('.ts')) { | ||
files.push(filePathFromSrcFolder); | ||
} | ||
} | ||
return files; | ||
} | ||
|
||
const clientDirPath = resolve('src/main/webapp/app'); | ||
|
||
const tsFiles = collectTypeScriptFiles(clientDirPath); | ||
|
||
// preprocess each file | ||
tsFiles.forEach((filePath) => { | ||
const preProcessor = new Preprocessor(filePath); | ||
preProcessor.preprocessFile(); | ||
}); | ||
|
||
// postprocess each file | ||
tsFiles.forEach((filePath) => { | ||
const postProcessor = new Postprocessor(filePath); | ||
postProcessor.extractRestCalls(); | ||
}); | ||
|
||
try { | ||
writeFileSync('supporting_scripts/analysis-of-endpoint-connections/restCalls.json', JSON.stringify(Postprocessor.filesWithRestCalls, null, 2)); | ||
} catch (error) { | ||
console.error('Failed to write REST calls to file:', error); | ||
} |
Oops, something went wrong.