Skip to content

Commit

Permalink
Development: Add client sided endpoints parser (#8580)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan-Thurner authored Aug 13, 2024
1 parent 151fcba commit b67c333
Show file tree
Hide file tree
Showing 10 changed files with 2,812 additions and 38 deletions.
98 changes: 62 additions & 36 deletions .github/workflows/analysis-of-endpoint-connections.yml
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)"
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ on:
types:
- created

# Keep in sync with codeql-analysis.yml and test.yml
# Keep in sync with codeql-analysis.yml and test.yml and analysis-of-endpoint-connections.yml
env:
CI: true
node: 20
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ on:
schedule:
- cron: '0 16 * * 0'

# Keep in sync with build.yml and test.yml
# Keep in sync with build.yml and test.yml and analysis-of-endpoint-connections.yml
env:
CI: true
node: 20
Expand Down
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"
}
}
}
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);
}
Loading

0 comments on commit b67c333

Please sign in to comment.