-
-
Notifications
You must be signed in to change notification settings - Fork 82
Add status page badges #430
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| namespace Cachet\Http; | ||
|
|
||
| use Cachet\Badger\BadgeImage; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Http\Response; | ||
|
|
||
| class BadgeResponseFactory | ||
| { | ||
| /** | ||
| * Build a cacheable SVG response. | ||
| */ | ||
| public function make(BadgeImage $badge): Response | ||
| { | ||
| return response((string) $badge, 200, [ | ||
| 'Cache-Control' => 'public, max-age=60, s-maxage=60', | ||
| 'Content-Type' => 'image/svg+xml; charset=UTF-8', | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * Return the requested style, falling back to the default for unsupported values. | ||
| */ | ||
| public function style(Request $request): string | ||
| { | ||
| $style = $request->string('style', 'flat-square')->value(); | ||
|
|
||
| return in_array($style, ['flat-square', 'plastic-flat', 'flat', 'plastic', 'social', 'svg'], true) | ||
| ? $style | ||
| : 'flat-square'; | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/Http/Controllers/StatusPage/ComponentBadgeController.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| namespace Cachet\Http\Controllers\StatusPage; | ||
|
|
||
| use Cachet\Badger\Badger; | ||
| use Cachet\Enums\ResourceVisibilityEnum; | ||
| use Cachet\Http\BadgeResponseFactory; | ||
| use Cachet\Models\Component; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Http\Response; | ||
|
|
||
| class ComponentBadgeController | ||
| { | ||
| /** | ||
| * Render a badge for a publicly visible component. | ||
| */ | ||
| public function __invoke(Request $request, Component $component, Badger $badger, BadgeResponseFactory $badgeResponseFactory): Response | ||
| { | ||
| $component->loadMissing('group'); | ||
|
|
||
| abort_if(! $component->enabled || ($component->group?->visible !== null && $component->group->visible !== ResourceVisibilityEnum::guest), 404); | ||
|
|
||
| return $badgeResponseFactory->make( | ||
| $badger->generate( | ||
| $component->name, | ||
| $component->latest_status->getLabel(), | ||
| $component->latest_status->getBadgeColor(), | ||
| $badgeResponseFactory->style($request), | ||
| ), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| namespace Cachet\Http\Controllers\StatusPage; | ||
|
|
||
| use Cachet\Badger\Badger; | ||
| use Cachet\Http\BadgeResponseFactory; | ||
| use Cachet\Status; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Http\Response; | ||
|
|
||
| class StatusBadgeController | ||
| { | ||
| /** | ||
| * Render a badge for the status page's current system status. | ||
| */ | ||
| public function __invoke(Request $request, Status $status, Badger $badger, BadgeResponseFactory $badgeResponseFactory): Response | ||
| { | ||
| $systemStatus = $status->current(); | ||
|
|
||
| return $badgeResponseFactory->make( | ||
| $badger->generate('status', $systemStatus->getLabel(), $systemStatus->getBadgeColor(), $badgeResponseFactory->style($request)), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| use Cachet\Enums\ComponentStatusEnum; | ||
| use Cachet\Enums\SystemStatusEnum; | ||
|
|
||
| it('maps component statuses to badge colors', function (ComponentStatusEnum $status, string $color) { | ||
| expect($status->getBadgeColor())->toBe($color); | ||
| })->with([ | ||
| [ComponentStatusEnum::operational, 'brightgreen'], | ||
| [ComponentStatusEnum::performance_issues, 'yellow'], | ||
| [ComponentStatusEnum::partial_outage, 'orange'], | ||
| [ComponentStatusEnum::major_outage, 'red'], | ||
| [ComponentStatusEnum::unknown, 'lightgray'], | ||
| [ComponentStatusEnum::under_maintenance, 'orange'], | ||
| ]); | ||
|
|
||
| it('maps system statuses to badge colors', function (SystemStatusEnum $status, string $color) { | ||
| expect($status->getBadgeColor())->toBe($color); | ||
| })->with([ | ||
| [SystemStatusEnum::operational, 'brightgreen'], | ||
| [SystemStatusEnum::partial_outage, 'orange'], | ||
| [SystemStatusEnum::major_outage, 'red'], | ||
| [SystemStatusEnum::under_maintenance, 'orange'], | ||
| ]); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces
cachethq/badgeras a new runtime dependency, but the repository explicitly prohibits adding dependencies without prior approval, and the reviewed change provides no evidence of that approval. Obtain and document approval or use an existing approved dependency before merging.AGENTS.md reference: AGENTS.md:L20-L24
Useful? React with 👍 / 👎.