Copilot commented on code in PR #13140:
URL: https://github.com/apache/cloudstack/pull/13140#discussion_r3409961437
##########
.github/workflows/sonar-check.yml:
##########
@@ -65,3 +65,51 @@ jobs:
verbose: true
name: codecov
token: ${{ secrets.CODECOV_TOKEN }}
+ - name: Compute Coverage Grade
+ id: grade
+ run: bash scripts/coverage-grade.sh
client/target/site/jacoco-aggregate/jacoco.xml
+ - name: Post Coverage Grade Comment on PR
+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 #
v9.0.0
+ with:
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+ script: |
+ const grade = '${{ steps.grade.outputs.coverage_grade }}';
+ const label = '${{ steps.grade.outputs.coverage_grade_label
}}';
+ const linePct = '${{ steps.grade.outputs.line_coverage }}';
+ const branchPct = '${{ steps.grade.outputs.branch_coverage }}';
+ const emojiMap = { A: '🟢', B: '🟡', C: '🟠', D: '🔴', F: '⛔' };
+ const emoji = emojiMap[grade] ?? '❓';
+ const runUrl =
`${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
+
+ const branchRow = branchPct !== 'N/A'
+ ? `| Branch coverage | **${branchPct}%** |`
+ : '';
+
+ const body = [
+ `## ${emoji} Test Coverage Grade: \`${grade}\` — ${label}`,
+ '',
+ '| Metric | Value |',
+ '|--------|-------|',
+ `| Line coverage | **${linePct}%** |`,
+ branchRow,
+ '',
+ '### Grade Scale',
+ '| Grade | Line Coverage | Meaning |',
+ '|-------|--------------|---------|',
+ '| 🟢 A | ≥ 80% | Excellent - this code sleeps well at night 😴 |',
+ '| 🟡 B | 60-79% | Good - almost there, don\'t stop now 😉 |',
+ '| 🟠 C | 40-59% | Acceptable - your code is wearing a seatbelt,
but no airbags 😬 |',
+ '| 🔴 D | 20-39% | Marginal - boldly shipping where no test has
gone before 🖖 |',
+ '| ⛔ F | < 20% | Failing - tests? what tests? 🔥 |',
+ '',
+ '> Branch coverage is shown as a secondary signal. Grade is
determined by **line coverage**.',
+ `> [View full Actions run](${runUrl})`,
+ ].filter(l => l !== undefined).join('\n');
+
+ await github.rest.issues.createComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: context.issue.number,
+ body: body,
+ });
Review Comment:
This step calls `github.rest.issues.createComment(...)`. With the workflow
permissions currently set to `pull-requests: write` (and no `issues: write`),
the default `GITHUB_TOKEN` will typically get a 403 when creating issue
comments. Add `issues: write` to the workflow `permissions:` block (and
consider whether `pull-requests: write` is still needed).
##########
scripts/coverage-grade.sh:
##########
@@ -0,0 +1,174 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# coverage-grade.sh
+#
+# Parses the JaCoCo aggregate XML report and outputs an A–F coverage grade.
+#
+# Usage:
+# ./scripts/coverage-grade.sh [path/to/jacoco.xml]
+#
+# Exit codes:
+# 0 – grade is D or above (line coverage >= 20%)
+# 1 – grade is F (line coverage < 20%)
+#
Review Comment:
The exit-code documentation doesn't match the script behavior: the script
also exits with code 2 (missing report / missing counters), but only 0 and 1
are documented. This can confuse CI consumers and local users interpreting
failures.
##########
.github/workflows/sonar-check.yml:
##########
@@ -65,3 +65,51 @@ jobs:
verbose: true
name: codecov
token: ${{ secrets.CODECOV_TOKEN }}
+ - name: Compute Coverage Grade
+ id: grade
+ run: bash scripts/coverage-grade.sh
client/target/site/jacoco-aggregate/jacoco.xml
+ - name: Post Coverage Grade Comment on PR
+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 #
v9.0.0
+ with:
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+ script: |
+ const grade = '${{ steps.grade.outputs.coverage_grade }}';
+ const label = '${{ steps.grade.outputs.coverage_grade_label
}}';
+ const linePct = '${{ steps.grade.outputs.line_coverage }}';
+ const branchPct = '${{ steps.grade.outputs.branch_coverage }}';
+ const emojiMap = { A: '🟢', B: '🟡', C: '🟠', D: '🔴', F: '⛔' };
+ const emoji = emojiMap[grade] ?? '❓';
+ const runUrl =
`${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
+
+ const branchRow = branchPct !== 'N/A'
+ ? `| Branch coverage | **${branchPct}%** |`
+ : '';
Review Comment:
When branch coverage is not available, `branchRow` is set to an empty
string. Since the body array only filters out `undefined`, this leaves a blank
line inside the markdown table (ending the table early). Prefer using
`undefined` and keep the existing filter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]