Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 23 additions & 5 deletions .github/workflows/build_jar.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
name: Build JAR on Release
name: Build JAR

on:
release:
types: [published] # Solo al publicar una release
workflow_dispatch:
pull_request:
branches:
- '**'
push:
branches:
- '**'
workflow_dispatch:

jobs:
build:
Expand Down Expand Up @@ -52,12 +58,24 @@ jobs:

- name: Rename artifact using release tag (or manual)
run: |
TAG="${{ github.event.release.tag_name || 'manual' }}"
OUT="sonar-report-${TAG}.jar"
if [ "${{ github.event_name }}" == "release" ]; then
TAG="${{ github.event.release.tag_name }}"
OUT="sonar-report-${TAG}.jar"
elif [ "${{ github.event_name }}" == "pull_request" ]; then
PR_NUM="${{ github.event.pull_request.number }}"
SHORT_SHA="${GITHUB_SHA:0:7}"
OUT="sonar-report-pr${PR_NUM}-${SHORT_SHA}.jar"
else
# push or workflow_dispatch
BRANCH="${GITHUB_REF_NAME}"
SHORT_SHA="${GITHUB_SHA:0:7}"
SAFE_BRANCH=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9_-]/_/g')
OUT="sonar-report-${SAFE_BRANCH}-${SHORT_SHA}.jar"
fi
cp "$ARTIFACT_PATH" "$OUT"
echo "OUT=${OUT}" >> "$GITHUB_ENV"

- name: Upload workflow artifact (optional)
- name: Upload workflow artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.OUT }}
Expand Down
32 changes: 21 additions & 11 deletions pdf-generator/src/main/java/com/bi/GenerateSonarReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -600,24 +600,33 @@ public static void main(String[] args) throws IOException {
String currentLocations = existing.getString("location");
String file = originalObj.getString("component");
file = file.contains(":") ? file.split(":", 2)[1].trim() : file;
JSONObject textLines = originalObj.getJSONObject("textRange");
String textLine = Integer.toString(textLines.getInt("startLine"));
existing.put("location", currentLocations + " | " + file + ": " + textLine);

// Check if the issue is in a line of text or is the file itself
if (originalObj.has("textRange")) {
JSONObject textLines = originalObj.getJSONObject("textRange");
String textLine = Integer.toString(textLines.getInt("startLine"));
existing.put("location", currentLocations + " | " + file + ": " + textLine);
}
else existing.put("location", currentLocations + " | " + file);
} else {
// Is new
JSONObject newObj = new JSONObject();
JSONObject textLines = originalObj.getJSONObject("textRange");


String file = originalObj.getString("component");
file = file.contains(":") ? file.split(":", 2)[1].trim() : file;
String textLine = Integer.toString(textLines.getInt("startLine"));

newObj.put("ruleKey", ruleKey);
newObj.put("count", 1);
newObj.put("severity", originalObj.getString("severity"));
newObj.put("message", originalObj.getString("message"));
newObj.put("type", originalObj.getString("type"));
newObj.put("location", file + ": " + textLine);

// Check if the issue is in a line of text or is the file itself
if (originalObj.has("textRange")) {
JSONObject textLines = originalObj.getJSONObject("textRange");
String textLine = Integer.toString(textLines.getInt("startLine"));
newObj.put("location", file + ": " + textLine);
}
else newObj.put("location", file);
issuesMap.put(ruleKey, newObj);
}
}
Expand All @@ -636,7 +645,7 @@ public static void main(String[] args) throws IOException {
}
pdf.insertIndexAtBeginning();
pdf.addCoverPage("SonarQube Report", "Generated for "+ project);
pdf.save("reportes.pdf");
pdf.save("sonarqube-report.pdf");
}

private static String minsToDaysHoursMins(int minutes) {
Expand All @@ -652,10 +661,11 @@ private String getCountAsString(JSONArray jsonArray, int index) {
try {
return String.valueOf(jsonArray.getJSONObject(index).getString("count"));
} catch (JSONException e) {
System.err.println("Error al obtener 'count' en el índice " + index + ": " + e.getMessage());
System.err.println("Error at obtaning 'count' in the index " + index + ": " + e.getMessage());
return "";
}
}
return "";
}
}

}