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

V2.8.4 #111

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Changes from all commits
Commits
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
78 changes: 34 additions & 44 deletions scrub/tools/templates/sonarqube.template
Original file line number Diff line number Diff line change
Expand Up @@ -133,55 +133,45 @@ then
exit 1
fi

# Retrieve the results from the SonarQube server
PAGE=1
MORE_RESULTS=true
while $MORE_RESULTS; do
# Retrieve the issues from the SonarQube server
PAGE_SIZE=500
# Get the first page
RESULTS_FILE=${{TOOL_ANALYSIS_DIR}}/sonarqube_issues_1.json
curl -u ${{SONARQUBE_TOKEN}}: "${{SONARQUBE_SERVER}}/api/issues/search?ps=$PAGE_SIZE&componentKeys=${{SONARQUBE_PROJECT}}&p=1&${{SONARQUBE_CURL_FLAGS}}" -o $RESULTS_FILE

# Get the number of remaining pages
TOTAL_RESULTS=$(grep -E '[0-9]+' -m 1 -o -a $RESULTS_FILE | sed -n 1p)
TOTAL_PAGES=$(( ( TOTAL_RESULTS / PAGE_SIZE ) + ( TOTAL_RESULTS % PAGE_SIZE > 0 ) ))
if (( TOTAL_PAGES > 20 )); then
TOTAL_PAGES=20
fi

# Get the rest of the issues
for ((CURRENT_PAGE=2; CURRENT_PAGE <= TOTAL_PAGES; CURRENT_PAGE++));
do
# Get the page
RESULTS_FILE=${{TOOL_ANALYSIS_DIR}}/sonarqube_issues_$PAGE.json
curl -u ${{SONARQUBE_TOKEN}}: "${{SONARQUBE_SERVER}}/api/issues/search?ps=500&componentKeys=${{SONARQUBE_PROJECT}}&p=$PAGE&${{SONARQUBE_CURL_FLAGS}}" -o $RESULTS_FILE
# Check to see if the file is empty
if [ ! -s "$RESULTS_FILE" ]; then
exit 1
fi
# Check the contents, verify file is not empty, and make sure the max page hasn't been reached
if grep -q "Can return only the first 10000 results" $RESULTS_FILE; then
echo "WARNING: Not all results have been retrieved."
MORE_RESULTS=false
elif [ $PAGE -gt 20 ]; then
MORE_RESULTS=false
elif grep -q "\"issues\":\[\]" $RESULTS_FILE; then
rm -f $RESULTS_FILE
MORE_RESULTS=false
else
PAGE=$((PAGE+1))
fi
RESULTS_FILE=${{TOOL_ANALYSIS_DIR}}/sonarqube_issues_$CURRENT_PAGE.json
curl -u ${{SONARQUBE_TOKEN}}: "${{SONARQUBE_SERVER}}/api/issues/search?ps=$PAGE_SIZE&componentKeys=${{SONARQUBE_PROJECT}}&p=$CURRENT_PAGE&${{SONARQUBE_CURL_FLAGS}}" -o $RESULTS_FILE
done

# Retrieve the hotspots from the SonarQube server
PAGE=1
MORE_RESULTS=true
while $MORE_RESULTS; do
# Get the first page
RESULTS_FILE=${{TOOL_ANALYSIS_DIR}}/sonarqube_hotspots_1.json
curl -u ${{SONARQUBE_TOKEN}}: "${{SONARQUBE_SERVER}}/api/hotspots/search?ps=$PAGE_SIZE&projectKey=${{SONARQUBE_PROJECT}}&p=1&${{SONARQUBE_CURL_FLAGS}}" -o $RESULTS_FILE

# Get the number of remaining pages
TOTAL_RESULTS=$(( $(grep -E '[0-9]+' -m 1 -o -a $RESULTS_FILE | sed -n 3p) ))
TOTAL_PAGES=$(( ( TOTAL_RESULTS / PAGE_SIZE ) + ( TOTAL_RESULTS % PAGE_SIZE > 0 ) ))
if (( TOTAL_PAGES > 20 )); then
TOTAL_PAGES=20
fi

# Get the rest of the hotspots
for ((CURRENT_PAGE=2; CURRENT_PAGE <= TOTAL_PAGES; CURRENT_PAGE++));
do
# Get the page
RESULTS_FILE=${{TOOL_ANALYSIS_DIR}}/sonarqube_hotspots_$PAGE.json
curl -u ${{SONARQUBE_TOKEN}}: "${{SONARQUBE_SERVER}}/api/hotspots/search?ps=500&projectKey=${{SONARQUBE_PROJECT}}&p=$PAGE&${{SONARQUBE_CURL_FLAGS}}" -o $RESULTS_FILE
# Check to see if the file is empty
if [ ! -s "$RESULTS_FILE" ]; then
exit 1
fi
# Check the contents, verify file is not empty, and make sure the max page hasn't been reached
if grep -q "Can return only the first 10000 results" $RESULTS_FILE; then
echo "WARNING: Not all results have been retrieved."
rm -f $RESULTS_FILE
MORE_RESULTS=false
elif [ $PAGE -gt 20 ]; then
MORE_RESULTS=false
elif grep -q "\"hotspots\":\[\]" $RESULTS_FILE; then
rm -f $RESULTS_FILE
MORE_RESULTS=false
else
PAGE=$((PAGE+1))
fi
RESULTS_FILE=${{TOOL_ANALYSIS_DIR}}/sonarqube_hotspots_$CURRENT_PAGE.json
curl -u ${{SONARQUBE_TOKEN}}: "${{SONARQUBE_SERVER}}/api/hotspots/search?ps=$PAGE_SIZE&projectKey=${{SONARQUBE_PROJECT}}&p=$CURRENT_PAGE&${{SONARQUBE_CURL_FLAGS}}" -o $RESULTS_FILE
done

# Parse the results
Expand Down
Loading