Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

frontend: Use Cloud search for Go import badges #30350

Merged
merged 7 commits into from
Jan 28, 2022
Merged

Conversation

tsenart
Copy link
Contributor

@tsenart tsenart commented Jan 28, 2022

This commit fixes our Go import badges on sourcegraph.com, which have been broken since api.godoc.org was brought down. There's a tracking issue to re-introduce an API for pkg.go.dev, but it's not implemented yet.

Instead, we implement a best-effort alternative that relies on searching go.mod files for the given repo name on sourcegraph.com. Sometimes packages will have different canonical names than their repositories, and we don't handle that case.

There are many open-source projects that have a broken badge. After this lands, they will recover.

Tested locally by changing the target URL to sourcegraph.com rather than internal.Client.URL.

This commit fixes our Go import badges on sourcegraph.com, which have
been broken since api.godoc.org was brought down. There's a [tracking
issue](golang/go#36785) to re-introduce an
API for pkg.go.dev, but it's not implemented yet.

Instead, we implement a best-effort alternative that relies on searching
`go.mod` files for the given repo name on sourcegraph.com.
Sometimes packages will have different canonical names than their
repositories, and we don't handle that case.

There are [many open-source projects that have a broken badge](https://sourcegraph.com/search?q=context:global+sourcegraph.com+-/badge.svg&patternType=regexp).
After this lands, they will recover.
@tsenart tsenart requested a review from a team January 28, 2022 12:57
@cla-bot cla-bot bot added the cla-signed label Jan 28, 2022
cmd/frontend/backend/go_importers.go Outdated Show resolved Hide resolved
Co-authored-by: Erik Seliger <erikseliger@me.com>
cmd/frontend/backend/go_importers.go Outdated Show resolved Hide resolved
@@ -12,6 +12,7 @@ import (
"github.com/sourcegraph/sourcegraph/cmd/frontend/backend"
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/routevar"
"github.com/sourcegraph/sourcegraph/internal/database"
"github.com/sourcegraph/sourcegraph/internal/httpcli"
)

// TODO(slimsag): once https://github.com/badges/shields/pull/828 is merged,
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we might be able to drop this TODO as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, that hasn't been done. I'm not sure what the exact steps would be here, so I'll let @slimsag comment.

Copy link
Member

Choose a reason for hiding this comment

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

The point of this TODO is that once shields.io has official badges for Sourcegraph, then we don't need our own endpoint that serves SVGs (and the serveRepoBadge below could just redirect to shields.io directly.)

Looks like that PR was merged, so I believe we could do this today if we wanted to. If you search for Sourcegraph on https://shields.io/ you'll see it's there:

image

And if you click the URL /sourcegraph/rrc it pops up the builder UI:

image

But it seems like that badge design doesn't include the Sourcegraph logo, I guess when we added that customization on our side we never sent a PR to shields.io to add the logo there:

so yeah, idk, would it be nice to fix? maybe. but also maybe not worth the time.

@daxmc99
Copy link
Contributor

daxmc99 commented Jan 28, 2022

Removed blackbox alerts here: https://github.com/sourcegraph/deploy-sourcegraph-cloud/pull/15386

@tsenart tsenart merged commit 52fead1 into main Jan 28, 2022
@tsenart tsenart deleted the ts/fix-go-import-badges branch January 28, 2022 15:00
davejrt pushed a commit that referenced this pull request Feb 15, 2022
This commit fixes our Go import badges on sourcegraph.com, which have
been broken since api.godoc.org was brought down. There's a [tracking
issue](golang/go#36785) to re-introduce an
API for pkg.go.dev, but it's not implemented yet.

Instead, we implement a best-effort alternative that relies on searching
`go.mod` files for the given repo name on sourcegraph.com.
Sometimes packages will have different canonical names than their
repositories, and we don't handle that case.

There are [many open-source projects that have a broken badge](https://sourcegraph.com/search?q=context:global+sourcegraph.com+-/badge.svg&patternType=regexp).
After this lands, they will recover.

Co-authored-by: Erik Seliger <erikseliger@me.com>
Co-authored-by: Keegan Carruthers-Smith <keegan@sourcegraph.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants