Skip to content

fix: make default support links respect --docs-url #14176

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add version through frontend
  • Loading branch information
bcpeinhardt committed Aug 6, 2024
commit 466004de30f9b190d0c04b5e31779d66cd9ed349
38 changes: 19 additions & 19 deletions coderd/appearance/appearance.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,9 @@ type Fetcher interface {
Fetch(ctx context.Context) (codersdk.AppearanceConfig, error)
}

var defaultSupportLinks = []codersdk.LinkConfig{
{
Name: "Report a bug",
Target: "https://github.com/coder/coder/issues/new?labels=needs+grooming&body={CODER_BUILD_INFO}",
Icon: "bug",
},
{
Name: "Join the Coder Discord",
Target: "https://coder.com/chat?utm_source=coder&utm_medium=coder&utm_campaign=server-footer",
Icon: "chat",
},
{
Name: "Star the Repo",
Target: "https://github.com/coder/coder",
Icon: "star",
},
}

func DefaultSupportLinks(docsURL string) []codersdk.LinkConfig {
if docsURL == "" {
docsURL = "https://coder.com/docs/coder-oss"
docsURL = "https://coder.com/docs/{CODER_VERSION}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use buildinfo.Version() instead so the frontend doesn't have to replace this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was taking a "do as the Romans do" approach and doing it the way the build info was done, but I agree with your comment below that we have this info on the backend so we might as well do it here.
Let me ping someone for context on why it's set up this way before falling into the classic "refactor and then realize why they did it the original way" trap and get back to you haha.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can just have the backend do this :)
https://codercom.slack.com/archives/CJURPL8DN/p1723126779529959

}

docsLink := codersdk.LinkConfig{
Expand All @@ -39,6 +21,24 @@ func DefaultSupportLinks(docsURL string) []codersdk.LinkConfig {
Icon: "docs",
}

defaultSupportLinks := []codersdk.LinkConfig{
{
Name: "Report a bug",
Target: "https://github.com/coder/coder/issues/new?labels=needs+grooming&body={CODER_BUILD_INFO}",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you didn't introduce this, but I think we should be doing this replacement on the backend, not the frontend. We already should have this info anyways.

Icon: "bug",
},
{
Name: "Join the Coder Discord",
Target: "https://coder.com/chat?utm_source=coder&utm_medium=coder&utm_campaign=server-footer",
Icon: "chat",
},
{
Name: "Star the Repo",
Target: "https://github.com/coder/coder",
Icon: "star",
},
}

return append([]codersdk.LinkConfig{docsLink}, defaultSupportLinks...)
}

Expand Down
4 changes: 3 additions & 1 deletion enterprise/coderd/appearance.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ type appearanceFetcher struct {
database database.Store
supportLinks []codersdk.LinkConfig
docsURL string
coderVersion string
}

func newAppearanceFetcher(store database.Store, links []codersdk.LinkConfig, docsURL string) agpl.Fetcher {
func newAppearanceFetcher(store database.Store, links []codersdk.LinkConfig, docsURL, coderVersion string) agpl.Fetcher {
return &appearanceFetcher{
database: store,
supportLinks: links,
docsURL: docsURL,
coderVersion: coderVersion,
}
}

Expand Down
2 changes: 2 additions & 0 deletions enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sync"
"time"

"github.com/coder/coder/v2/buildinfo"
"github.com/coder/coder/v2/coderd/appearance"
"github.com/coder/coder/v2/coderd/database"
agplportsharing "github.com/coder/coder/v2/coderd/portsharing"
Expand Down Expand Up @@ -791,6 +792,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
api.Database,
api.DeploymentValues.Support.Links.Value,
api.DeploymentValues.DocsURL.String(),
buildinfo.Version(),
)
api.AGPL.AppearanceFetcher.Store(&f)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,20 @@ const includeBuildInfo = (
href: string,
buildInfo?: TypesGen.BuildInfoResponse,
): string => {
return href.replace(
"{CODER_BUILD_INFO}",
`${encodeURIComponent(
`Version: [\`${buildInfo?.version}\`](${buildInfo?.external_url})`,
)}`,
);
let version = encodeURIComponent((buildInfo?.version ?? "").split("-")[0]);
if (version) {
// Not encoding the @ because it makes the link look a bit weird.
version = `@${version}`;
}

return href
.replace(
"{CODER_BUILD_INFO}",
`${encodeURIComponent(
`Version: [\`${buildInfo?.version}\`](${buildInfo?.external_url})`,
)}`,
)
.replace("{CODER_VERSION}", version);
};

const styles = {
Expand Down
Loading