Skip to content

Commit ae0e8a5

Browse files
MishaKavclaude
andauthored
Add text-instead-badge option implementation (#235)
* Add text-instead-badge option to display coverage as text Implemented the text-instead-badge input option to allow users to display coverage information as plain text instead of badge images, matching the functionality available in jest-coverage-comment. - Added text-instead-badge input to action.yml (defaults to 'false') - Updated src/index.js to read the new input option - Modified src/parse.js toHtml function to show text format when enabled - Text format displays as: XX% (covered/statements) - Built dist/index.js with updated changes * Fix text-instead-badge to use correct property names Use total.stmts and total.miss instead of non-existent properties. Calculate covered statements as (stmts - miss). * docs: add text-instead-badge option to README Add documentation for the new text-instead-badge input option: - Added to Display Options table with description and default value - Added usage example in Advanced Features section - Explained benefits: no external dependencies, faster rendering, simpler appearance * docs: enhance text-instead-badge documentation - Add Complete Configuration section showing all parameters - Add Text Mode example in Result Examples section with visual comparison - Show text-instead-badge: false in complete configuration example - Include benefits and use cases for text mode - Match documentation style of jest-coverage-comment * docs: simplify text-instead-badge documentation Remove verbose benefits lists and keep documentation minimal * docs: remove Complete Configuration section * chore: bump version to 1.2.0 and update CHANGELOG * feat: update CHANGELOG for version 1.2.0, add text-instead-badge option and automatic server URL detection --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c026f3a commit ae0e8a5

8 files changed

Lines changed: 72 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog of the Pytest Coverage Comment
22

3+
## [Pytest Coverage Comment 1.2.0](https://github.com/MishaKav/pytest-coverage-comment/tree/v1.2.0)
4+
5+
**Release Date:** 2025-11-15
6+
7+
#### Changes
8+
9+
- feat: add `text-instead-badge` option to display coverage as simple text instead of badge images (#235)
10+
- text format displays as `XX% (covered/total)` (e.g., `85% (42/50)`)
11+
- applies to all coverage reports: main summary and multiple-files tables
12+
- fully backward compatible - badge mode remains the default
13+
- feat: add automatic server URL detection for self-hosted GitHub instances (#234)
14+
15+
**Note:** Starting from this version, version bumps follow conventional semantic versioning (MAJOR.MINOR.PATCH) instead of only bumping PATCH versions.
16+
317
## [Pytest Coverage Comment 1.1.59](https://github.com/MishaKav/pytest-coverage-comment/tree/v1.1.59)
418

519
**Release Date:** 2025-11-08

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ jobs:
171171
| `remove-link-from-badge` | `false` | Remove hyperlink from coverage badge (badge becomes plain image) |
172172
| `remove-links-to-files` | `false` | Remove file links from coverage table to reduce comment size |
173173
| `remove-links-to-lines` | `false` | Remove line number links from coverage table to reduce comment size |
174+
| `text-instead-badge` | `false` | Use simple text instead of badge images for coverage display |
174175

175176
</details>
176177

@@ -392,6 +393,22 @@ Here's what the generated coverage comment looks like:
392393

393394
## 🔬 Advanced Features
394395

396+
<details>
397+
<summary>📝 Text-Based Coverage Display</summary>
398+
399+
```yaml
400+
- name: Coverage comment
401+
uses: MishaKav/pytest-coverage-comment@main
402+
with:
403+
pytest-coverage-path: ./pytest-coverage.txt
404+
junitxml-path: ./pytest.xml
405+
text-instead-badge: true
406+
```
407+
408+
Displays coverage as `85% (42/50)` instead of a badge image.
409+
410+
</details>
411+
395412
<details>
396413
<summary>📊 Using Output Variables</summary>
397414

@@ -528,6 +545,18 @@ If you want auto-update the coverage badge on your README, you can see the [work
528545

529546
![Multiple Files](https://user-images.githubusercontent.com/289035/122121939-ddd0c500-ce34-11eb-8546-89a8a769e065.png)
530547

548+
### Text Mode (text-instead-badge: true)
549+
550+
With `text-instead-badge: true`, coverage displays as simple text:
551+
552+
```
553+
85% (42/50)
554+
```
555+
556+
Instead of a badge image:
557+
558+
![Coverage Badge](https://img.shields.io/badge/Coverage-85%25-green.svg)
559+
531560
</details>
532561

533562
## 🔧 Troubleshooting

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ inputs:
114114
default: 'false'
115115
required: false
116116

117+
text-instead-badge:
118+
description: 'Use simple text instead of badge images for coverage display'
119+
default: 'false'
120+
required: false
121+
117122
outputs:
118123
coverage:
119124
description: 'Coverage percentage from pytest report (e.g., 85%)'

dist/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36953,6 +36953,7 @@ const toHtml = (data, options, dataFromXml = null) => {
3695336953
hideReport,
3695436954
reportOnlyChangedFiles,
3695536955
removeLinkFromBadge,
36956+
textInsteadBadge,
3695636957
} = options;
3695736958
const table = hideReport ? '' : toTable(data, options, dataFromXml);
3695836959
const total = dataFromXml ? dataFromXml.total : getTotal(data);
@@ -36963,7 +36964,10 @@ const toHtml = (data, options, dataFromXml = null) => {
3696336964
const badgeWithLink = removeLinkFromBadge
3696436965
? badge
3696536966
: `<a href="${readmeHref}">${badge}</a>`;
36966-
const badgeHtml = hideBadge ? '' : badgeWithLink;
36967+
const covered = total.stmts - total.miss;
36968+
const textBadge = `${total.cover} (${covered}/${total.stmts})`;
36969+
const badgeContent = textInsteadBadge ? textBadge : badgeWithLink;
36970+
const badgeHtml = hideBadge ? '' : badgeContent;
3696736971
const reportHtml = hideReport
3696836972
? ''
3696936973
: `<details><summary>${title} ${onlyChnaged}</summary>${table}</details>`;
@@ -39487,6 +39491,9 @@ const main = async () => {
3948739491
const removeLinksToLines = core.getBooleanInput('remove-links-to-lines', {
3948839492
required: false,
3948939493
});
39494+
const textInsteadBadge = core.getBooleanInput('text-instead-badge', {
39495+
required: false,
39496+
});
3949039497
const uniqueIdForComment = core.getInput('unique-id-for-comment', {
3949139498
required: false,
3949239499
});
@@ -39533,6 +39540,7 @@ const main = async () => {
3953339540
removeLinkFromBadge,
3953439541
removeLinksToFiles,
3953539542
removeLinksToLines,
39543+
textInsteadBadge,
3953639544
defaultBranch,
3953739545
xmlTitle,
3953839546
multipleFiles,

package-lock.json

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pytest-coverage-comment",
3-
"version": "1.1.59",
3+
"version": "1.2.0",
44
"description": "Comments a pull request with the pytest code coverage badge, full report and tests summary",
55
"author": "Misha Kav",
66
"license": "MIT",

src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ const main = async () => {
180180
const removeLinksToLines = core.getBooleanInput('remove-links-to-lines', {
181181
required: false,
182182
});
183+
const textInsteadBadge = core.getBooleanInput('text-instead-badge', {
184+
required: false,
185+
});
183186
const uniqueIdForComment = core.getInput('unique-id-for-comment', {
184187
required: false,
185188
});
@@ -226,6 +229,7 @@ const main = async () => {
226229
removeLinkFromBadge,
227230
removeLinksToFiles,
228231
removeLinksToLines,
232+
textInsteadBadge,
229233
defaultBranch,
230234
xmlTitle,
231235
multipleFiles,

src/parse.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ const toHtml = (data, options, dataFromXml = null) => {
194194
hideReport,
195195
reportOnlyChangedFiles,
196196
removeLinkFromBadge,
197+
textInsteadBadge,
197198
} = options;
198199
const table = hideReport ? '' : toTable(data, options, dataFromXml);
199200
const total = dataFromXml ? dataFromXml.total : getTotal(data);
@@ -204,7 +205,10 @@ const toHtml = (data, options, dataFromXml = null) => {
204205
const badgeWithLink = removeLinkFromBadge
205206
? badge
206207
: `<a href="${readmeHref}">${badge}</a>`;
207-
const badgeHtml = hideBadge ? '' : badgeWithLink;
208+
const covered = total.stmts - total.miss;
209+
const textBadge = `${total.cover} (${covered}/${total.stmts})`;
210+
const badgeContent = textInsteadBadge ? textBadge : badgeWithLink;
211+
const badgeHtml = hideBadge ? '' : badgeContent;
208212
const reportHtml = hideReport
209213
? ''
210214
: `<details><summary>${title} ${onlyChnaged}</summary>${table}</details>`;

0 commit comments

Comments
 (0)