Skip to content

Commit

Permalink
fix: use random words for subdomain
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasHiltl committed Oct 20, 2024
1 parent 7c74d1d commit bb953a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ require (
github.com/a-h/templ v0.2.771
github.com/bradleyfalzon/ghinstallation/v2 v2.10.0
github.com/google/go-github/v62 v62.0.0
github.com/gosimple/slug v1.14.0
github.com/guregu/null/v5 v5.0.0
github.com/jonashiltl/openchangelog/apitypes v0.0.0-20241013200840-98b510d4c198
github.com/mattn/go-sqlite3 v1.14.16
github.com/naveensrinivasan/httpcache v1.2.1
github.com/peterbourgon/diskv v2.0.1+incompatible
github.com/quail-ink/goldmark-enclave v0.0.8
github.com/rs/xid v1.5.0
github.com/sio/coolname v0.1.0
github.com/sourcegraph/s3cache v0.0.0-20141202193749-4150cc6b0465
github.com/spf13/viper v1.18.2
github.com/yuin/goldmark v1.7.1
Expand All @@ -29,6 +31,7 @@ require (
github.com/google/btree v1.0.0 // indirect
github.com/google/go-github/v60 v60.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/kr/http v0.0.0-20150505212737-77bd98b60462 // indirect
github.com/magiconair/properties v1.8.7 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ github.com/google/go-github/v62 v62.0.0 h1:/6mGCaRywZz9MuHyw9gD1CwsbmBX8GWsbFkwM
github.com/google/go-github/v62 v62.0.0/go.mod h1:EMxeUqGJq2xRu9DYBMwel/mr7kZrzUOfQmmpYrZn2a4=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/gosimple/slug v1.14.0 h1:RtTL/71mJNDfpUbCOmnf/XFkzKRtD6wL6Uy+3akm4Es=
github.com/gosimple/slug v1.14.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA=
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/guregu/null/v5 v5.0.0 h1:PRxjqyOekS11W+w/7Vfz6jgJE/BCwELWtgvOJzddimw=
Expand Down Expand Up @@ -76,6 +80,8 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/sio/coolname v0.1.0 h1:Hha2+NQ4dRb9pmWqGlPgu0PktZYuWPaoCJbGcbYSAsA=
github.com/sio/coolname v0.1.0/go.mod h1:3Z0yllmTmmNnicHY0vr2mUpIw31Ts755TO/6rocFXeo=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/sourcegraph/s3cache v0.0.0-20141202193749-4150cc6b0465 h1:YwSzrOdV58EJMej5zdLFYUuJp6zHaE4KshMxiSaqbXY=
Expand Down
11 changes: 8 additions & 3 deletions internal/store/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"regexp"
"strings"

"github.com/gosimple/slug"
"github.com/jonashiltl/openchangelog/apitypes"
"github.com/jonashiltl/openchangelog/internal/errs"
"github.com/sio/coolname"
"golang.org/x/exp/rand"
)

Expand Down Expand Up @@ -61,10 +63,13 @@ func (s Subdomain) NullString() apitypes.NullString {
}

func NewSubdomain(workspaceName string) Subdomain {
wsName := strings.ReplaceAll(strings.ToLower(workspaceName), " ", "-")
rnd := rand.Intn(100000)
suffix, err := coolname.SlugN(2)
if err != nil {
suffix = fmt.Sprint(rand.Intn(100000))
}

return Subdomain(fmt.Sprintf("%s-%d", wsName, rnd))
subdomain := slug.Make(fmt.Sprintf("%s %s", workspaceName, suffix))
return Subdomain(subdomain)
}

var subdomainRegex = regexp.MustCompile("^[a-z0-9-]*$")
Expand Down

0 comments on commit bb953a0

Please sign in to comment.