Skip to content

Commit 8a633d4

Browse files
feat: display custom domain and locale in status page commands (#21)
- Show custom domain URL instead of default slug URL in status page list - Update proto dependency to include custom_domain on StatusPageSummary - Display default locale and defined locales in status page info
1 parent badfb63 commit 8a633d4

6 files changed

Lines changed: 96 additions & 28 deletions

File tree

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ go 1.24.0
55
require github.com/urfave/cli/v3 v3.0.0-alpha9.2 // direct
66

77
require (
8-
buf.build/gen/go/openstatus/api/connectrpc/gosimple v1.19.1-20260202165838-5bd92a1e5d53.2
9-
buf.build/gen/go/openstatus/api/protocolbuffers/go v1.36.11-20260202165838-5bd92a1e5d53.1
8+
buf.build/gen/go/openstatus/api/connectrpc/gosimple v1.19.1-20260323160652-4be687fa490b.2
9+
buf.build/gen/go/openstatus/api/protocolbuffers/go v1.36.11-20260323160652-4be687fa490b.1
1010
connectrpc.com/connect v1.19.1
1111
github.com/briandowns/spinner v1.23.2
1212
github.com/fatih/color v1.18.0
@@ -26,6 +26,7 @@ require (
2626

2727
require (
2828
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.11-20251209175733-2a1774d88802.1 // indirect
29+
buf.build/gen/go/gnostic/gnostic/protocolbuffers/go v1.36.11-20230414000709-087bc8072ce4.1 // indirect
2930
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
3031
github.com/fsnotify/fsnotify v1.7.0 // indirect
3132
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.11-20251209175733-2a1774d88802.1 h1:j9yeqTWEFrtimt8Nng2MIeRrpoCvQzM9/g25XTvqUGg=
22
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.11-20251209175733-2a1774d88802.1/go.mod h1:tvtbpgaVXZX4g6Pn+AnzFycuRK3MOz5HJfEGeEllXYM=
3-
buf.build/gen/go/openstatus/api/connectrpc/gosimple v1.19.1-20260202165838-5bd92a1e5d53.2 h1:MeP+r7GwYHWKSMa1ltvtRNwzT+gCyHIYCEpNxWeNwS4=
4-
buf.build/gen/go/openstatus/api/connectrpc/gosimple v1.19.1-20260202165838-5bd92a1e5d53.2/go.mod h1:W/PtF1QguqXdSkOHAD0VAOTMNfuESeNOdR2cF/CWeOQ=
5-
buf.build/gen/go/openstatus/api/protocolbuffers/go v1.36.11-20260202165838-5bd92a1e5d53.1 h1:vw4PznfU8x7XrFtc/HHPjWfxNnFExtaSwrPS8cEKq+w=
6-
buf.build/gen/go/openstatus/api/protocolbuffers/go v1.36.11-20260202165838-5bd92a1e5d53.1/go.mod h1:pZsKB5l3aT2mKtGkAZTC8pXhTptdfyYwFGCyH+KVfOM=
3+
buf.build/gen/go/gnostic/gnostic/protocolbuffers/go v1.36.11-20230414000709-087bc8072ce4.1 h1:t8f+WWZ5WNrZaP5zrpWD8f1tKU7eelJMbIAT9FRX558=
4+
buf.build/gen/go/gnostic/gnostic/protocolbuffers/go v1.36.11-20230414000709-087bc8072ce4.1/go.mod h1:/t9AeRQQp2iNkiGHDLfHLW3SzNpYpNPGRZ+Ih8+SOUs=
5+
buf.build/gen/go/openstatus/api/connectrpc/gosimple v1.19.1-20260323160652-4be687fa490b.2 h1:AHDJQUgykCBDBE8qx4ewHxk4q29BYin4I5k2VZBJoSI=
6+
buf.build/gen/go/openstatus/api/connectrpc/gosimple v1.19.1-20260323160652-4be687fa490b.2/go.mod h1:M+ceX35kH8wh3cgoFD8o2fNVedIx8NB9LWV7Z0ObO6Y=
7+
buf.build/gen/go/openstatus/api/protocolbuffers/go v1.36.11-20260323160652-4be687fa490b.1 h1:sTK/97BsCzbBtqydnKAyRduWLbm1U7LbOk+hAzOikhs=
8+
buf.build/gen/go/openstatus/api/protocolbuffers/go v1.36.11-20260323160652-4be687fa490b.1/go.mod h1:GRsD/In1AV3/RC92zWVAjBpj57hJIQm7Rph0rLOYYPg=
79
connectrpc.com/connect v1.19.1 h1:R5M57z05+90EfEvCY1b7hBxDVOUl45PrtXtAV2fOC14=
810
connectrpc.com/connect v1.19.1/go.mod h1:tN20fjdGlewnSFeZxLKb0xwIZ6ozc3OQs2hTXy4du9w=
911
github.com/briandowns/spinner v1.23.2 h1:Zc6ecUnI+YzLmJniCfDNaMbW0Wid1d5+qcTq4L2FW8w=

internal/statuspage/statuspage.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,27 @@ func componentTypeToString(t status_pagev1.PageComponentType) string {
6565
}
6666
}
6767

68+
func localeToString(l status_pagev1.Locale) string {
69+
switch l {
70+
case status_pagev1.Locale_LOCALE_EN:
71+
return "en"
72+
case status_pagev1.Locale_LOCALE_FR:
73+
return "fr"
74+
case status_pagev1.Locale_LOCALE_DE:
75+
return "de"
76+
default:
77+
return "unknown"
78+
}
79+
}
80+
81+
func localesToStrings(locales []status_pagev1.Locale) []string {
82+
result := make([]string, 0, len(locales))
83+
for _, l := range locales {
84+
result = append(result, localeToString(l))
85+
}
86+
return result
87+
}
88+
6889
func StatusPageCmd() *cli.Command {
6990
return &cli.Command{
7091
Name: "status-page",

internal/statuspage/statuspage_info.go

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ import (
2323
)
2424

2525
type statusPageDetail struct {
26-
ID string `json:"id"`
27-
Title string `json:"title"`
28-
Description string `json:"description,omitempty"`
29-
URL string `json:"url"`
30-
Published bool `json:"published"`
31-
AccessType string `json:"access_type"`
32-
Theme string `json:"theme"`
33-
HomepageURL string `json:"homepage_url,omitempty"`
34-
ContactURL string `json:"contact_url,omitempty"`
35-
Components []statusPageComponent `json:"components,omitempty"`
26+
ID string `json:"id"`
27+
Title string `json:"title"`
28+
Description string `json:"description,omitempty"`
29+
URL string `json:"url"`
30+
Published bool `json:"published"`
31+
AccessType string `json:"access_type"`
32+
Theme string `json:"theme"`
33+
DefaultLocale string `json:"default_locale"`
34+
Locales []string `json:"locales,omitempty"`
35+
HomepageURL string `json:"homepage_url,omitempty"`
36+
ContactURL string `json:"contact_url,omitempty"`
37+
Components []statusPageComponent `json:"components,omitempty"`
3638
}
3739

3840
type statusPageComponent struct {
@@ -109,16 +111,18 @@ func GetStatusPageInfo(ctx context.Context, client status_pagev1connect.StatusPa
109111

110112
if output.IsJSONOutput() {
111113
detail := statusPageDetail{
112-
ID: page.GetId(),
113-
Title: page.GetTitle(),
114-
Description: page.GetDescription(),
115-
URL: pageURL,
116-
Published: page.GetPublished(),
117-
AccessType: accessTypeToString(page.GetAccessType()),
118-
Theme: themeToString(page.GetTheme()),
119-
HomepageURL: page.GetHomepageUrl(),
120-
ContactURL: page.GetContactUrl(),
121-
Components: comps,
114+
ID: page.GetId(),
115+
Title: page.GetTitle(),
116+
Description: page.GetDescription(),
117+
URL: pageURL,
118+
Published: page.GetPublished(),
119+
AccessType: accessTypeToString(page.GetAccessType()),
120+
Theme: themeToString(page.GetTheme()),
121+
DefaultLocale: localeToString(page.GetDefaultLocale()),
122+
Locales: localesToStrings(page.GetLocales()),
123+
HomepageURL: page.GetHomepageUrl(),
124+
ContactURL: page.GetContactUrl(),
125+
Components: comps,
122126
}
123127
return output.PrintJSON(detail)
124128
}
@@ -162,6 +166,10 @@ func GetStatusPageInfo(ctx context.Context, client status_pagev1connect.StatusPa
162166

163167
data = append(data, []string{"Access Type", accessTypeToString(page.GetAccessType())})
164168
data = append(data, []string{"Theme", themeToString(page.GetTheme())})
169+
data = append(data, []string{"Default Locale", localeToString(page.GetDefaultLocale())})
170+
if locales := page.GetLocales(); len(locales) > 0 {
171+
data = append(data, []string{"Locales", strings.Join(localesToStrings(locales), ", ")})
172+
}
165173

166174
if page.GetHomepageUrl() != "" {
167175
data = append(data, []string{"Homepage URL", page.GetHomepageUrl()})

internal/statuspage/statuspage_list.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7+
"strings"
78

89
status_pagev1 "buf.build/gen/go/openstatus/api/protocolbuffers/go/openstatus/status_page/v1"
910
"buf.build/gen/go/openstatus/api/connectrpc/gosimple/openstatus/status_page/v1/status_pagev1connect"
@@ -42,7 +43,7 @@ func ListStatusPages(ctx context.Context, client status_pagev1connect.StatusPage
4243
entries = append(entries, statusPageListEntry{
4344
ID: p.GetId(),
4445
Title: p.GetTitle(),
45-
URL: "https://" + p.GetSlug() + ".openstatus.dev",
46+
URL: statusPageURL(p),
4647
})
4748
}
4849
return output.PrintJSON(entries)
@@ -65,14 +66,22 @@ func ListStatusPages(ctx context.Context, client status_pagev1connect.StatusPage
6566
tbl.AddRow(
6667
p.GetId(),
6768
p.GetTitle(),
68-
"https://"+p.GetSlug()+".openstatus.dev",
69+
statusPageURL(p),
6970
)
7071
}
7172

7273
tbl.Print()
7374
return nil
7475
}
7576

77+
func statusPageURL(p *status_pagev1.StatusPageSummary) string {
78+
if d := p.GetCustomDomain(); d != "" {
79+
d = strings.TrimPrefix(strings.TrimPrefix(d, "https://"), "http://")
80+
return "https://" + d
81+
}
82+
return "https://" + p.GetSlug() + ".openstatus.dev"
83+
}
84+
7685
func ListStatusPagesWithHTTPClient(ctx context.Context, httpClient *http.Client, apiKey string, limit int) error {
7786
client := NewStatusPageClientWithHTTPClient(httpClient, apiKey)
7887
return ListStatusPages(ctx, client, limit, nil)

internal/statuspage/statuspage_list_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,33 @@ func Test_ListStatusPages(t *testing.T) {
4242
}
4343
})
4444

45+
t.Run("Displays custom domain when set", func(t *testing.T) {
46+
body := `{"statusPages":[{"id":"1","title":"My Status Page","slug":"my-page","customDomain":"status.example.com","published":true,"createdAt":"2026-01-01T00:00:00Z","updatedAt":"2026-01-01T00:00:00Z"}],"totalSize":1}`
47+
r := io.NopCloser(bytes.NewReader([]byte(body)))
48+
49+
interceptor := &interceptorHTTPClient{
50+
f: func(req *http.Request) (*http.Response, error) {
51+
return &http.Response{
52+
StatusCode: http.StatusOK,
53+
Body: r,
54+
Header: http.Header{
55+
"Content-Type": []string{"application/json"},
56+
},
57+
}, nil
58+
},
59+
}
60+
61+
var bf bytes.Buffer
62+
log.SetOutput(&bf)
63+
t.Cleanup(func() {
64+
log.SetOutput(os.Stderr)
65+
})
66+
err := statuspage.ListStatusPagesWithHTTPClient(context.Background(), interceptor.GetHTTPClient(), "test-token", 0)
67+
if err != nil {
68+
t.Errorf("Expected no error, got %v", err)
69+
}
70+
})
71+
4572
t.Run("Returns empty list", func(t *testing.T) {
4673
body := `{"statusPages":[],"totalSize":0}`
4774
r := io.NopCloser(bytes.NewReader([]byte(body)))

0 commit comments

Comments
 (0)