Skip to content

Commit

Permalink
feat: add the Stryker logo to the badge (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
regseb authored Mar 18, 2024
1 parent 87d3563 commit ab4e8e0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
14 changes: 8 additions & 6 deletions packages/badge-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@

# Stryker dashboard Badge API

The Badge API azure function that is responsible for delivering the badge structure to shields.io.
The Badge API azure function that is responsible for delivering the badge structure to shields.io.

Example of a badge URL:
Example of a badge URL:
https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgh.neting.cc%2Fstryker-mutator%2Fstryker-dashboard%2Fmaster%3Fmodule%3Dbadge-api

Example of a badge api URL itself:

HTTP GET https://badge-api.stryker-mutator.io/github.com/stryker-mutator/stryker-dashboard/master?module=badge-api

Response:
Response:

```json
{
"color": "orange",
"schemaVersion": 1,
"label": "Mutation score",
"message": "69.4%",
"schemaVersion": 1
"color": "orange",
"namedLogo": "stryker",
"logoColor": "whitesmoke"
}
```
```
3 changes: 3 additions & 0 deletions packages/badge-api/badge/Shield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface Shield {
label: string;
message: string;
color: Color;
namedLogo: 'stryker';
logoColor: Color;
}

export enum Color {
Expand All @@ -15,4 +17,5 @@ export enum Color {
Orange = 'orange',
Green = 'green',
BrightGreen = 'brightgreen',
WhiteSmoke = 'whitesmoke',
}
12 changes: 8 additions & 4 deletions packages/badge-api/badge/ShieldMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ export class ShieldMapper {
const score = Math.round(report.model.mutationScore * 10) / 10;
const scoreColor = determineColor(score);
return {
color: scoreColor,
schemaVersion: 1,
label: 'Mutation score',
message: `${score}%`,
schemaVersion: 1,
color: scoreColor,
namedLogo: 'stryker',
logoColor: Color.WhiteSmoke,
};
} else {
return {
color: Color.Grey,
schemaVersion: 1,
label: 'Mutation score',
message: 'unknown',
schemaVersion: 1,
color: Color.Grey,
namedLogo: 'stryker',
logoColor: Color.WhiteSmoke,
};
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/badge-api/test/badge/ShieldMapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ describe(ShieldMapper.name, () => {
const actualShield = await sut.shieldFor('foo', 'bar', 'baz');
const expectedShield: Shield = {
schemaVersion: 1,
color: Color.Grey,
label: 'Mutation score',
message: 'unknown',
color: Color.Grey,
namedLogo: 'stryker',
logoColor: Color.WhiteSmoke,
};
expect(actualShield).deep.eq(expectedShield);
});
Expand Down
6 changes: 4 additions & 2 deletions packages/badge-api/test/badge/handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ describe(handler.name, () => {
it('should return the given mapped shield', async () => {
// Arrange
const expectedShield: Shield = {
color: Color.Green,
schemaVersion: 1,
label: 'Mutation Testing',
message: '80%',
schemaVersion: 1,
color: Color.Green,
namedLogo: 'stryker',
logoColor: Color.WhiteSmoke,
};
shieldMapperStub.shieldFor.resolves(expectedShield);
const context = createContext();
Expand Down

0 comments on commit ab4e8e0

Please sign in to comment.